aboutsummaryrefslogtreecommitdiff
path: root/crates/completion/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/completion/src')
-rw-r--r--crates/completion/src/config.rs9
-rw-r--r--crates/completion/src/item.rs3
-rw-r--r--crates/completion/src/render.rs10
-rw-r--r--crates/completion/src/render/enum_variant.rs5
-rw-r--r--crates/completion/src/render/function.rs5
-rw-r--r--crates/completion/src/render/macro_.rs5
-rw-r--r--crates/completion/src/test_utils.rs1
7 files changed, 29 insertions, 9 deletions
diff --git a/crates/completion/src/config.rs b/crates/completion/src/config.rs
index e9a02aeb8..f2fa5c27b 100644
--- a/crates/completion/src/config.rs
+++ b/crates/completion/src/config.rs
@@ -15,9 +15,15 @@ pub struct CompletionConfig {
15 pub add_call_argument_snippets: bool, 15 pub add_call_argument_snippets: bool,
16 pub snippet_cap: Option<SnippetCap>, 16 pub snippet_cap: Option<SnippetCap>,
17 pub merge: Option<MergeBehaviour>, 17 pub merge: Option<MergeBehaviour>,
18 /// A set of capabilities, enabled on the cliend and supported on the server.
18 pub resolve_capabilities: FxHashSet<CompletionResolveCapability>, 19 pub resolve_capabilities: FxHashSet<CompletionResolveCapability>,
19} 20}
20 21
22/// A resolve capability, supported on a server.
23/// If the client registers any of those in its completion resolve capabilities,
24/// the server is able to render completion items' corresponding fields later,
25/// not during an initial completion item request.
26/// See https://github.com/rust-analyzer/rust-analyzer/issues/6366 for more details.
21#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)] 27#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
22pub enum CompletionResolveCapability { 28pub enum CompletionResolveCapability {
23 Documentation, 29 Documentation,
@@ -30,7 +36,8 @@ impl CompletionConfig {
30 self.snippet_cap = if yes { Some(SnippetCap { _private: () }) } else { None } 36 self.snippet_cap = if yes { Some(SnippetCap { _private: () }) } else { None }
31 } 37 }
32 38
33 pub fn should_resolve_immediately(&self) -> bool { 39 /// Whether the completions' additional edits are calculated later, during a resolve request or not.
40 pub fn should_resolve_additional_edits_immediately(&self) -> bool {
34 !self.resolve_capabilities.contains(&CompletionResolveCapability::AdditionalTextEdits) 41 !self.resolve_capabilities.contains(&CompletionResolveCapability::AdditionalTextEdits)
35 } 42 }
36} 43}
diff --git a/crates/completion/src/item.rs b/crates/completion/src/item.rs
index 5906637a6..775245b3b 100644
--- a/crates/completion/src/item.rs
+++ b/crates/completion/src/item.rs
@@ -67,8 +67,7 @@ pub struct CompletionItem {
67 /// possible match. 67 /// possible match.
68 ref_match: Option<(Mutability, CompletionScore)>, 68 ref_match: Option<(Mutability, CompletionScore)>,
69 69
70 /// The data later to be used in the `completionItem/resolve` response 70 /// The import data to add to completion's edits.
71 /// to add the insert import edit.
72 import_to_add: Option<ImportToAdd>, 71 import_to_add: Option<ImportToAdd>,
73} 72}
74 73
diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs
index b7a3a3935..3a793000b 100644
--- a/crates/completion/src/render.rs
+++ b/crates/completion/src/render.rs
@@ -194,7 +194,10 @@ impl<'a> Render<'a> {
194 local_name, 194 local_name,
195 ) 195 )
196 .kind(CompletionItemKind::UnresolvedReference) 196 .kind(CompletionItemKind::UnresolvedReference)
197 .add_import(import_to_add, self.ctx.completion.config.should_resolve_immediately()) 197 .add_import(
198 import_to_add,
199 self.ctx.completion.config.should_resolve_additional_edits_immediately(),
200 )
198 .build(); 201 .build();
199 return Some(item); 202 return Some(item);
200 } 203 }
@@ -249,7 +252,10 @@ impl<'a> Render<'a> {
249 252
250 let item = item 253 let item = item
251 .kind(kind) 254 .kind(kind)
252 .add_import(import_to_add, self.ctx.completion.config.should_resolve_immediately()) 255 .add_import(
256 import_to_add,
257 self.ctx.completion.config.should_resolve_additional_edits_immediately(),
258 )
253 .set_documentation(docs) 259 .set_documentation(docs)
254 .set_ref_match(ref_match) 260 .set_ref_match(ref_match)
255 .build(); 261 .build();
diff --git a/crates/completion/src/render/enum_variant.rs b/crates/completion/src/render/enum_variant.rs
index c08824c6a..6548b4676 100644
--- a/crates/completion/src/render/enum_variant.rs
+++ b/crates/completion/src/render/enum_variant.rs
@@ -71,7 +71,10 @@ impl<'a> EnumVariantRender<'a> {
71 .kind(CompletionItemKind::EnumVariant) 71 .kind(CompletionItemKind::EnumVariant)
72 .set_documentation(self.variant.docs(self.ctx.db())) 72 .set_documentation(self.variant.docs(self.ctx.db()))
73 .set_deprecated(self.ctx.is_deprecated(self.variant)) 73 .set_deprecated(self.ctx.is_deprecated(self.variant))
74 .add_import(import_to_add, self.ctx.completion.config.should_resolve_immediately()) 74 .add_import(
75 import_to_add,
76 self.ctx.completion.config.should_resolve_additional_edits_immediately(),
77 )
75 .detail(self.detail()); 78 .detail(self.detail());
76 79
77 if self.variant_kind == StructKind::Tuple { 80 if self.variant_kind == StructKind::Tuple {
diff --git a/crates/completion/src/render/function.rs b/crates/completion/src/render/function.rs
index 3492384c6..b13e0dafc 100644
--- a/crates/completion/src/render/function.rs
+++ b/crates/completion/src/render/function.rs
@@ -47,7 +47,10 @@ impl<'a> FunctionRender<'a> {
47 .set_deprecated(self.ctx.is_deprecated(self.func)) 47 .set_deprecated(self.ctx.is_deprecated(self.func))
48 .detail(self.detail()) 48 .detail(self.detail())
49 .add_call_parens(self.ctx.completion, self.name, params) 49 .add_call_parens(self.ctx.completion, self.name, params)
50 .add_import(import_to_add, self.ctx.completion.config.should_resolve_immediately()) 50 .add_import(
51 import_to_add,
52 self.ctx.completion.config.should_resolve_additional_edits_immediately(),
53 )
51 .build() 54 .build()
52 } 55 }
53 56
diff --git a/crates/completion/src/render/macro_.rs b/crates/completion/src/render/macro_.rs
index 15648b5b7..7a8eeb7b9 100644
--- a/crates/completion/src/render/macro_.rs
+++ b/crates/completion/src/render/macro_.rs
@@ -50,7 +50,10 @@ impl<'a> MacroRender<'a> {
50 .kind(CompletionItemKind::Macro) 50 .kind(CompletionItemKind::Macro)
51 .set_documentation(self.docs.clone()) 51 .set_documentation(self.docs.clone())
52 .set_deprecated(self.ctx.is_deprecated(self.macro_)) 52 .set_deprecated(self.ctx.is_deprecated(self.macro_))
53 .add_import(import_to_add, self.ctx.completion.config.should_resolve_immediately()) 53 .add_import(
54 import_to_add,
55 self.ctx.completion.config.should_resolve_additional_edits_immediately(),
56 )
54 .detail(self.detail()); 57 .detail(self.detail());
55 58
56 let needs_bang = self.needs_bang(); 59 let needs_bang = self.needs_bang();
diff --git a/crates/completion/src/test_utils.rs b/crates/completion/src/test_utils.rs
index 88351ee15..4c1b1a839 100644
--- a/crates/completion/src/test_utils.rs
+++ b/crates/completion/src/test_utils.rs
@@ -97,7 +97,6 @@ pub(crate) fn check_edit_with_config(
97 .unwrap_or_else(|| panic!("can't find {:?} completion in {:#?}", what, completions)); 97 .unwrap_or_else(|| panic!("can't find {:?} completion in {:#?}", what, completions));
98 let mut actual = db.file_text(position.file_id).to_string(); 98 let mut actual = db.file_text(position.file_id).to_string();
99 completion.text_edit().apply(&mut actual); 99 completion.text_edit().apply(&mut actual);
100 // git how to apply imports now?
101 assert_eq_text!(&ra_fixture_after, &actual) 100 assert_eq_text!(&ra_fixture_after, &actual)
102} 101}
103 102