aboutsummaryrefslogtreecommitdiff
path: root/crates/completion
diff options
context:
space:
mode:
Diffstat (limited to 'crates/completion')
-rw-r--r--crates/completion/src/completions/unqualified_path.rs58
-rw-r--r--crates/completion/src/config.rs2
-rw-r--r--crates/completion/src/lib.rs7
-rw-r--r--crates/completion/src/render.rs1
4 files changed, 41 insertions, 27 deletions
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs
index 86c143b63..3bd776905 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
44 acc.add_resolution(ctx, name.to_string(), &res) 44 acc.add_resolution(ctx, name.to_string(), &res)
45 }); 45 });
46 46
47 fuzzy_completion(acc, ctx).unwrap_or_default() 47 if ctx.config.enable_experimental_completions {
48 fuzzy_completion(acc, ctx).unwrap_or_default()
49 }
48} 50}
49 51
50fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &Type) { 52fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &Type) {
@@ -79,32 +81,34 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
79 81
80 let potential_import_name = ctx.token.to_string(); 82 let potential_import_name = ctx.token.to_string();
81 83
82 let possible_imports = 84 let possible_imports = imports_locator::find_similar_imports(
83 imports_locator::find_similar_imports(&ctx.sema, ctx.krate?, &potential_import_name, 400) 85 &ctx.sema,
84 .filter_map(|import_candidate| match import_candidate { 86 ctx.krate?,
85 // when completing outside the use declaration, modules are pretty useless 87 &potential_import_name,
86 // and tend to bloat the completion suggestions a lot 88 50,
87 Either::Left(ModuleDef::Module(_)) => None, 89 true,
88 Either::Left(module_def) => Some(( 90 )
89 current_module.find_use_path(ctx.db, module_def)?, 91 .filter_map(|import_candidate| {
90 ScopeDef::ModuleDef(module_def), 92 Some(match import_candidate {
91 )), 93 Either::Left(module_def) => {
92 Either::Right(macro_def) => Some(( 94 (current_module.find_use_path(ctx.db, module_def)?, ScopeDef::ModuleDef(module_def))
93 current_module.find_use_path(ctx.db, macro_def)?, 95 }
94 ScopeDef::MacroDef(macro_def), 96 Either::Right(macro_def) => {
95 )), 97 (current_module.find_use_path(ctx.db, macro_def)?, ScopeDef::MacroDef(macro_def))
96 }) 98 }
97 .filter(|(mod_path, _)| mod_path.len() > 1) 99 })
98 .filter_map(|(import_path, definition)| { 100 })
99 render_resolution_with_import( 101 .filter(|(mod_path, _)| mod_path.len() > 1)
100 RenderContext::new(ctx), 102 .take(20)
101 import_path.clone(), 103 .filter_map(|(import_path, definition)| {
102 import_scope.clone(), 104 render_resolution_with_import(
103 ctx.config.merge, 105 RenderContext::new(ctx),
104 &definition, 106 import_path.clone(),
105 ) 107 import_scope.clone(),
106 }) 108 ctx.config.merge,
107 .take(20); 109 &definition,
110 )
111 });
108 112
109 acc.add_all(possible_imports); 113 acc.add_all(possible_imports);
110 Some(()) 114 Some(())
diff --git a/crates/completion/src/config.rs b/crates/completion/src/config.rs
index 82874ff25..f50735372 100644
--- a/crates/completion/src/config.rs
+++ b/crates/completion/src/config.rs
@@ -9,6 +9,7 @@ use assists::utils::MergeBehaviour;
9#[derive(Clone, Debug, PartialEq, Eq)] 9#[derive(Clone, Debug, PartialEq, Eq)]
10pub struct CompletionConfig { 10pub struct CompletionConfig {
11 pub enable_postfix_completions: bool, 11 pub enable_postfix_completions: bool,
12 pub enable_experimental_completions: bool,
12 pub add_call_parenthesis: bool, 13 pub add_call_parenthesis: bool,
13 pub add_call_argument_snippets: bool, 14 pub add_call_argument_snippets: bool,
14 pub snippet_cap: Option<SnippetCap>, 15 pub snippet_cap: Option<SnippetCap>,
@@ -30,6 +31,7 @@ impl Default for CompletionConfig {
30 fn default() -> Self { 31 fn default() -> Self {
31 CompletionConfig { 32 CompletionConfig {
32 enable_postfix_completions: true, 33 enable_postfix_completions: true,
34 enable_experimental_completions: true,
33 add_call_parenthesis: true, 35 add_call_parenthesis: true,
34 add_call_argument_snippets: true, 36 add_call_argument_snippets: true,
35 snippet_cap: Some(SnippetCap { _private: () }), 37 snippet_cap: Some(SnippetCap { _private: () }),
diff --git a/crates/completion/src/lib.rs b/crates/completion/src/lib.rs
index cb6e0554e..aecc1378b 100644
--- a/crates/completion/src/lib.rs
+++ b/crates/completion/src/lib.rs
@@ -67,6 +67,13 @@ pub use crate::{
67// fn test_name() {} 67// fn test_name() {}
68// } 68// }
69// ``` 69// ```
70//
71// And experimental completions, enabled with the `rust-analyzer.completion.enableExperimental` setting.
72// This flag enables or disables:
73//
74// - Auto import: additional completion options with automatic `use` import and options from all project importable items, matched for the input
75//
76// Experimental completions might cause issues with performance and completion list look.
70 77
71/// Main entry point for completion. We run completion as a two-phase process. 78/// Main entry point for completion. We run completion as a two-phase process.
72/// 79///
diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs
index e892d4de8..bce02f577 100644
--- a/crates/completion/src/render.rs
+++ b/crates/completion/src/render.rs
@@ -150,6 +150,7 @@ impl<'a> Render<'a> {
150 import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>, 150 import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>,
151 resolution: &ScopeDef, 151 resolution: &ScopeDef,
152 ) -> Option<CompletionItem> { 152 ) -> Option<CompletionItem> {
153 let _p = profile::span("render_resolution");
153 use hir::ModuleDef::*; 154 use hir::ModuleDef::*;
154 155
155 let completion_kind = match resolution { 156 let completion_kind = match resolution {