Skip to content

Commit

Permalink
Implement MarkedString rendering
Browse files Browse the repository at this point in the history
Solves typescript and python documentation rendering
  • Loading branch information
archseer committed Nov 15, 2021
1 parent 8f7ada1 commit e128a87
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4660,18 +4660,28 @@ fn hover(cx: &mut Context) {
move |editor: &mut Editor, compositor: &mut Compositor, response: Option<lsp::Hover>| {
if let Some(hover) = response {
// hover.contents / .range <- used for visualizing
let contents = match hover.contents {
lsp::HoverContents::Scalar(contents) => {
// markedstring(string/languagestring to be highlighted)
// TODO
log::error!("hover contents {:?}", contents);
return;
}
lsp::HoverContents::Array(contents) => {
log::error!("hover contents {:?}", contents);
return;

fn marked_string_to_markdown(contents: lsp::MarkedString) -> String {
match contents {
lsp::MarkedString::String(contents) => contents,
lsp::MarkedString::LanguageString(string) => {
log::error!("MarkedString {}: {}", string.language, string.value);
if string.language == "markdown" {
string.value
} else {
format!("```{}\n{}\n```", string.language, string.value)
}
}
}
// TODO: render markdown
}

let contents = match hover.contents {
lsp::HoverContents::Scalar(contents) => marked_string_to_markdown(contents),
lsp::HoverContents::Array(contents) => contents
.into_iter()
.map(marked_string_to_markdown)
.collect::<Vec<_>>()
.join("\n\n"),
lsp::HoverContents::Markup(contents) => contents.value,
};

Expand Down

0 comments on commit e128a87

Please sign in to comment.