diff --git a/lapce-core/src/command.rs b/lapce-core/src/command.rs index 47829caf..ce99e8f1 100644 --- a/lapce-core/src/command.rs +++ b/lapce-core/src/command.rs @@ -238,6 +238,8 @@ pub enum FocusCommand { BottomOfWindow, #[strum(serialize = "show_code_actions")] ShowCodeActions, + #[strum(serialize = "get_completion")] + GetCompletion, /// This will close a modal, such as the settings window or completion #[strum(message = "Close Modal")] #[strum(serialize = "modal.close")] diff --git a/lapce-data/src/editor.rs b/lapce-data/src/editor.rs index 1f8eb0d9..6e0cf4fd 100644 --- a/lapce-data/src/editor.rs +++ b/lapce-data/src/editor.rs @@ -412,7 +412,13 @@ pub fn cancel_hover(&mut self) { hover.cancel(); } - fn update_completion(&mut self, ctx: &mut EventCtx) { + /// Update the displayed autocompletion box + /// Sends a request to the LSP for completion information + fn update_completion( + &mut self, + ctx: &mut EventCtx, + display_if_empty_input: bool, + ) { if self.get_mode() != Mode::Insert { self.cancel_completion(); return; @@ -440,7 +446,8 @@ fn update_completion(&mut self, ctx: &mut EventCtx) { .to_string() }; let completion = Arc::make_mut(&mut self.completion); - if input.is_empty() && char != "." && char != ":" { + if !display_if_empty_input && input.is_empty() && char != "." && char != ":" + { completion.cancel(); return; } @@ -1246,7 +1253,7 @@ fn run_edit_command( } } - self.update_completion(ctx); + self.update_completion(ctx, false); self.apply_deltas(&deltas); CommandExecuted::Yes @@ -1678,6 +1685,10 @@ fn run_focus_command( Target::Widget(self.editor.editor_id), )); } + GetCompletion => { + // we allow empty inputs to allow for cases where the user wants to get the autocompletion beforehand + self.update_completion(ctx, true); + } GotoDefinition => { let offset = self.editor.cursor.offset(); let start_offset = self.doc.buffer().prev_code_boundary(offset); @@ -1966,7 +1977,7 @@ fn receive_char(&mut self, ctx: &mut EventCtx, c: &str) { let cursor = &mut Arc::make_mut(&mut self.editor).cursor; let deltas = doc.do_insert(cursor, c); - self.update_completion(ctx); + self.update_completion(ctx, false); self.cancel_hover(); self.apply_deltas(&deltas); } else if let Some(direction) = self.editor.inline_find.clone() {