From 23abd97cf0109fcce59bf9e390173c4a35af0ed8 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 25 Nov 2024 23:33:11 +0200 Subject: [PATCH] Revert "Resolve completion items" This reverts commit ecae5a8b33abfa7b084aa0bd29d47f5b98ea2527. --- .../rust-analyzer/src/handlers/request.rs | 49 ++++--------------- .../crates/rust-analyzer/src/lsp/ext.rs | 2 +- .../crates/rust-analyzer/src/lsp/to_proto.rs | 2 +- 3 files changed, 11 insertions(+), 42 deletions(-) diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs index 80d8c53801f..7d5a3946db1 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs @@ -10,9 +10,9 @@ use std::{ use anyhow::Context; use ide::{ - AnnotationConfig, AssistKind, AssistResolveStrategy, Cancellable, CompletionFieldsToResolve, - FilePosition, FileRange, HoverAction, HoverGotoTypeData, InlayFieldsToResolve, Query, - RangeInfo, ReferenceCategory, Runnable, RunnableKind, SingleResolve, SourceChange, TextEdit, + AnnotationConfig, AssistKind, AssistResolveStrategy, Cancellable, FilePosition, FileRange, + HoverAction, HoverGotoTypeData, InlayFieldsToResolve, Query, RangeInfo, ReferenceCategory, + Runnable, RunnableKind, SingleResolve, SourceChange, TextEdit, }; use ide_db::SymbolKind; use itertools::Itertools; @@ -1056,43 +1056,12 @@ pub(crate) fn handle_completion_resolve( }; let source_root = snap.analysis.source_root_id(file_id)?; - let mut forced_resolve_completions_config = snap.config.completion(Some(source_root)); - forced_resolve_completions_config.fields_to_resolve = CompletionFieldsToResolve::empty(); - - let position = FilePosition { file_id, offset }; - let Some(unresolved_completions) = snap.analysis.completions( - &&forced_resolve_completions_config, - position, - resolve_data.trigger_character, - )? - else { - return Ok(original_completion); - }; - let resolved_completions = to_proto::completion_items( - &snap.config, - &forced_resolve_completions_config.fields_to_resolve, - &line_index, - snap.file_version(position.file_id), - resolve_data.position, - resolve_data.trigger_character, - unresolved_completions, - ); - let Some(mut resolved_completion) = resolved_completions.into_iter().find(|completion| { - completion.label == original_completion.label - && completion.kind == original_completion.kind - && completion.deprecated == original_completion.deprecated - && completion.preselect == original_completion.preselect - && completion.sort_text == original_completion.sort_text - }) else { - return Ok(original_completion); - }; - if !resolve_data.imports.is_empty() { let additional_edits = snap .analysis .resolve_completion_edits( - &forced_resolve_completions_config, - position, + &snap.config.completion(Some(source_root)), + FilePosition { file_id, offset }, resolve_data .imports .into_iter() @@ -1102,7 +1071,7 @@ pub(crate) fn handle_completion_resolve( .flat_map(|edit| edit.into_iter().map(|indel| to_proto::text_edit(&line_index, indel))) .collect::>(); - if !all_edits_are_disjoint(&resolved_completion, &additional_edits) { + if !all_edits_are_disjoint(&original_completion, &additional_edits) { return Err(LspError::new( ErrorCode::InternalError as i32, "Import edit overlaps with the original completion edits, this is not LSP-compliant" @@ -1111,15 +1080,15 @@ pub(crate) fn handle_completion_resolve( .into()); } - if let Some(original_additional_edits) = resolved_completion.additional_text_edits.as_mut() + if let Some(original_additional_edits) = original_completion.additional_text_edits.as_mut() { original_additional_edits.extend(additional_edits) } else { - resolved_completion.additional_text_edits = Some(additional_edits); + original_completion.additional_text_edits = Some(additional_edits); } } - Ok(resolved_completion) + Ok(original_completion) } pub(crate) fn handle_folding_range( diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/ext.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/ext.rs index 8039f0644ee..990fadc6719 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/ext.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/ext.rs @@ -825,7 +825,7 @@ pub struct CompletionResolveData { pub position: lsp_types::TextDocumentPositionParams, pub imports: Vec, pub version: Option, - pub trigger_character: Option, + pub completion_trigger_character: Option, } #[derive(Debug, Serialize, Deserialize)] diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs index c6a57c6114c..c7f4b22a771 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs @@ -396,7 +396,7 @@ fn completion_item( position: tdpp.clone(), imports, version, - trigger_character: completion_trigger_character, + completion_trigger_character, }; lsp_item.data = Some(to_value(data).unwrap()); }