diff options
-rw-r--r-- | crates/completion/src/config.rs | 10 | ||||
-rw-r--r-- | crates/completion/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ide/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/rust-analyzer/src/caps.rs | 41 | ||||
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 4 |
5 files changed, 56 insertions, 5 deletions
diff --git a/crates/completion/src/config.rs b/crates/completion/src/config.rs index 654a76f7b..736af455e 100644 --- a/crates/completion/src/config.rs +++ b/crates/completion/src/config.rs | |||
@@ -5,6 +5,7 @@ | |||
5 | //! completions if we are allowed to. | 5 | //! completions if we are allowed to. |
6 | 6 | ||
7 | use ide_db::helpers::insert_use::MergeBehaviour; | 7 | use ide_db::helpers::insert_use::MergeBehaviour; |
8 | use rustc_hash::FxHashSet; | ||
8 | 9 | ||
9 | #[derive(Clone, Debug, PartialEq, Eq)] | 10 | #[derive(Clone, Debug, PartialEq, Eq)] |
10 | pub struct CompletionConfig { | 11 | pub struct CompletionConfig { |
@@ -14,6 +15,14 @@ pub struct CompletionConfig { | |||
14 | pub add_call_argument_snippets: bool, | 15 | pub add_call_argument_snippets: bool, |
15 | pub snippet_cap: Option<SnippetCap>, | 16 | pub snippet_cap: Option<SnippetCap>, |
16 | pub merge: Option<MergeBehaviour>, | 17 | pub merge: Option<MergeBehaviour>, |
18 | pub resolve_capabilities: FxHashSet<CompletionResolveCapability>, | ||
19 | } | ||
20 | |||
21 | #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)] | ||
22 | pub enum CompletionResolveCapability { | ||
23 | Documentation, | ||
24 | Detail, | ||
25 | AdditionalTextEdits, | ||
17 | } | 26 | } |
18 | 27 | ||
19 | impl CompletionConfig { | 28 | impl CompletionConfig { |
@@ -36,6 +45,7 @@ impl Default for CompletionConfig { | |||
36 | add_call_argument_snippets: true, | 45 | add_call_argument_snippets: true, |
37 | snippet_cap: Some(SnippetCap { _private: () }), | 46 | snippet_cap: Some(SnippetCap { _private: () }), |
38 | merge: Some(MergeBehaviour::Full), | 47 | merge: Some(MergeBehaviour::Full), |
48 | resolve_capabilities: FxHashSet::default(), | ||
39 | } | 49 | } |
40 | } | 50 | } |
41 | } | 51 | } |
diff --git a/crates/completion/src/lib.rs b/crates/completion/src/lib.rs index 28209d4e0..c689b0dde 100644 --- a/crates/completion/src/lib.rs +++ b/crates/completion/src/lib.rs | |||
@@ -17,7 +17,7 @@ use ide_db::RootDatabase; | |||
17 | use crate::{completions::Completions, context::CompletionContext, item::CompletionKind}; | 17 | use crate::{completions::Completions, context::CompletionContext, item::CompletionKind}; |
18 | 18 | ||
19 | pub use crate::{ | 19 | pub use crate::{ |
20 | config::CompletionConfig, | 20 | config::{CompletionConfig, CompletionResolveCapability}, |
21 | item::{CompletionItem, CompletionItemKind, CompletionScore, ImportToAdd, InsertTextFormat}, | 21 | item::{CompletionItem, CompletionItemKind, CompletionScore, ImportToAdd, InsertTextFormat}, |
22 | }; | 22 | }; |
23 | 23 | ||
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 7015a5126..d1a27f3a5 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs | |||
@@ -80,8 +80,8 @@ pub use crate::{ | |||
80 | }, | 80 | }, |
81 | }; | 81 | }; |
82 | pub use completion::{ | 82 | pub use completion::{ |
83 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, ImportToAdd, | 83 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionResolveCapability, |
84 | InsertTextFormat, | 84 | CompletionScore, ImportToAdd, InsertTextFormat, |
85 | }; | 85 | }; |
86 | pub use ide_db::{ | 86 | pub use ide_db::{ |
87 | call_info::CallInfo, | 87 | call_info::CallInfo, |
diff --git a/crates/rust-analyzer/src/caps.rs b/crates/rust-analyzer/src/caps.rs index c559e1a3d..d6b862088 100644 --- a/crates/rust-analyzer/src/caps.rs +++ b/crates/rust-analyzer/src/caps.rs | |||
@@ -1,6 +1,7 @@ | |||
1 | //! Advertizes the capabilities of the LSP Server. | 1 | //! Advertizes the capabilities of the LSP Server. |
2 | use std::env; | 2 | use std::env; |
3 | 3 | ||
4 | use ide::CompletionResolveCapability; | ||
4 | use lsp_types::{ | 5 | use lsp_types::{ |
5 | CallHierarchyServerCapability, ClientCapabilities, CodeActionKind, CodeActionOptions, | 6 | CallHierarchyServerCapability, ClientCapabilities, CodeActionKind, CodeActionOptions, |
6 | CodeActionProviderCapability, CodeLensOptions, CompletionOptions, | 7 | CodeActionProviderCapability, CodeLensOptions, CompletionOptions, |
@@ -11,6 +12,7 @@ use lsp_types::{ | |||
11 | TextDocumentSyncKind, TextDocumentSyncOptions, TypeDefinitionProviderCapability, | 12 | TextDocumentSyncKind, TextDocumentSyncOptions, TypeDefinitionProviderCapability, |
12 | WorkDoneProgressOptions, | 13 | WorkDoneProgressOptions, |
13 | }; | 14 | }; |
15 | use rustc_hash::FxHashSet; | ||
14 | use serde_json::json; | 16 | use serde_json::json; |
15 | 17 | ||
16 | use crate::semantic_tokens; | 18 | use crate::semantic_tokens; |
@@ -48,7 +50,9 @@ pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabiliti | |||
48 | document_symbol_provider: Some(OneOf::Left(true)), | 50 | document_symbol_provider: Some(OneOf::Left(true)), |
49 | workspace_symbol_provider: Some(OneOf::Left(true)), | 51 | workspace_symbol_provider: Some(OneOf::Left(true)), |
50 | code_action_provider: Some(code_action_capabilities(client_caps)), | 52 | code_action_provider: Some(code_action_capabilities(client_caps)), |
51 | code_lens_provider: Some(CodeLensOptions { resolve_provider: Some(true) }), | 53 | code_lens_provider: Some(CodeLensOptions { |
54 | resolve_provider: resolve_provider(client_caps), | ||
55 | }), | ||
52 | document_formatting_provider: Some(OneOf::Left(true)), | 56 | document_formatting_provider: Some(OneOf::Left(true)), |
53 | document_range_formatting_provider: None, | 57 | document_range_formatting_provider: None, |
54 | document_on_type_formatting_provider: Some(DocumentOnTypeFormattingOptions { | 58 | document_on_type_formatting_provider: Some(DocumentOnTypeFormattingOptions { |
@@ -93,6 +97,41 @@ pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabiliti | |||
93 | } | 97 | } |
94 | } | 98 | } |
95 | 99 | ||
100 | fn resolve_provider(client_caps: &ClientCapabilities) -> Option<bool> { | ||
101 | if enabled_resolve_capabilities(client_caps)?.is_empty() { | ||
102 | None | ||
103 | } else { | ||
104 | Some(true) | ||
105 | } | ||
106 | } | ||
107 | |||
108 | /// Parses client capabilities and returns all that rust-analyzer supports. | ||
109 | pub fn enabled_resolve_capabilities( | ||
110 | caps: &ClientCapabilities, | ||
111 | ) -> Option<FxHashSet<CompletionResolveCapability>> { | ||
112 | Some( | ||
113 | caps.text_document | ||
114 | .as_ref()? | ||
115 | .completion | ||
116 | .as_ref()? | ||
117 | .completion_item | ||
118 | .as_ref()? | ||
119 | .resolve_support | ||
120 | .as_ref()? | ||
121 | .properties | ||
122 | .iter() | ||
123 | .filter_map(|cap_string| { | ||
124 | Some(match cap_string.as_str() { | ||
125 | "additionalTextEdits" => CompletionResolveCapability::AdditionalTextEdits, | ||
126 | "detail" => CompletionResolveCapability::Detail, | ||
127 | "documentation" => CompletionResolveCapability::Documentation, | ||
128 | _unsupported => return None, | ||
129 | }) | ||
130 | }) | ||
131 | .collect(), | ||
132 | ) | ||
133 | } | ||
134 | |||
96 | fn code_action_capabilities(client_caps: &ClientCapabilities) -> CodeActionProviderCapability { | 135 | fn code_action_capabilities(client_caps: &ClientCapabilities) -> CodeActionProviderCapability { |
97 | client_caps | 136 | client_caps |
98 | .text_document | 137 | .text_document |
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 59269a74b..83f097829 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -19,7 +19,7 @@ use rustc_hash::FxHashSet; | |||
19 | use serde::Deserialize; | 19 | use serde::Deserialize; |
20 | use vfs::AbsPathBuf; | 20 | use vfs::AbsPathBuf; |
21 | 21 | ||
22 | use crate::diagnostics::DiagnosticsMapConfig; | 22 | use crate::{caps::enabled_resolve_capabilities, diagnostics::DiagnosticsMapConfig}; |
23 | 23 | ||
24 | #[derive(Debug, Clone)] | 24 | #[derive(Debug, Clone)] |
25 | pub struct Config { | 25 | pub struct Config { |
@@ -388,6 +388,8 @@ impl Config { | |||
388 | } | 388 | } |
389 | 389 | ||
390 | self.completion.allow_snippets(false); | 390 | self.completion.allow_snippets(false); |
391 | self.completion.resolve_capabilities = | ||
392 | enabled_resolve_capabilities(caps).unwrap_or_default(); | ||
391 | if let Some(completion) = &doc_caps.completion { | 393 | if let Some(completion) = &doc_caps.completion { |
392 | if let Some(completion_item) = &completion.completion_item { | 394 | if let Some(completion_item) = &completion.completion_item { |
393 | if let Some(value) = completion_item.snippet_support { | 395 | if let Some(value) = completion_item.snippet_support { |