From 87d0617f3bb1031e587b958dc45ce795847120e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Sun, 30 May 2021 17:13:02 +0900 Subject: [PATCH] Completion: Format docs tabs & highlight in the doc's native language --- helix-term/src/ui/completion.rs | 15 ++++++++++++--- helix-term/src/ui/markdown.rs | 6 ++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index a75a4d6c..a24a0757 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -231,6 +231,12 @@ impl Component for Completion { // --- // option.documentation + let (view, doc) = cx.editor.current(); + let language = doc + .language() + .and_then(|scope| scope.strip_prefix("source.")) + .unwrap_or(""); + let doc = match &option.documentation { Some(lsp::Documentation::String(contents)) | Some(lsp::Documentation::MarkupContent(lsp::MarkupContent { @@ -239,7 +245,8 @@ impl Component for Completion { })) => { // TODO: convert to wrapped text Markdown::new(format!( - "```rust\n{}\n```\n{}", + "```{}\n{}\n```\n{}", + language, option.detail.as_deref().unwrap_or_default(), contents.clone() )) @@ -250,7 +257,8 @@ impl Component for Completion { })) => { // TODO: set language based on doc scope Markdown::new(format!( - "```rust\n{}\n```\n{}", + "```{}\n{}\n```\n{}", + language, option.detail.as_deref().unwrap_or_default(), contents.clone() )) @@ -260,7 +268,8 @@ impl Component for Completion { // TODO: set language based on doc scope Markdown::new(format!( - "```rust\n{}\n```", + "```{}\n{}\n```", + language, option.detail.as_deref().unwrap_or_default(), )) } diff --git a/helix-term/src/ui/markdown.rs b/helix-term/src/ui/markdown.rs index daac173d..be113747 100644 --- a/helix-term/src/ui/markdown.rs +++ b/helix-term/src/ui/markdown.rs @@ -113,7 +113,8 @@ fn parse<'a>(contents: &'a str, theme: Option<&Theme>) -> tui::text::Text<'a> { while let Some(end) = slice.find('\n') { // emit span up to newline let text = &slice[..end]; - let span = Span::styled(text.to_owned(), style); + let text = text.replace('\t', " "); // replace tabs + let span = Span::styled(text, style); spans.push(span); // truncate slice to after newline @@ -126,7 +127,8 @@ fn parse<'a>(contents: &'a str, theme: Option<&Theme>) -> tui::text::Text<'a> { // if there's anything left, emit it too if !slice.is_empty() { - let span = Span::styled(slice.to_owned(), style); + let span = + Span::styled(slice.replace('\t', " "), style); spans.push(span); } }