aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-05-30 08:13:02 +0000
committerBlaž Hrastnik2021-05-30 08:13:02 +0000
commit87d0617f3bb1031e587b958dc45ce795847120e2 (patch)
tree43e8c83e0d98e6da25614f7400d0c4d753420c58
parent668f735232c6853d34d100c7ec9168bfcd44dd3f (diff)
Completion: Format docs tabs & highlight in the doc's native language
-rw-r--r--helix-term/src/ui/completion.rs15
-rw-r--r--helix-term/src/ui/markdown.rs6
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);
}
}