Add flyimport completion for trait assoc items

This commit is contained in:
Kirill Bulatov
2021-01-05 10:34:03 +02:00
parent 9a349f280f
commit db335a1bbf
18 changed files with 661 additions and 247 deletions

View File

@@ -93,7 +93,7 @@ impl BenchCmd {
if is_completion {
let options = CompletionConfig {
enable_postfix_completions: true,
enable_autoimport_completions: true,
enable_imports_on_the_fly: true,
add_call_parenthesis: true,
add_call_argument_snippets: true,
snippet_cap: SnippetCap::new(true),

View File

@@ -559,7 +559,7 @@ impl Config {
pub fn completion(&self) -> CompletionConfig {
CompletionConfig {
enable_postfix_completions: self.data.completion_postfix_enable,
enable_autoimport_completions: self.data.completion_autoimport_enable
enable_imports_on_the_fly: self.data.completion_autoimport_enable
&& completion_item_edit_resolve(&self.caps),
add_call_parenthesis: self.data.completion_addCallParenthesis,
add_call_argument_snippets: self.data.completion_addCallArgumentSnippets,
@@ -581,18 +581,7 @@ impl Config {
AssistConfig {
snippet_cap: SnippetCap::new(self.experimental("snippetTextEdit")),
allowed: None,
insert_use: InsertUseConfig {
merge: match self.data.assist_importMergeBehavior {
MergeBehaviorDef::None => None,
MergeBehaviorDef::Full => Some(MergeBehavior::Full),
MergeBehaviorDef::Last => Some(MergeBehavior::Last),
},
prefix_kind: match self.data.assist_importPrefix {
ImportPrefixDef::Plain => PrefixKind::Plain,
ImportPrefixDef::ByCrate => PrefixKind::ByCrate,
ImportPrefixDef::BySelf => PrefixKind::BySelf,
},
},
insert_use: self.insert_use_config(),
}
}
pub fn call_info_full(&self) -> bool {

View File

@@ -653,7 +653,7 @@ pub(crate) fn handle_completion(
let mut new_completion_items =
to_proto::completion_item(&line_index, line_endings, item.clone());
if completion_config.enable_autoimport_completions {
if completion_config.enable_imports_on_the_fly {
for new_item in &mut new_completion_items {
fill_resolve_data(&mut new_item.data, &item, &text_document_position);
}
@@ -703,6 +703,7 @@ pub(crate) fn handle_completion_resolve(
FilePosition { file_id, offset },
&resolve_data.full_import_path,
resolve_data.imported_name,
resolve_data.import_for_trait_assoc_item,
)?
.into_iter()
.flat_map(|edit| {
@@ -1694,6 +1695,7 @@ struct CompletionResolveData {
position: lsp_types::TextDocumentPositionParams,
full_import_path: String,
imported_name: String,
import_for_trait_assoc_item: bool,
}
fn fill_resolve_data(
@@ -1710,6 +1712,7 @@ fn fill_resolve_data(
position: position.to_owned(),
full_import_path,
imported_name,
import_for_trait_assoc_item: import_edit.import_for_trait_assoc_item,
})
.unwrap(),
);

View File

@@ -884,7 +884,7 @@ mod tests {
.completions(
&ide::CompletionConfig {
enable_postfix_completions: true,
enable_autoimport_completions: true,
enable_imports_on_the_fly: true,
add_call_parenthesis: true,
add_call_argument_snippets: true,
snippet_cap: SnippetCap::new(true),