mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
Merge pull request #18503 from SomeoneToIgnore/kb/better-resolve-indexing
Use completion item indices instead of property matching when searching for the completion item to resolve
This commit is contained in:
commit
fc98e0657a
4 changed files with 34 additions and 16 deletions
|
@ -1131,7 +1131,7 @@ pub(crate) fn handle_completion_resolve(
|
|||
else {
|
||||
return Ok(original_completion);
|
||||
};
|
||||
let resolved_completions = to_proto::completion_items(
|
||||
let mut resolved_completions = to_proto::completion_items(
|
||||
&snap.config,
|
||||
&forced_resolve_completions_config.fields_to_resolve,
|
||||
&line_index,
|
||||
|
@ -1140,15 +1140,13 @@ pub(crate) fn handle_completion_resolve(
|
|||
resolve_data.trigger_character,
|
||||
resolved_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);
|
||||
};
|
||||
|
||||
let mut resolved_completion =
|
||||
if resolved_completions.get(resolve_data.completion_item_index).is_some() {
|
||||
resolved_completions.swap_remove(resolve_data.completion_item_index)
|
||||
} else {
|
||||
return Ok(original_completion);
|
||||
};
|
||||
|
||||
if !resolve_data.imports.is_empty() {
|
||||
let additional_edits = snap
|
||||
|
|
|
@ -826,6 +826,7 @@ pub struct CompletionResolveData {
|
|||
pub imports: Vec<CompletionImport>,
|
||||
pub version: Option<i32>,
|
||||
pub trigger_character: Option<char>,
|
||||
pub completion_item_index: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
|
|
@ -392,18 +392,36 @@ fn completion_item(
|
|||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
if something_to_resolve || !imports.is_empty() {
|
||||
let data = lsp_ext::CompletionResolveData {
|
||||
let (ref_resolve_data, resolve_data) = if something_to_resolve || !imports.is_empty() {
|
||||
let mut item_index = acc.len();
|
||||
let ref_resolve_data = if ref_match.is_some() {
|
||||
let ref_resolve_data = lsp_ext::CompletionResolveData {
|
||||
position: tdpp.clone(),
|
||||
imports: Vec::new(),
|
||||
version,
|
||||
trigger_character: completion_trigger_character,
|
||||
completion_item_index: item_index,
|
||||
};
|
||||
item_index += 1;
|
||||
Some(to_value(ref_resolve_data).unwrap())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let resolve_data = lsp_ext::CompletionResolveData {
|
||||
position: tdpp.clone(),
|
||||
imports,
|
||||
version,
|
||||
trigger_character: completion_trigger_character,
|
||||
completion_item_index: item_index,
|
||||
};
|
||||
lsp_item.data = Some(to_value(data).unwrap());
|
||||
}
|
||||
(ref_resolve_data, Some(to_value(resolve_data).unwrap()))
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
|
||||
if let Some((label, indel, relevance)) = ref_match {
|
||||
let mut lsp_item_with_ref = lsp_types::CompletionItem { label, ..lsp_item.clone() };
|
||||
let mut lsp_item_with_ref =
|
||||
lsp_types::CompletionItem { label, data: ref_resolve_data, ..lsp_item.clone() };
|
||||
lsp_item_with_ref
|
||||
.additional_text_edits
|
||||
.get_or_insert_with(Default::default)
|
||||
|
@ -412,6 +430,7 @@ fn completion_item(
|
|||
acc.push(lsp_item_with_ref);
|
||||
};
|
||||
|
||||
lsp_item.data = resolve_data;
|
||||
acc.push(lsp_item);
|
||||
|
||||
fn set_score(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<!---
|
||||
lsp/ext.rs hash: 90cf7718d54fe3c2
|
||||
lsp/ext.rs hash: 96f88b7a5d0080c6
|
||||
|
||||
If you need to change the above hash to make the test pass, please check if you
|
||||
need to adjust this doc as well and ping this issue:
|
||||
|
|
Loading…
Reference in a new issue