on master help sign in
Completion: Format docs tabs & highlight in the doc's native language
commit87d0617f3bb1031e587b958dc45ce795847120e2 authorBlaž Hrastnik <blaz@mxxn.io> dateSun 30 May 2021, 17:13 (5 years ago) parent668f735
2 files changed+16−5
helix-term/src/ui/completion.rs+12−3 helix-term/src/ui/markdown.rs+4−2
helix-term/src/ui/completion.rs+12−3
@@ -231,6 +231,12 @@ impl Component for Completion {
231231 // ---
232232 // option.documentation
233233
234+ let (view, doc) = cx.editor.current();
235+ let language = doc
236+ .language()
237+ .and_then(|scope| scope.strip_prefix("source."))
238+ .unwrap_or("");
239+
234240 let doc = match &option.documentation {
235241 Some(lsp::Documentation::String(contents))
236242 | Some(lsp::Documentation::MarkupContent(lsp::MarkupContent {
@@ -239,7 +245,8 @@ impl Component for Completion {
239245 })) => {
240246 // TODO: convert to wrapped text
241247 Markdown::new(format!(
242− "```rust\n{}\n```\n{}",
248+ "```{}\n{}\n```\n{}",
249+ language,
243250 option.detail.as_deref().unwrap_or_default(),
244251 contents.clone()
245252 ))
@@ -250,7 +257,8 @@ impl Component for Completion {
250257 })) => {
251258 // TODO: set language based on doc scope
252259 Markdown::new(format!(
253− "```rust\n{}\n```\n{}",
260+ "```{}\n{}\n```\n{}",
261+ language,
254262 option.detail.as_deref().unwrap_or_default(),
255263 contents.clone()
256264 ))
@@ -260,7 +268,8 @@ impl Component for Completion {
260268
261269 // TODO: set language based on doc scope
262270 Markdown::new(format!(
263− "```rust\n{}\n```",
271+ "```{}\n{}\n```",
272+ language,
264273 option.detail.as_deref().unwrap_or_default(),
265274 ))
266275 }
helix-term/src/ui/markdown.rs+4−2
@@ -113,7 +113,8 @@ fn parse<'a>(contents: &'a str, theme: Option<&Theme>) -> tui::text::Text<'a> {
113113 while let Some(end) = slice.find('\n') {
114114 // emit span up to newline
115115 let text = &slice[..end];
116− let span = Span::styled(text.to_owned(), style);
116+ let text = text.replace('\t', " "); // replace tabs
117+ let span = Span::styled(text, style);
117118 spans.push(span);
118119
119120 // truncate slice to after newline
@@ -126,7 +127,8 @@ fn parse<'a>(contents: &'a str, theme: Option<&Theme>) -> tui::text::Text<'a> {
126127
127128 // if there's anything left, emit it too
128129 if !slice.is_empty() {
129− let span = Span::styled(slice.to_owned(), style);
130+ let span =
131+ Span::styled(slice.replace('\t', " "), style);
130132 spans.push(span);
131133 }
132134 }