aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-12-01 20:46:06 +0000
committerKirill Bulatov <[email protected]>2020-12-07 21:41:08 +0000
commit47464e556c160ce705c2e3c84f501ad4e8dbb123 (patch)
treeb007b475fccd932c9697fb07f70885ecf693c374 /crates
parent9a4daffe16f81e154b542a195fdf81463e5212bb (diff)
Properly fill client completion resolve capabilities data
Diffstat (limited to 'crates')
-rw-r--r--crates/completion/src/config.rs10
-rw-r--r--crates/completion/src/lib.rs2
-rw-r--r--crates/ide/src/lib.rs4
-rw-r--r--crates/rust-analyzer/src/caps.rs41
-rw-r--r--crates/rust-analyzer/src/config.rs4
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
7use ide_db::helpers::insert_use::MergeBehaviour; 7use ide_db::helpers::insert_use::MergeBehaviour;
8use rustc_hash::FxHashSet;
8 9
9#[derive(Clone, Debug, PartialEq, Eq)] 10#[derive(Clone, Debug, PartialEq, Eq)]
10pub struct CompletionConfig { 11pub 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)]
22pub enum CompletionResolveCapability {
23 Documentation,
24 Detail,
25 AdditionalTextEdits,
17} 26}
18 27
19impl CompletionConfig { 28impl 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;
17use crate::{completions::Completions, context::CompletionContext, item::CompletionKind}; 17use crate::{completions::Completions, context::CompletionContext, item::CompletionKind};
18 18
19pub use crate::{ 19pub 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};
82pub use completion::{ 82pub use completion::{
83 CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, ImportToAdd, 83 CompletionConfig, CompletionItem, CompletionItemKind, CompletionResolveCapability,
84 InsertTextFormat, 84 CompletionScore, ImportToAdd, InsertTextFormat,
85}; 85};
86pub use ide_db::{ 86pub 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.
2use std::env; 2use std::env;
3 3
4use ide::CompletionResolveCapability;
4use lsp_types::{ 5use 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};
15use rustc_hash::FxHashSet;
14use serde_json::json; 16use serde_json::json;
15 17
16use crate::semantic_tokens; 18use 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
100fn 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.
109pub 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
96fn code_action_capabilities(client_caps: &ClientCapabilities) -> CodeActionProviderCapability { 135fn 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;
19use serde::Deserialize; 19use serde::Deserialize;
20use vfs::AbsPathBuf; 20use vfs::AbsPathBuf;
21 21
22use crate::diagnostics::DiagnosticsMapConfig; 22use crate::{caps::enabled_resolve_capabilities, diagnostics::DiagnosticsMapConfig};
23 23
24#[derive(Debug, Clone)] 24#[derive(Debug, Clone)]
25pub struct Config { 25pub 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 {