Omit completion fields to be resolved later
This commit is contained in:
parent
008d5130b7
commit
cc2686c1a9
4 changed files with 98 additions and 61 deletions
|
@ -43,11 +43,8 @@ pub struct CompletionFieldsToResolve {
|
||||||
pub resolve_tags: bool,
|
pub resolve_tags: bool,
|
||||||
pub resolve_detail: bool,
|
pub resolve_detail: bool,
|
||||||
pub resolve_documentation: bool,
|
pub resolve_documentation: bool,
|
||||||
pub resolve_sort_text: bool,
|
|
||||||
pub resolve_filter_text: bool,
|
pub resolve_filter_text: bool,
|
||||||
pub resolve_text_edit: bool,
|
pub resolve_text_edit: bool,
|
||||||
// FIXME: those are always resolved
|
|
||||||
// pub resolve_additional_text_edits: bool,
|
|
||||||
pub resolve_command: bool,
|
pub resolve_command: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +55,6 @@ impl CompletionFieldsToResolve {
|
||||||
resolve_tags: false,
|
resolve_tags: false,
|
||||||
resolve_detail: false,
|
resolve_detail: false,
|
||||||
resolve_documentation: false,
|
resolve_documentation: false,
|
||||||
resolve_sort_text: false,
|
|
||||||
resolve_filter_text: false,
|
resolve_filter_text: false,
|
||||||
resolve_text_edit: false,
|
resolve_text_edit: false,
|
||||||
resolve_command: false,
|
resolve_command: false,
|
||||||
|
|
|
@ -1421,7 +1421,6 @@ impl Config {
|
||||||
resolve_tags: client_capability_fields.contains("tags"),
|
resolve_tags: client_capability_fields.contains("tags"),
|
||||||
resolve_detail: client_capability_fields.contains("detail"),
|
resolve_detail: client_capability_fields.contains("detail"),
|
||||||
resolve_documentation: client_capability_fields.contains("documentation"),
|
resolve_documentation: client_capability_fields.contains("documentation"),
|
||||||
resolve_sort_text: client_capability_fields.contains("sortText"),
|
|
||||||
resolve_filter_text: client_capability_fields.contains("filterText"),
|
resolve_filter_text: client_capability_fields.contains("filterText"),
|
||||||
resolve_text_edit: client_capability_fields.contains("textEdit"),
|
resolve_text_edit: client_capability_fields.contains("textEdit"),
|
||||||
resolve_command: client_capability_fields.contains("command"),
|
resolve_command: client_capability_fields.contains("command"),
|
||||||
|
|
|
@ -1056,6 +1056,7 @@ pub(crate) fn handle_completion_resolve(
|
||||||
};
|
};
|
||||||
let source_root = snap.analysis.source_root_id(file_id)?;
|
let source_root = snap.analysis.source_root_id(file_id)?;
|
||||||
|
|
||||||
|
if !resolve_data.imports.is_empty() {
|
||||||
let additional_edits = snap
|
let additional_edits = snap
|
||||||
.analysis
|
.analysis
|
||||||
.resolve_completion_edits(
|
.resolve_completion_edits(
|
||||||
|
@ -1079,11 +1080,13 @@ pub(crate) fn handle_completion_resolve(
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(original_additional_edits) = original_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)
|
original_additional_edits.extend(additional_edits)
|
||||||
} else {
|
} else {
|
||||||
original_completion.additional_text_edits = Some(additional_edits);
|
original_completion.additional_text_edits = Some(additional_edits);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(original_completion)
|
Ok(original_completion)
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,14 +275,23 @@ fn completion_item(
|
||||||
) {
|
) {
|
||||||
let insert_replace_support = config.insert_replace_support().then_some(tdpp.position);
|
let insert_replace_support = config.insert_replace_support().then_some(tdpp.position);
|
||||||
let ref_match = item.ref_match();
|
let ref_match = item.ref_match();
|
||||||
let lookup = item.lookup().to_owned();
|
|
||||||
|
|
||||||
let mut additional_text_edits = Vec::new();
|
let mut additional_text_edits = Vec::new();
|
||||||
let mut something_to_resolve = false;
|
let mut something_to_resolve = false;
|
||||||
|
|
||||||
|
let filter_text = if fields_to_resolve.resolve_filter_text {
|
||||||
|
something_to_resolve = !item.lookup().is_empty();
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(item.lookup().to_owned())
|
||||||
|
};
|
||||||
|
|
||||||
// LSP does not allow arbitrary edits in completion, so we have to do a
|
// LSP does not allow arbitrary edits in completion, so we have to do a
|
||||||
// non-trivial mapping here.
|
// non-trivial mapping here.
|
||||||
let text_edit = {
|
let text_edit = if fields_to_resolve.resolve_text_edit {
|
||||||
|
something_to_resolve = true;
|
||||||
|
None
|
||||||
|
} else {
|
||||||
let mut text_edit = None;
|
let mut text_edit = None;
|
||||||
let source_range = item.source_range;
|
let source_range = item.source_range;
|
||||||
for indel in item.text_edit {
|
for indel in item.text_edit {
|
||||||
|
@ -305,25 +314,49 @@ fn completion_item(
|
||||||
additional_text_edits.push(text_edit);
|
additional_text_edits.push(text_edit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
text_edit.unwrap()
|
Some(text_edit.unwrap())
|
||||||
};
|
};
|
||||||
|
|
||||||
let insert_text_format = item.is_snippet.then_some(lsp_types::InsertTextFormat::SNIPPET);
|
let insert_text_format = item.is_snippet.then_some(lsp_types::InsertTextFormat::SNIPPET);
|
||||||
let tags = item.deprecated.then(|| vec![lsp_types::CompletionItemTag::DEPRECATED]);
|
let tags = if fields_to_resolve.resolve_tags {
|
||||||
|
something_to_resolve = item.deprecated;
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
item.deprecated.then(|| vec![lsp_types::CompletionItemTag::DEPRECATED])
|
||||||
|
};
|
||||||
let command = if item.trigger_call_info && config.client_commands().trigger_parameter_hints {
|
let command = if item.trigger_call_info && config.client_commands().trigger_parameter_hints {
|
||||||
|
if fields_to_resolve.resolve_command {
|
||||||
|
something_to_resolve = true;
|
||||||
Some(command::trigger_parameter_hints())
|
Some(command::trigger_parameter_hints())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let detail = if fields_to_resolve.resolve_detail {
|
||||||
|
something_to_resolve = item.detail.is_some();
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
item.detail
|
||||||
|
};
|
||||||
|
|
||||||
|
let documentation = if fields_to_resolve.resolve_documentation {
|
||||||
|
something_to_resolve = item.documentation.is_some();
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
item.documentation.map(documentation)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut lsp_item = lsp_types::CompletionItem {
|
let mut lsp_item = lsp_types::CompletionItem {
|
||||||
label: item.label.to_string(),
|
label: item.label.to_string(),
|
||||||
detail: item.detail,
|
detail,
|
||||||
filter_text: Some(lookup),
|
filter_text,
|
||||||
kind: Some(completion_item_kind(item.kind)),
|
kind: Some(completion_item_kind(item.kind)),
|
||||||
text_edit: Some(text_edit),
|
text_edit,
|
||||||
additional_text_edits: Some(additional_text_edits),
|
additional_text_edits: Some(additional_text_edits),
|
||||||
documentation: item.documentation.map(documentation),
|
documentation,
|
||||||
deprecated: Some(item.deprecated),
|
deprecated: Some(item.deprecated),
|
||||||
tags,
|
tags,
|
||||||
command,
|
command,
|
||||||
|
@ -332,26 +365,33 @@ fn completion_item(
|
||||||
};
|
};
|
||||||
|
|
||||||
if config.completion_label_details_support() {
|
if config.completion_label_details_support() {
|
||||||
|
if fields_to_resolve.resolve_label_details {
|
||||||
|
something_to_resolve = true;
|
||||||
|
} else {
|
||||||
lsp_item.label_details = Some(lsp_types::CompletionItemLabelDetails {
|
lsp_item.label_details = Some(lsp_types::CompletionItemLabelDetails {
|
||||||
detail: item.label_detail.as_ref().map(ToString::to_string),
|
detail: item.label_detail.as_ref().map(ToString::to_string),
|
||||||
description: lsp_item.detail.clone(),
|
description: lsp_item.detail.clone(),
|
||||||
});
|
});
|
||||||
|
}
|
||||||
} else if let Some(label_detail) = item.label_detail {
|
} else if let Some(label_detail) = item.label_detail {
|
||||||
lsp_item.label.push_str(label_detail.as_str());
|
lsp_item.label.push_str(label_detail.as_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
set_score(&mut lsp_item, max_relevance, item.relevance);
|
set_score(&mut lsp_item, max_relevance, item.relevance);
|
||||||
|
|
||||||
|
let imports =
|
||||||
if config.completion(None).enable_imports_on_the_fly && !item.import_to_add.is_empty() {
|
if config.completion(None).enable_imports_on_the_fly && !item.import_to_add.is_empty() {
|
||||||
let imports = item
|
item.import_to_add
|
||||||
.import_to_add
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(import_path, import_name)| lsp_ext::CompletionImport {
|
.map(|(import_path, import_name)| lsp_ext::CompletionImport {
|
||||||
full_import_path: import_path,
|
full_import_path: import_path,
|
||||||
imported_name: import_name,
|
imported_name: import_name,
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect()
|
||||||
if !imports.is_empty() {
|
} else {
|
||||||
|
Vec::new()
|
||||||
|
};
|
||||||
|
if something_to_resolve || !imports.is_empty() {
|
||||||
let data = lsp_ext::CompletionResolveData {
|
let data = lsp_ext::CompletionResolveData {
|
||||||
position: tdpp.clone(),
|
position: tdpp.clone(),
|
||||||
imports,
|
imports,
|
||||||
|
@ -360,7 +400,6 @@ fn completion_item(
|
||||||
};
|
};
|
||||||
lsp_item.data = Some(to_value(data).unwrap());
|
lsp_item.data = Some(to_value(data).unwrap());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Some((label, indel, relevance)) = ref_match {
|
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, ..lsp_item.clone() };
|
||||||
|
|
Loading…
Add table
Reference in a new issue