diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-06 17:29:18 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-06 17:29:18 +0000 |
commit | 7ae4b8bdb62735ee767dff25ce1485ae8bffe199 (patch) | |
tree | 3bc2f50593d77c86ccaad22c8748719495721432 /crates/completion | |
parent | ae2ea108e08bdd53362335e5a4e61a83feb296a0 (diff) | |
parent | 6e87828756d970e9c25635aa9f71f0a90cc8ff65 (diff) |
Merge #7183
7183: YAGNI active_resolve_capabilities r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/completion')
-rw-r--r-- | crates/completion/src/completions/unqualified_path.rs | 8 | ||||
-rw-r--r-- | crates/completion/src/config.rs | 22 | ||||
-rw-r--r-- | crates/completion/src/lib.rs | 2 |
3 files changed, 3 insertions, 29 deletions
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index 2f41a3f96..896f167ff 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs | |||
@@ -46,7 +46,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC | |||
46 | acc.add_resolution(ctx, name.to_string(), &res) | 46 | acc.add_resolution(ctx, name.to_string(), &res) |
47 | }); | 47 | }); |
48 | 48 | ||
49 | if ctx.config.enable_autoimport_completions && ctx.config.resolve_additional_edits_lazily() { | 49 | if ctx.config.enable_autoimport_completions { |
50 | fuzzy_completion(acc, ctx); | 50 | fuzzy_completion(acc, ctx); |
51 | } | 51 | } |
52 | } | 52 | } |
@@ -206,11 +206,7 @@ mod tests { | |||
206 | } | 206 | } |
207 | 207 | ||
208 | fn fuzzy_completion_config() -> CompletionConfig { | 208 | fn fuzzy_completion_config() -> CompletionConfig { |
209 | let mut completion_config = CompletionConfig::default(); | 209 | CompletionConfig::default() |
210 | completion_config | ||
211 | .active_resolve_capabilities | ||
212 | .insert(crate::CompletionResolveCapability::AdditionalTextEdits); | ||
213 | completion_config | ||
214 | } | 210 | } |
215 | 211 | ||
216 | #[test] | 212 | #[test] |
diff --git a/crates/completion/src/config.rs b/crates/completion/src/config.rs index 30577dc11..9f82b0346 100644 --- a/crates/completion/src/config.rs +++ b/crates/completion/src/config.rs | |||
@@ -5,7 +5,6 @@ | |||
5 | //! completions if we are allowed to. | 5 | //! completions if we are allowed to. |
6 | 6 | ||
7 | use ide_db::helpers::insert_use::MergeBehavior; | 7 | use ide_db::helpers::insert_use::MergeBehavior; |
8 | use rustc_hash::FxHashSet; | ||
9 | 8 | ||
10 | #[derive(Clone, Debug, PartialEq, Eq)] | 9 | #[derive(Clone, Debug, PartialEq, Eq)] |
11 | pub struct CompletionConfig { | 10 | pub struct CompletionConfig { |
@@ -15,32 +14,12 @@ pub struct CompletionConfig { | |||
15 | pub add_call_argument_snippets: bool, | 14 | pub add_call_argument_snippets: bool, |
16 | pub snippet_cap: Option<SnippetCap>, | 15 | pub snippet_cap: Option<SnippetCap>, |
17 | pub merge: Option<MergeBehavior>, | 16 | pub merge: Option<MergeBehavior>, |
18 | /// A set of capabilities, enabled on the client and supported on the server. | ||
19 | pub active_resolve_capabilities: FxHashSet<CompletionResolveCapability>, | ||
20 | } | ||
21 | |||
22 | /// A resolve capability, supported on the server. | ||
23 | /// If the client registers any 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. | ||
27 | #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)] | ||
28 | pub enum CompletionResolveCapability { | ||
29 | Documentation, | ||
30 | Detail, | ||
31 | AdditionalTextEdits, | ||
32 | } | 17 | } |
33 | 18 | ||
34 | impl CompletionConfig { | 19 | impl CompletionConfig { |
35 | pub fn allow_snippets(&mut self, yes: bool) { | 20 | pub fn allow_snippets(&mut self, yes: bool) { |
36 | self.snippet_cap = if yes { Some(SnippetCap { _private: () }) } else { None } | 21 | self.snippet_cap = if yes { Some(SnippetCap { _private: () }) } else { None } |
37 | } | 22 | } |
38 | |||
39 | /// Whether the completions' additional edits are calculated when sending an initional completions list | ||
40 | /// or later, in a separate resolve request. | ||
41 | pub fn resolve_additional_edits_lazily(&self) -> bool { | ||
42 | self.active_resolve_capabilities.contains(&CompletionResolveCapability::AdditionalTextEdits) | ||
43 | } | ||
44 | } | 23 | } |
45 | 24 | ||
46 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] | 25 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
@@ -57,7 +36,6 @@ impl Default for CompletionConfig { | |||
57 | add_call_argument_snippets: true, | 36 | add_call_argument_snippets: true, |
58 | snippet_cap: Some(SnippetCap { _private: () }), | 37 | snippet_cap: Some(SnippetCap { _private: () }), |
59 | merge: Some(MergeBehavior::Full), | 38 | merge: Some(MergeBehavior::Full), |
60 | active_resolve_capabilities: FxHashSet::default(), | ||
61 | } | 39 | } |
62 | } | 40 | } |
63 | } | 41 | } |
diff --git a/crates/completion/src/lib.rs b/crates/completion/src/lib.rs index c57d05bbe..366aced71 100644 --- a/crates/completion/src/lib.rs +++ b/crates/completion/src/lib.rs | |||
@@ -20,7 +20,7 @@ use text_edit::TextEdit; | |||
20 | use crate::{completions::Completions, context::CompletionContext, item::CompletionKind}; | 20 | use crate::{completions::Completions, context::CompletionContext, item::CompletionKind}; |
21 | 21 | ||
22 | pub use crate::{ | 22 | pub use crate::{ |
23 | config::{CompletionConfig, CompletionResolveCapability}, | 23 | config::CompletionConfig, |
24 | item::{CompletionItem, CompletionItemKind, CompletionScore, ImportEdit, InsertTextFormat}, | 24 | item::{CompletionItem, CompletionItemKind, CompletionScore, ImportEdit, InsertTextFormat}, |
25 | }; | 25 | }; |
26 | 26 | ||