on master help sign in
ui: Draft for completion doc preview.
commit3038c2ef6d392a570aaed9c7d51427363c43046d authorBlaž Hrastnik <blaz@mxxn.io> dateMon 3 May 2021, 18:22 (5 years ago) parentab4decf
1 file changed+43−2
helix-term/src/ui/completion.rs+43−2
helix-term/src/ui/completion.rs+43−2
@@ -13,7 +13,7 @@ use helix_core::{Position, Transaction};
1313use helix_view::Editor;
1414
1515use crate::commands;
16−use crate::ui::{Menu, Popup, PromptEvent};
16+use crate::ui::{Markdown, Menu, Popup, PromptEvent};
1717
1818use helix_lsp::lsp;
1919use lsp::CompletionItem;
@@ -173,6 +173,47 @@ impl Component for Completion {
173173 }
174174
175175 fn render(&self, area: Rect, surface: &mut Surface, cx: &mut Context) {
176− self.popup.render(area, surface, cx)
176+ self.popup.render(area, surface, cx);
177+
178+ // TODO: if we have a selection, render a markdown popup on top/below with info
179+ if let Some(option) = self.popup.contents().selection() {
180+ // need to render:
181+ // option.detail
182+ // ---
183+ // option.documentation
184+ match &option.documentation {
185+ Some(lsp::Documentation::String(s))
186+ | Some(lsp::Documentation::MarkupContent(lsp::MarkupContent {
187+ kind: lsp::MarkupKind::PlainText,
188+ value: s,
189+ })) => {
190+ // TODO: convert to wrapped text
191+ let doc = s;
192+ }
193+ Some(lsp::Documentation::MarkupContent(lsp::MarkupContent {
194+ kind: lsp::MarkupKind::Markdown,
195+ value: contents,
196+ })) => {
197+ let doc = Markdown::new(contents.clone());
198+ let half = area.height / 2;
199+ let height = 15.min(half);
200+ // -2 to subtract command line + statusline. a bit of a hack, because of splits.
201+ let area = Rect::new(0, area.height - height - 2, area.width, height);
202+
203+ // clear area
204+ let background = cx.editor.theme.get("ui.popup");
205+ for y in area.top()..area.bottom() {
206+ for x in area.left()..area.right() {
207+ let cell = surface.get_mut(x, y);
208+ cell.reset();
209+ // cell.symbol.clear();
210+ cell.set_style(background);
211+ }
212+ }
213+ doc.render(area, surface, cx);
214+ }
215+ None => (),
216+ }
217+ }
177218 }
178219}