aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorkjeremy <[email protected]>2020-05-19 22:22:38 +0100
committerkjeremy <[email protected]>2020-05-19 22:22:38 +0100
commite3ae298e7869e8b403c91426d7c88c98558767ea (patch)
treea4ec857de712ac799226588ec5454d20da088d6e /crates
parent6bf4fc27d923207df36d06da295d815d768f3a0b (diff)
Fill code action capabilities with a function
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/caps.rs56
1 files changed, 27 insertions, 29 deletions
diff --git a/crates/rust-analyzer/src/caps.rs b/crates/rust-analyzer/src/caps.rs
index 5ac98c657..4effc82ca 100644
--- a/crates/rust-analyzer/src/caps.rs
+++ b/crates/rust-analyzer/src/caps.rs
@@ -15,35 +15,7 @@ use lsp_types::{
15}; 15};
16 16
17pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabilities { 17pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabilities {
18 let mut code_action_provider = CodeActionProviderCapability::Simple(true); 18 let code_action_provider = code_action_capabilities(client_caps);
19
20 match client_caps.text_document.as_ref() {
21 Some(it) => {
22 match it.code_action.as_ref().and_then(|c| c.code_action_literal_support.as_ref()) {
23 Some(_literal_support) => {
24 code_action_provider =
25 CodeActionProviderCapability::Options(CodeActionOptions {
26 // Advertise support for all built-in CodeActionKinds.
27 // Ideally we would base this off of the client capabilities
28 // but the client is supposed to fall back gracefully for unknown values.
29 code_action_kinds: Some(vec![
30 lsp_types::code_action_kind::EMPTY.to_string(),
31 lsp_types::code_action_kind::QUICKFIX.to_string(),
32 lsp_types::code_action_kind::REFACTOR.to_string(),
33 lsp_types::code_action_kind::REFACTOR_EXTRACT.to_string(),
34 lsp_types::code_action_kind::REFACTOR_INLINE.to_string(),
35 lsp_types::code_action_kind::REFACTOR_REWRITE.to_string(),
36 lsp_types::code_action_kind::SOURCE.to_string(),
37 lsp_types::code_action_kind::SOURCE_ORGANIZE_IMPORTS.to_string(),
38 ]),
39 work_done_progress_options: Default::default(),
40 });
41 }
42 None => {}
43 }
44 }
45 None => {}
46 };
47 19
48 ServerCapabilities { 20 ServerCapabilities {
49 text_document_sync: Some(TextDocumentSyncCapability::Options(TextDocumentSyncOptions { 21 text_document_sync: Some(TextDocumentSyncCapability::Options(TextDocumentSyncOptions {
@@ -112,3 +84,29 @@ pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabiliti
112 experimental: Default::default(), 84 experimental: Default::default(),
113 } 85 }
114} 86}
87
88fn code_action_capabilities(client_caps: &ClientCapabilities) -> CodeActionProviderCapability {
89 client_caps
90 .text_document
91 .as_ref()
92 .and_then(|it| it.code_action.as_ref())
93 .and_then(|it| it.code_action_literal_support.as_ref())
94 .map_or(CodeActionProviderCapability::Simple(true), |_| {
95 CodeActionProviderCapability::Options(CodeActionOptions {
96 // Advertise support for all built-in CodeActionKinds.
97 // Ideally we would base this off of the client capabilities
98 // but the client is supposed to fall back gracefully for unknown values.
99 code_action_kinds: Some(vec![
100 lsp_types::code_action_kind::EMPTY.to_string(),
101 lsp_types::code_action_kind::QUICKFIX.to_string(),
102 lsp_types::code_action_kind::REFACTOR.to_string(),
103 lsp_types::code_action_kind::REFACTOR_EXTRACT.to_string(),
104 lsp_types::code_action_kind::REFACTOR_INLINE.to_string(),
105 lsp_types::code_action_kind::REFACTOR_REWRITE.to_string(),
106 lsp_types::code_action_kind::SOURCE.to_string(),
107 lsp_types::code_action_kind::SOURCE_ORGANIZE_IMPORTS.to_string(),
108 ]),
109 work_done_progress_options: Default::default(),
110 })
111 })
112}