aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-01 17:46:26 +0100
committerAleksey Kladov <[email protected]>2020-04-01 17:46:26 +0100
commite870cbc23d78f5bc424983b1d9ef945888f9dc49 (patch)
tree6ada4ac34541dc811bb59a8c063138191812e630
parenta97e5eb85d1a8a2a07663abbd9beaae317fdb24d (diff)
Centralize client capabilities
-rw-r--r--crates/rust-analyzer/src/bin/main.rs2
-rw-r--r--crates/rust-analyzer/src/config.rs22
-rw-r--r--crates/rust-analyzer/src/conv.rs2
-rw-r--r--crates/rust-analyzer/src/lib.rs3
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs2
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/support.rs7
6 files changed, 21 insertions, 17 deletions
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs
index 483f50ce6..a3897b728 100644
--- a/crates/rust-analyzer/src/bin/main.rs
+++ b/crates/rust-analyzer/src/bin/main.rs
@@ -5,7 +5,7 @@ mod args;
5 5
6use lsp_server::Connection; 6use lsp_server::Connection;
7 7
8use rust_analyzer::{cli, from_json, Config, Result}; 8use rust_analyzer::{cli, config::Config, from_json, Result};
9 9
10use crate::args::HelpPrinted; 10use crate::args::HelpPrinted;
11 11
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index c07626e5c..e72017dcc 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -15,11 +15,10 @@ use serde::Deserialize;
15 15
16#[derive(Debug, Clone)] 16#[derive(Debug, Clone)]
17pub struct Config { 17pub struct Config {
18 pub client_caps: ClientCapsConfig,
18 pub publish_decorations: bool, 19 pub publish_decorations: bool,
19 pub publish_diagnostics: bool, 20 pub publish_diagnostics: bool,
20 pub notifications: NotificationsConfig, 21 pub notifications: NotificationsConfig,
21 pub supports_location_link: bool,
22 pub line_folding_only: bool,
23 pub inlay_hints: InlayHintsConfig, 22 pub inlay_hints: InlayHintsConfig,
24 pub completion: CompletionConfig, 23 pub completion: CompletionConfig,
25 pub call_info_full: bool, 24 pub call_info_full: bool,
@@ -58,6 +57,12 @@ impl Default for RustfmtConfig {
58 } 57 }
59} 58}
60 59
60#[derive(Debug, Clone, Default)]
61pub struct ClientCapsConfig {
62 pub location_link: bool,
63 pub line_folding_only: bool,
64}
65
61impl Default for Config { 66impl Default for Config {
62 fn default() -> Self { 67 fn default() -> Self {
63 Config { 68 Config {
@@ -67,8 +72,7 @@ impl Default for Config {
67 workspace_loaded: true, 72 workspace_loaded: true,
68 cargo_toml_not_found: true, 73 cargo_toml_not_found: true,
69 }, 74 },
70 supports_location_link: false, 75 client_caps: ClientCapsConfig::default(),
71 line_folding_only: false,
72 inlay_hints: InlayHintsConfig { 76 inlay_hints: InlayHintsConfig {
73 type_hints: true, 77 type_hints: true,
74 parameter_hints: true, 78 parameter_hints: true,
@@ -97,11 +101,9 @@ impl Default for Config {
97impl Config { 101impl Config {
98 #[rustfmt::skip] 102 #[rustfmt::skip]
99 pub fn update(&mut self, value: &serde_json::Value) { 103 pub fn update(&mut self, value: &serde_json::Value) {
100 let line_folding_only = self.line_folding_only; 104 let client_caps = self.client_caps.clone();
101 let supports_location_link = self.supports_location_link;
102 *self = Default::default(); 105 *self = Default::default();
103 self.line_folding_only = line_folding_only; 106 self.client_caps = client_caps;
104 self.supports_location_link = supports_location_link;
105 107
106 set(value, "publishDecorations", &mut self.publish_decorations); 108 set(value, "publishDecorations", &mut self.publish_decorations);
107 set(value, "excludeGlobs", &mut self.exclude_globs); 109 set(value, "excludeGlobs", &mut self.exclude_globs);
@@ -157,10 +159,10 @@ impl Config {
157 159
158 pub fn update_caps(&mut self, caps: &TextDocumentClientCapabilities) { 160 pub fn update_caps(&mut self, caps: &TextDocumentClientCapabilities) {
159 if let Some(value) = caps.definition.as_ref().and_then(|it| it.link_support) { 161 if let Some(value) = caps.definition.as_ref().and_then(|it| it.link_support) {
160 self.supports_location_link = value; 162 self.client_caps.location_link = value;
161 } 163 }
162 if let Some(value) = caps.folding_range.as_ref().and_then(|it| it.line_folding_only) { 164 if let Some(value) = caps.folding_range.as_ref().and_then(|it| it.line_folding_only) {
163 self.line_folding_only = value 165 self.client_caps.line_folding_only = value
164 } 166 }
165 } 167 }
166} 168}
diff --git a/crates/rust-analyzer/src/conv.rs b/crates/rust-analyzer/src/conv.rs
index e8dc953c3..57c4c8ce5 100644
--- a/crates/rust-analyzer/src/conv.rs
+++ b/crates/rust-analyzer/src/conv.rs
@@ -579,7 +579,7 @@ impl TryConvWith<&WorldSnapshot> for (FileId, RangeInfo<Vec<NavigationTarget>>)
579 .into_iter() 579 .into_iter()
580 .map(|nav| (file_id, RangeInfo::new(range, nav))) 580 .map(|nav| (file_id, RangeInfo::new(range, nav)))
581 .try_conv_with_to_vec(world)?; 581 .try_conv_with_to_vec(world)?;
582 if world.config.supports_location_link { 582 if world.config.client_caps.location_link {
583 Ok(links.into()) 583 Ok(links.into())
584 } else { 584 } else {
585 let locations: Vec<Location> = links 585 let locations: Vec<Location> = links
diff --git a/crates/rust-analyzer/src/lib.rs b/crates/rust-analyzer/src/lib.rs
index 6062d0984..02953be30 100644
--- a/crates/rust-analyzer/src/lib.rs
+++ b/crates/rust-analyzer/src/lib.rs
@@ -33,7 +33,7 @@ mod conv;
33mod main_loop; 33mod main_loop;
34mod markdown; 34mod markdown;
35pub mod req; 35pub mod req;
36mod config; 36pub mod config;
37mod world; 37mod world;
38mod diagnostics; 38mod diagnostics;
39mod semantic_tokens; 39mod semantic_tokens;
@@ -42,7 +42,6 @@ use serde::de::DeserializeOwned;
42 42
43pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>; 43pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
44pub use crate::{ 44pub use crate::{
45 config::Config,
46 caps::server_capabilities, 45 caps::server_capabilities,
47 main_loop::LspError, 46 main_loop::LspError,
48 main_loop::{main_loop, show_message}, 47 main_loop::{main_loop, show_message},
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index d0f64f007..23e48c089 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -450,7 +450,7 @@ pub fn handle_folding_range(
450 let ctx = FoldConvCtx { 450 let ctx = FoldConvCtx {
451 text: &text, 451 text: &text,
452 line_index: &line_index, 452 line_index: &line_index,
453 line_folding_only: world.config.line_folding_only, 453 line_folding_only: world.config.client_caps.line_folding_only,
454 }; 454 };
455 let res = Some(folds.into_iter().map_conv_with(&ctx).collect()); 455 let res = Some(folds.into_iter().map_conv_with(&ctx).collect());
456 Ok(res) 456 Ok(res)
diff --git a/crates/rust-analyzer/tests/heavy_tests/support.rs b/crates/rust-analyzer/tests/heavy_tests/support.rs
index c83cb8adb..7eebedff7 100644
--- a/crates/rust-analyzer/tests/heavy_tests/support.rs
+++ b/crates/rust-analyzer/tests/heavy_tests/support.rs
@@ -19,7 +19,10 @@ use tempfile::TempDir;
19use test_utils::{find_mismatch, parse_fixture}; 19use test_utils::{find_mismatch, parse_fixture};
20 20
21use req::{ProgressParams, ProgressParamsValue}; 21use req::{ProgressParams, ProgressParamsValue};
22use rust_analyzer::{main_loop, req, Config}; 22use rust_analyzer::{
23 config::{ClientCapsConfig, Config},
24 main_loop, req,
25};
23 26
24pub struct Project<'a> { 27pub struct Project<'a> {
25 fixture: &'a str, 28 fixture: &'a str,
@@ -78,7 +81,7 @@ impl<'a> Project<'a> {
78 let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect(); 81 let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect();
79 82
80 let mut config = Config { 83 let mut config = Config {
81 supports_location_link: true, 84 client_caps: ClientCapsConfig { location_link: true, ..Default::default() },
82 with_sysroot: self.with_sysroot, 85 with_sysroot: self.with_sysroot,
83 ..Config::default() 86 ..Config::default()
84 }; 87 };