@@ -3,7 +3,7 @@ use crate::{
33 compositor::{Component, Compositor, Context, EventResult},
44 key,
55 keymap::{self, Keymaps},
6− ui::text_color,
6+ ui::{text_color, Completion},
77};
88
99use helix_core::{
@@ -29,6 +29,7 @@ pub struct EditorView {
2929 on_next_key: Option<Box<dyn FnOnce(&mut commands::Context, KeyEvent)>>,
3030 status_msg: Option<String>,
3131 last_insert: (commands::Command, Vec<KeyEvent>),
32+ completion: Option<Completion>,
3233}
3334
3435const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
@@ -40,6 +41,7 @@ impl EditorView {
4041 on_next_key: None,
4142 status_msg: None,
4243 last_insert: (commands::normal_mode, Vec::new()),
44+ completion: None,
4345 }
4446 }
4547
@@ -435,15 +437,15 @@ impl EditorView {
435437 );
436438 }
437439
438− fn insert_mode(&self, cxt: &mut commands::Context, event: KeyEvent) {
440+ fn insert_mode(&self, cx: &mut commands::Context, event: KeyEvent) {
439441 if let Some(command) = self.keymap[&Mode::Insert].get(&event) {
440− command(cxt);
442+ command(cx);
441443 } else if let KeyEvent {
442444 code: KeyCode::Char(ch),
443445 ..
444446 } = event
445447 {
446− commands::insert::insert_char(cxt, ch);
448+ commands::insert::insert_char(cx, ch);
447449 }
448450 }
449451
@@ -476,6 +478,18 @@ impl EditorView {
476478 }
477479 }
478480 }
481+
482+ pub fn set_completion(
483+ &mut self,
484+ items: Vec<helix_lsp::lsp::CompletionItem>,
485+ trigger_offset: usize,
486+ size: Rect,
487+ ) {
488+ let mut completion = Completion::new(items, trigger_offset);
489+ // TODO : propagate required size on resize to completion too
490+ completion.required_size((size.width, size.height));
491+ self.completion = Some(completion);
492+ }
479493}
480494
481495impl Component for EditorView {
@@ -512,7 +526,15 @@ impl Component for EditorView {
512526 // record last_insert key
513527 self.last_insert.1.push(event);
514528
515− self.insert_mode(&mut cxt, event)
529+ self.insert_mode(&mut cxt, event);
530+
531+ if let Some(completion) = &mut self.completion {
532+ completion.update(&mut cxt);
533+ if completion.is_empty() {
534+ self.completion = None;
535+ }
536+ // TODO: if exiting InsertMode, remove completion
537+ }
516538 }
517539 mode => self.command_mode(mode, &mut cxt, event),
518540 }
@@ -547,6 +569,11 @@ impl Component for EditorView {
547569 let doc = cx.editor.document(view.doc).unwrap();
548570 self.render_view(doc, view, view.area, surface, &cx.editor.theme, is_focused);
549571 }
572+
573+ if let Some(completion) = &self.completion {
574+ completion.render(area, surface, cx)
575+ // render completion here
576+ }
550577 }
551578
552579 fn cursor_position(&self, area: Rect, editor: &Editor) -> Option<Position> {