From 4c95c6e25d7765798fc527f11beb6c039c6adabe Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 25 Nov 2020 00:02:45 +0200 Subject: [PATCH 1/2] Gate autoimports begind experimental completions flag --- crates/completion/src/completions/unqualified_path.rs | 4 +++- crates/completion/src/config.rs | 2 ++ crates/rust-analyzer/src/config.rs | 3 +++ editors/code/package.json | 5 +++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index 86c143b637f..4f1c9faa083 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs @@ -44,7 +44,9 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC acc.add_resolution(ctx, name.to_string(), &res) }); - fuzzy_completion(acc, ctx).unwrap_or_default() + if ctx.config.enable_experimental_completions { + fuzzy_completion(acc, ctx).unwrap_or_default() + } } fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &Type) { diff --git a/crates/completion/src/config.rs b/crates/completion/src/config.rs index 82874ff256a..f5073537295 100644 --- a/crates/completion/src/config.rs +++ b/crates/completion/src/config.rs @@ -9,6 +9,7 @@ #[derive(Clone, Debug, PartialEq, Eq)] pub struct CompletionConfig { pub enable_postfix_completions: bool, + pub enable_experimental_completions: bool, pub add_call_parenthesis: bool, pub add_call_argument_snippets: bool, pub snippet_cap: Option, @@ -30,6 +31,7 @@ impl Default for CompletionConfig { fn default() -> Self { CompletionConfig { enable_postfix_completions: true, + enable_experimental_completions: true, add_call_parenthesis: true, add_call_argument_snippets: true, snippet_cap: Some(SnippetCap { _private: () }), diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 5fc6800cf2f..a334cdb116a 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -184,6 +184,7 @@ pub fn new(root_path: AbsPathBuf) -> Self { }, completion: CompletionConfig { enable_postfix_completions: true, + enable_experimental_completions: true, add_call_parenthesis: true, add_call_argument_snippets: true, ..CompletionConfig::default() @@ -306,6 +307,7 @@ pub fn update(&mut self, json: serde_json::Value) { }; self.completion.enable_postfix_completions = data.completion_postfix_enable; + self.completion.enable_experimental_completions = data.completion_enableExperimental; self.completion.add_call_parenthesis = data.completion_addCallParenthesis; self.completion.add_call_argument_snippets = data.completion_addCallArgumentSnippets; self.completion.merge = self.assist.insert_use.merge; @@ -506,6 +508,7 @@ struct ConfigData { completion_addCallArgumentSnippets: bool = true, completion_addCallParenthesis: bool = true, completion_postfix_enable: bool = true, + completion_enableExperimental: bool = true, diagnostics_enable: bool = true, diagnostics_enableExperimental: bool = true, diff --git a/editors/code/package.json b/editors/code/package.json index a2d6b1148fa..5bf72075f50 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -460,6 +460,11 @@ "default": true, "markdownDescription": "Whether to show postfix snippets like `dbg`, `if`, `not`, etc." }, + "rust-analyzer.completion.enableExperimental": { + "type": "boolean", + "default": true, + "markdownDescription": "Display additional completions with potential false positives and performance issues" + }, "rust-analyzer.callInfo.full": { "type": "boolean", "default": true, From 9812150047ea5f53631762e83ed25177e821857f Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 25 Nov 2020 00:42:58 +0200 Subject: [PATCH 2/2] Document experimental completions --- crates/completion/src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/completion/src/lib.rs b/crates/completion/src/lib.rs index cb6e0554e9a..aecc1378b1b 100644 --- a/crates/completion/src/lib.rs +++ b/crates/completion/src/lib.rs @@ -67,6 +67,13 @@ // fn test_name() {} // } // ``` +// +// And experimental completions, enabled with the `rust-analyzer.completion.enableExperimental` setting. +// This flag enables or disables: +// +// - Auto import: additional completion options with automatic `use` import and options from all project importable items, matched for the input +// +// Experimental completions might cause issues with performance and completion list look. /// Main entry point for completion. We run completion as a two-phase process. ///