diff options
author | Pascal Kuthe | 2023-04-04 23:38:17 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2023-05-18 06:16:50 +0000 |
commit | 9c558fc4705934097b5f20b100462fc1fa4f50e1 (patch) | |
tree | 75271bddb0add9c78fa25fcc0a71399a98da13b2 /helix-term/src | |
parent | 30ff7f8db29d5fc84191268b94ec971e7ca5da5d (diff) |
ensure correct trigger/start completion offset
When re requesting a completion that already has a selected item we
reuse that selections savepoint. However, the selection has likely
changed since that savepoint which requires us to use the selection
from that savepoint
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/commands.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 8d70cd9e..80774cea 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4210,16 +4210,23 @@ pub fn completion(cx: &mut Context) { let (view, doc) = current!(cx.editor); + let savepoint = if let Some(CompleteAction::Selected { savepoint }) = &cx.editor.last_completion + { + savepoint.clone() + } else { + doc.savepoint(view) + }; + let language_server = match doc.language_server() { Some(language_server) => language_server, None => return, }; let offset_encoding = language_server.offset_encoding(); - let text = doc.text().slice(..); - let cursor = doc.selection(view.id).primary().cursor(text); + let text = savepoint.text.clone(); + let cursor = savepoint.cursor(); - let pos = pos_to_lsp_pos(doc.text(), cursor, offset_encoding); + let pos = pos_to_lsp_pos(&text, cursor, offset_encoding); let future = match language_server.completion(doc.identifier(), pos, None) { Some(future) => future, @@ -4254,12 +4261,6 @@ pub fn completion(cx: &mut Context) { iter.reverse(); let offset = iter.take_while(|ch| chars::char_is_word(*ch)).count(); let start_offset = cursor.saturating_sub(offset); - let savepoint = if let Some(CompleteAction::Selected { savepoint }) = &cx.editor.last_completion - { - savepoint.clone() - } else { - doc.savepoint(view) - }; let trigger_doc = doc.id(); let trigger_view = view.id; |