From 1d5d5dab4718b9db40a20037c1cb1edf66f7991a Mon Sep 17 00:00:00 2001 From: Philipp Mildenberger Date: Mon, 20 Mar 2023 00:02:41 +0100 Subject: [PATCH] Remove offset_encoding in CompletionItem --- helix-term/src/commands.rs | 1 - helix-term/src/ui/completion.rs | 31 ++++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 060c9d837..772db6f85 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4269,7 +4269,6 @@ pub fn completion(cx: &mut Context) { .map(|item| CompletionItem { item, language_server_id, - offset_encoding, resolved: false, }) .collect(); diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index 980bc8b6a..e62efdaca 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -88,7 +88,6 @@ impl menu::Item for CompletionItem { pub struct CompletionItem { pub item: lsp::CompletionItem, pub language_server_id: usize, - pub offset_encoding: OffsetEncoding, pub resolved: bool, } @@ -121,6 +120,7 @@ impl Completion { doc: &Document, view_id: ViewId, item: &CompletionItem, + offset_encoding: OffsetEncoding, trigger_offset: usize, include_placeholder: bool, replace_mode: bool, @@ -143,8 +143,6 @@ impl Completion { } }; - let offset_encoding = item.offset_encoding; - let Some(range) = util::lsp_range_to_range(doc.text(), edit.range, offset_encoding) else{ return Transaction::new(doc.text()); }; @@ -238,8 +236,21 @@ impl Completion { // always present here let item = item.unwrap(); - let transaction = - item_to_transaction(doc, view.id, item, trigger_offset, true, replace_mode); + let offset_encoding = editor + .language_servers + .get_by_id(item.language_server_id) + .expect("language server disappeared between completion request and application") + .offset_encoding(); + + let transaction = item_to_transaction( + doc, + view.id, + item, + offset_encoding, + trigger_offset, + true, + replace_mode, + ); doc.apply_temporary(&transaction, view.id); } PromptEvent::Validate => { @@ -251,6 +262,12 @@ impl Completion { // always present here let mut item = item.unwrap().clone(); + let offset_encoding = editor + .language_servers + .get_by_id(item.language_server_id) + .expect("language server disappeared between completion request and application") + .offset_encoding(); + let language_server = editor .language_servers .get_by_id(item.language_server_id) @@ -270,6 +287,7 @@ impl Completion { doc, view.id, &item, + offset_encoding, trigger_offset, false, replace_mode, @@ -287,7 +305,7 @@ impl Completion { let transaction = util::generate_transaction_from_edits( doc.text(), additional_edits, - item.offset_encoding, // TODO: should probably transcode in Client + offset_encoding, // TODO: should probably transcode in Client ); doc.apply(&transaction, view.id); } @@ -414,7 +432,6 @@ impl Completion { let resolved_item = CompletionItem { item: resolved_item, language_server_id: current_item.language_server_id, - offset_encoding: current_item.offset_encoding, resolved: true, };