aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-11-15 01:29:07 +0000
committerBlaž Hrastnik2021-11-15 01:30:05 +0000
commite128a8702eda3d449cfe355b853724d18b03a977 (patch)
treefb8d59ad539356777b8785bfb3b151267a9cd000 /helix-term
parent8f7ada12ac7ed16276dbf2176c7d91ddcb721f97 (diff)
Implement MarkedString rendering
Solves typescript and python documentation rendering
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs32
1 files changed, 21 insertions, 11 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 115d1789..cb1f470b 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -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,
};