on master help sign in
Completion: Render non-markdown docs too
commit3810650a6bde441ce946a6983e6c46d423e12724 authorBlaž Hrastnik <blaz@mxxn.io> dateSun 30 May 2021, 00:26 (5 years ago) parent2c48d65
1 file changed+35−15
helix-term/src/ui/completion.rs+35−15
helix-term/src/ui/completion.rs+35−15
@@ -230,32 +230,52 @@ impl Component for Completion {
230230 // option.detail
231231 // ---
232232 // option.documentation
233− match &option.documentation {
234− Some(lsp::Documentation::String(s))
233+
234+ let doc = match &option.documentation {
235+ Some(lsp::Documentation::String(contents))
235236 | Some(lsp::Documentation::MarkupContent(lsp::MarkupContent {
236237 kind: lsp::MarkupKind::PlainText,
237− value: s,
238+ value: contents,
238239 })) => {
239240 // TODO: convert to wrapped text
240− let doc = s;
241+ Markdown::new(format!(
242+ "```rust\n{}\n```\n{}",
243+ option.detail.as_deref().unwrap_or_default(),
244+ contents.clone()
245+ ))
241246 }
242247 Some(lsp::Documentation::MarkupContent(lsp::MarkupContent {
243248 kind: lsp::MarkupKind::Markdown,
244249 value: contents,
245250 })) => {
246− let doc = Markdown::new(contents.clone());
247− let half = area.height / 2;
248− let height = 15.min(half);
249− // -2 to subtract command line + statusline. a bit of a hack, because of splits.
250− let area = Rect::new(0, area.height - height - 2, area.width, height);
251+ // TODO: set language based on doc scope
252+ Markdown::new(format!(
253+ "```rust\n{}\n```\n{}",
254+ option.detail.as_deref().unwrap_or_default(),
255+ contents.clone()
256+ ))
257+ }
258+ None if option.detail.is_some() => {
259+ // TODO: copied from above
251260
252− // clear area
253− let background = cx.editor.theme.get("ui.popup");
254− surface.clear_with(area, background);
255− doc.render(area, surface, cx);
261+ // TODO: set language based on doc scope
262+ Markdown::new(format!(
263+ "```rust\n{}\n```",
264+ option.detail.as_deref().unwrap_or_default(),
265+ ))
256266 }
257− None => (),
258− }
267+ None => return,
268+ };
269+
270+ let half = area.height / 2;
271+ let height = 15.min(half);
272+ // -2 to subtract command line + statusline. a bit of a hack, because of splits.
273+ let area = Rect::new(0, area.height - height - 2, area.width, height);
274+
275+ // clear area
276+ let background = cx.editor.theme.get("ui.popup");
277+ surface.clear_with(area, background);
278+ doc.render(area, surface, cx);
259279 }
260280 }
261281}