aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-05-29 15:26:27 +0000
committerBlaž Hrastnik2021-05-30 01:36:58 +0000
commit3810650a6bde441ce946a6983e6c46d423e12724 (patch)
tree7fee1a215ea7e2553ba0b7f8449a4e12682232f5 /helix-term/src
parent2c48d65b1565cf68a3efb5c9e91e9011526f43e7 (diff)
Completion: Render non-markdown docs too
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/ui/completion.rs50
1 files changed, 35 insertions, 15 deletions
diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs
index a757406b..a75a4d6c 100644
--- a/helix-term/src/ui/completion.rs
+++ b/helix-term/src/ui/completion.rs
@@ -230,32 +230,52 @@ impl Component for Completion {
// option.detail
// ---
// option.documentation
- match &option.documentation {
- Some(lsp::Documentation::String(s))
+
+ let doc = match &option.documentation {
+ Some(lsp::Documentation::String(contents))
| Some(lsp::Documentation::MarkupContent(lsp::MarkupContent {
kind: lsp::MarkupKind::PlainText,
- value: s,
+ value: contents,
})) => {
// TODO: convert to wrapped text
- let doc = s;
+ Markdown::new(format!(
+ "```rust\n{}\n```\n{}",
+ option.detail.as_deref().unwrap_or_default(),
+ contents.clone()
+ ))
}
Some(lsp::Documentation::MarkupContent(lsp::MarkupContent {
kind: lsp::MarkupKind::Markdown,
value: contents,
})) => {
- let doc = Markdown::new(contents.clone());
- let half = area.height / 2;
- let height = 15.min(half);
- // -2 to subtract command line + statusline. a bit of a hack, because of splits.
- let area = Rect::new(0, area.height - height - 2, area.width, height);
+ // TODO: set language based on doc scope
+ Markdown::new(format!(
+ "```rust\n{}\n```\n{}",
+ option.detail.as_deref().unwrap_or_default(),
+ contents.clone()
+ ))
+ }
+ None if option.detail.is_some() => {
+ // TODO: copied from above
- // clear area
- let background = cx.editor.theme.get("ui.popup");
- surface.clear_with(area, background);
- doc.render(area, surface, cx);
+ // TODO: set language based on doc scope
+ Markdown::new(format!(
+ "```rust\n{}\n```",
+ option.detail.as_deref().unwrap_or_default(),
+ ))
}
- None => (),
- }
+ None => return,
+ };
+
+ let half = area.height / 2;
+ let height = 15.min(half);
+ // -2 to subtract command line + statusline. a bit of a hack, because of splits.
+ let area = Rect::new(0, area.height - height - 2, area.width, height);
+
+ // clear area
+ let background = cx.editor.theme.get("ui.popup");
+ surface.clear_with(area, background);
+ doc.render(area, surface, cx);
}
}
}