mirror of
https://github.com/ilyakooo0/helix.git
synced 2024-11-30 00:35:26 +03:00
Completion: Format docs tabs & highlight in the doc's native language
This commit is contained in:
parent
668f735232
commit
87d0617f3b
@ -231,6 +231,12 @@ impl Component for Completion {
|
|||||||
// ---
|
// ---
|
||||||
// option.documentation
|
// 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 {
|
let doc = match &option.documentation {
|
||||||
Some(lsp::Documentation::String(contents))
|
Some(lsp::Documentation::String(contents))
|
||||||
| Some(lsp::Documentation::MarkupContent(lsp::MarkupContent {
|
| Some(lsp::Documentation::MarkupContent(lsp::MarkupContent {
|
||||||
@ -239,7 +245,8 @@ impl Component for Completion {
|
|||||||
})) => {
|
})) => {
|
||||||
// TODO: convert to wrapped text
|
// TODO: convert to wrapped text
|
||||||
Markdown::new(format!(
|
Markdown::new(format!(
|
||||||
"```rust\n{}\n```\n{}",
|
"```{}\n{}\n```\n{}",
|
||||||
|
language,
|
||||||
option.detail.as_deref().unwrap_or_default(),
|
option.detail.as_deref().unwrap_or_default(),
|
||||||
contents.clone()
|
contents.clone()
|
||||||
))
|
))
|
||||||
@ -250,7 +257,8 @@ impl Component for Completion {
|
|||||||
})) => {
|
})) => {
|
||||||
// TODO: set language based on doc scope
|
// TODO: set language based on doc scope
|
||||||
Markdown::new(format!(
|
Markdown::new(format!(
|
||||||
"```rust\n{}\n```\n{}",
|
"```{}\n{}\n```\n{}",
|
||||||
|
language,
|
||||||
option.detail.as_deref().unwrap_or_default(),
|
option.detail.as_deref().unwrap_or_default(),
|
||||||
contents.clone()
|
contents.clone()
|
||||||
))
|
))
|
||||||
@ -260,7 +268,8 @@ impl Component for Completion {
|
|||||||
|
|
||||||
// TODO: set language based on doc scope
|
// TODO: set language based on doc scope
|
||||||
Markdown::new(format!(
|
Markdown::new(format!(
|
||||||
"```rust\n{}\n```",
|
"```{}\n{}\n```",
|
||||||
|
language,
|
||||||
option.detail.as_deref().unwrap_or_default(),
|
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') {
|
while let Some(end) = slice.find('\n') {
|
||||||
// emit span up to newline
|
// emit span up to newline
|
||||||
let text = &slice[..end];
|
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);
|
spans.push(span);
|
||||||
|
|
||||||
// truncate slice to after newline
|
// 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 there's anything left, emit it too
|
||||||
if !slice.is_empty() {
|
if !slice.is_empty() {
|
||||||
let span = Span::styled(slice.to_owned(), style);
|
let span =
|
||||||
|
Span::styled(slice.replace('\t', " "), style);
|
||||||
spans.push(span);
|
spans.push(span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user