Implement MarkedString rendering

Solves typescript and python documentation rendering
imgbot
Blaž Hrastnik 3 years ago
parent 8f7ada12ac
commit e128a8702e

@ -4660,18 +4660,28 @@ fn hover(cx: &mut Context) {
move |editor: &mut Editor, compositor: &mut Compositor, response: Option<lsp::Hover>| { move |editor: &mut Editor, compositor: &mut Compositor, response: Option<lsp::Hover>| {
if let Some(hover) = response { if let Some(hover) = response {
// hover.contents / .range <- used for visualizing // hover.contents / .range <- used for visualizing
let contents = match hover.contents {
lsp::HoverContents::Scalar(contents) => { fn marked_string_to_markdown(contents: lsp::MarkedString) -> String {
// markedstring(string/languagestring to be highlighted) match contents {
// TODO lsp::MarkedString::String(contents) => contents,
log::error!("hover contents {:?}", contents); lsp::MarkedString::LanguageString(string) => {
return; log::error!("MarkedString {}: {}", string.language, string.value);
if string.language == "markdown" {
string.value
} else {
format!("```{}\n{}\n```", string.language, string.value)
} }
lsp::HoverContents::Array(contents) => {
log::error!("hover contents {:?}", contents);
return;
} }
// 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, lsp::HoverContents::Markup(contents) => contents.value,
}; };

Loading…
Cancel
Save