Completion: Format docs tabs & highlight in the doc's native language

pull/11/head
Blaž Hrastnik 4 years ago
parent 668f735232
commit 87d0617f3b

@ -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(),
))
}

@ -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);
}
}

Loading…
Cancel
Save