diff options
Diffstat (limited to 'crates/completion')
-rw-r--r-- | crates/completion/src/config.rs | 17 | ||||
-rw-r--r-- | crates/completion/src/render.rs | 10 | ||||
-rw-r--r-- | crates/completion/src/render/enum_variant.rs | 5 | ||||
-rw-r--r-- | crates/completion/src/render/function.rs | 5 | ||||
-rw-r--r-- | crates/completion/src/render/macro_.rs | 5 |
5 files changed, 15 insertions, 27 deletions
diff --git a/crates/completion/src/config.rs b/crates/completion/src/config.rs index f2fa5c27b..eacdd3449 100644 --- a/crates/completion/src/config.rs +++ b/crates/completion/src/config.rs | |||
@@ -15,12 +15,12 @@ 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 | /// A set of capabilities, enabled on the client and supported on the server. |
19 | pub resolve_capabilities: FxHashSet<CompletionResolveCapability>, | 19 | pub active_resolve_capabilities: FxHashSet<CompletionResolveCapability>, |
20 | } | 20 | } |
21 | 21 | ||
22 | /// A resolve capability, supported on a server. | 22 | /// A resolve capability, supported on the server. |
23 | /// If the client registers any of those in its completion resolve capabilities, | 23 | /// If the client registers any completion resolve capabilities, |
24 | /// the server is able to render completion items' corresponding fields later, | 24 | /// the server is able to render completion items' corresponding fields later, |
25 | /// not during an initial completion item request. | 25 | /// not during an initial completion item request. |
26 | /// See https://github.com/rust-analyzer/rust-analyzer/issues/6366 for more details. | 26 | /// See https://github.com/rust-analyzer/rust-analyzer/issues/6366 for more details. |
@@ -37,8 +37,11 @@ impl CompletionConfig { | |||
37 | } | 37 | } |
38 | 38 | ||
39 | /// Whether the completions' additional edits are calculated later, during a resolve request or not. | 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 { | 40 | /// See `CompletionResolveCapability` for the details. |
41 | !self.resolve_capabilities.contains(&CompletionResolveCapability::AdditionalTextEdits) | 41 | pub fn resolve_edits_immediately(&self) -> bool { |
42 | !self | ||
43 | .active_resolve_capabilities | ||
44 | .contains(&CompletionResolveCapability::AdditionalTextEdits) | ||
42 | } | 45 | } |
43 | } | 46 | } |
44 | 47 | ||
@@ -56,7 +59,7 @@ impl Default for CompletionConfig { | |||
56 | add_call_argument_snippets: true, | 59 | add_call_argument_snippets: true, |
57 | snippet_cap: Some(SnippetCap { _private: () }), | 60 | snippet_cap: Some(SnippetCap { _private: () }), |
58 | merge: Some(MergeBehaviour::Full), | 61 | merge: Some(MergeBehaviour::Full), |
59 | resolve_capabilities: FxHashSet::default(), | 62 | active_resolve_capabilities: FxHashSet::default(), |
60 | } | 63 | } |
61 | } | 64 | } |
62 | } | 65 | } |
diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs index 3a793000b..2b4f1ea14 100644 --- a/crates/completion/src/render.rs +++ b/crates/completion/src/render.rs | |||
@@ -194,10 +194,7 @@ impl<'a> Render<'a> { | |||
194 | local_name, | 194 | local_name, |
195 | ) | 195 | ) |
196 | .kind(CompletionItemKind::UnresolvedReference) | 196 | .kind(CompletionItemKind::UnresolvedReference) |
197 | .add_import( | 197 | .add_import(import_to_add, self.ctx.completion.config.resolve_edits_immediately()) |
198 | import_to_add, | ||
199 | self.ctx.completion.config.should_resolve_additional_edits_immediately(), | ||
200 | ) | ||
201 | .build(); | 198 | .build(); |
202 | return Some(item); | 199 | return Some(item); |
203 | } | 200 | } |
@@ -252,10 +249,7 @@ impl<'a> Render<'a> { | |||
252 | 249 | ||
253 | let item = item | 250 | let item = item |
254 | .kind(kind) | 251 | .kind(kind) |
255 | .add_import( | 252 | .add_import(import_to_add, self.ctx.completion.config.resolve_edits_immediately()) |
256 | import_to_add, | ||
257 | self.ctx.completion.config.should_resolve_additional_edits_immediately(), | ||
258 | ) | ||
259 | .set_documentation(docs) | 253 | .set_documentation(docs) |
260 | .set_ref_match(ref_match) | 254 | .set_ref_match(ref_match) |
261 | .build(); | 255 | .build(); |
diff --git a/crates/completion/src/render/enum_variant.rs b/crates/completion/src/render/enum_variant.rs index 6548b4676..4a91fe3c7 100644 --- a/crates/completion/src/render/enum_variant.rs +++ b/crates/completion/src/render/enum_variant.rs | |||
@@ -71,10 +71,7 @@ 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( | 74 | .add_import(import_to_add, self.ctx.completion.config.resolve_edits_immediately()) |
75 | import_to_add, | ||
76 | self.ctx.completion.config.should_resolve_additional_edits_immediately(), | ||
77 | ) | ||
78 | .detail(self.detail()); | 75 | .detail(self.detail()); |
79 | 76 | ||
80 | if self.variant_kind == StructKind::Tuple { | 77 | if self.variant_kind == StructKind::Tuple { |
diff --git a/crates/completion/src/render/function.rs b/crates/completion/src/render/function.rs index b13e0dafc..20f2b9b7e 100644 --- a/crates/completion/src/render/function.rs +++ b/crates/completion/src/render/function.rs | |||
@@ -47,10 +47,7 @@ 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( | 50 | .add_import(import_to_add, self.ctx.completion.config.resolve_edits_immediately()) |
51 | import_to_add, | ||
52 | self.ctx.completion.config.should_resolve_additional_edits_immediately(), | ||
53 | ) | ||
54 | .build() | 51 | .build() |
55 | } | 52 | } |
56 | 53 | ||
diff --git a/crates/completion/src/render/macro_.rs b/crates/completion/src/render/macro_.rs index 7a8eeb7b9..be7c53659 100644 --- a/crates/completion/src/render/macro_.rs +++ b/crates/completion/src/render/macro_.rs | |||
@@ -50,10 +50,7 @@ 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( | 53 | .add_import(import_to_add, self.ctx.completion.config.resolve_edits_immediately()) |
54 | import_to_add, | ||
55 | self.ctx.completion.config.should_resolve_additional_edits_immediately(), | ||
56 | ) | ||
57 | .detail(self.detail()); | 54 | .detail(self.detail()); |
58 | 55 | ||
59 | let needs_bang = self.needs_bang(); | 56 | let needs_bang = self.needs_bang(); |