aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/config.rs37
-rw-r--r--crates/rust-analyzer/src/main_loop.rs33
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs16
-rw-r--r--crates/rust-analyzer/src/world.rs14
4 files changed, 48 insertions, 52 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index fb7895ce0..94627d35d 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -9,18 +9,23 @@
9 9
10use rustc_hash::FxHashMap; 10use rustc_hash::FxHashMap;
11 11
12use crate::feature_flags::FeatureFlags;
12use lsp_types::TextDocumentClientCapabilities; 13use lsp_types::TextDocumentClientCapabilities;
13use ra_flycheck::FlycheckConfig; 14use ra_flycheck::FlycheckConfig;
14use ra_ide::InlayHintsConfig; 15use ra_ide::{CompletionConfig, InlayHintsConfig};
15use ra_project_model::CargoFeatures; 16use ra_project_model::CargoFeatures;
16use serde::{Deserialize, Deserializer}; 17use serde::{Deserialize, Deserializer};
17 18
18#[derive(Debug, Clone)] 19#[derive(Debug, Clone)]
19pub struct Config { 20pub struct Config {
20 pub publish_decorations: bool, 21 pub publish_decorations: bool,
22 pub publish_diagnostics: bool,
23 pub notifications: NotificationsConfig,
21 pub supports_location_link: bool, 24 pub supports_location_link: bool,
22 pub line_folding_only: bool, 25 pub line_folding_only: bool,
23 pub inlay_hints: InlayHintsConfig, 26 pub inlay_hints: InlayHintsConfig,
27 pub completion: CompletionConfig,
28 pub call_info_full: bool,
24 pub rustfmt: RustfmtConfig, 29 pub rustfmt: RustfmtConfig,
25 pub check: Option<FlycheckConfig>, 30 pub check: Option<FlycheckConfig>,
26 pub vscode_lldb: bool, 31 pub vscode_lldb: bool,
@@ -28,6 +33,12 @@ pub struct Config {
28} 33}
29 34
30#[derive(Debug, Clone)] 35#[derive(Debug, Clone)]
36pub struct NotificationsConfig {
37 pub workspace_loaded: bool,
38 pub cargo_toml_not_found: bool,
39}
40
41#[derive(Debug, Clone)]
31pub enum RustfmtConfig { 42pub enum RustfmtConfig {
32 Rustfmt { 43 Rustfmt {
33 extra_args: Vec<String>, 44 extra_args: Vec<String>,
@@ -49,8 +60,14 @@ pub(crate) fn get_config(
49 config: &ServerConfig, 60 config: &ServerConfig,
50 text_document_caps: Option<&TextDocumentClientCapabilities>, 61 text_document_caps: Option<&TextDocumentClientCapabilities>,
51) -> Config { 62) -> Config {
63 let feature_flags = get_feature_flags(config);
52 Config { 64 Config {
53 publish_decorations: config.publish_decorations, 65 publish_decorations: config.publish_decorations,
66 publish_diagnostics: feature_flags.get("lsp.diagnostics"),
67 notifications: NotificationsConfig {
68 workspace_loaded: feature_flags.get("notifications.workspace-loaded"),
69 cargo_toml_not_found: feature_flags.get("notifications.cargo-toml-not-found"),
70 },
54 supports_location_link: text_document_caps 71 supports_location_link: text_document_caps
55 .and_then(|it| it.definition) 72 .and_then(|it| it.definition)
56 .and_then(|it| it.link_support) 73 .and_then(|it| it.link_support)
@@ -65,6 +82,13 @@ pub(crate) fn get_config(
65 chaining_hints: config.inlay_hints_chaining, 82 chaining_hints: config.inlay_hints_chaining,
66 max_length: config.inlay_hints_max_length, 83 max_length: config.inlay_hints_max_length,
67 }, 84 },
85 completion: CompletionConfig {
86 enable_postfix_completions: feature_flags.get("completion.enable-postfix"),
87 add_call_parenthesis: feature_flags.get("completion.insertion.add-call-parenthesis"),
88 add_call_argument_snippets: feature_flags
89 .get("completion.insertion.add-argument-snippets"),
90 },
91 call_info_full: feature_flags.get("call-info.full"),
68 check: if config.cargo_watch_enable { 92 check: if config.cargo_watch_enable {
69 Some(FlycheckConfig::CargoCommand { 93 Some(FlycheckConfig::CargoCommand {
70 command: config.cargo_watch_command.clone(), 94 command: config.cargo_watch_command.clone(),
@@ -80,6 +104,17 @@ pub(crate) fn get_config(
80 } 104 }
81} 105}
82 106
107fn get_feature_flags(config: &ServerConfig) -> FeatureFlags {
108 let mut ff = FeatureFlags::default();
109 for (flag, &value) in &config.feature_flags {
110 if ff.set(flag.as_str(), value).is_err() {
111 log::error!("unknown feature flag: {:?}", flag);
112 }
113 }
114 log::info!("feature_flags: {:#?}", ff);
115 ff
116}
117
83/// Client provided initialization options 118/// Client provided initialization options
84#[derive(Deserialize, Clone, Debug, PartialEq, Eq)] 119#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
85#[serde(rename_all = "camelCase", default)] 120#[serde(rename_all = "camelCase", default)]
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index de40e2ac2..8f89fb7ea 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -33,7 +33,6 @@ use threadpool::ThreadPool;
33use crate::{ 33use crate::{
34 config::get_config, 34 config::get_config,
35 diagnostics::DiagnosticTask, 35 diagnostics::DiagnosticTask,
36 feature_flags::FeatureFlags,
37 main_loop::{ 36 main_loop::{
38 pending_requests::{PendingRequest, PendingRequests}, 37 pending_requests::{PendingRequest, PendingRequests},
39 subscriptions::Subscriptions, 38 subscriptions::Subscriptions,
@@ -66,22 +65,6 @@ impl fmt::Display for LspError {
66 65
67impl Error for LspError {} 66impl Error for LspError {}
68 67
69fn get_feature_flags(config: &ServerConfig, connection: &Connection) -> FeatureFlags {
70 let mut ff = FeatureFlags::default();
71 for (flag, &value) in &config.feature_flags {
72 if ff.set(flag.as_str(), value).is_err() {
73 log::error!("unknown feature flag: {:?}", flag);
74 show_message(
75 req::MessageType::Error,
76 format!("unknown feature flag: {:?}", flag),
77 &connection.sender,
78 );
79 }
80 }
81 log::info!("feature_flags: {:#?}", ff);
82 ff
83}
84
85pub fn main_loop( 68pub fn main_loop(
86 ws_roots: Vec<PathBuf>, 69 ws_roots: Vec<PathBuf>,
87 client_caps: ClientCapabilities, 70 client_caps: ClientCapabilities,
@@ -112,8 +95,8 @@ pub fn main_loop(
112 let text_document_caps = client_caps.text_document.as_ref(); 95 let text_document_caps = client_caps.text_document.as_ref();
113 let mut loop_state = LoopState::default(); 96 let mut loop_state = LoopState::default();
114 let mut world_state = { 97 let mut world_state = {
115 let feature_flags = get_feature_flags(&config, &connection); 98 // TODO: refactor
116 99 let new_config = get_config(&config, text_document_caps);
117 // FIXME: support dynamic workspace loading. 100 // FIXME: support dynamic workspace loading.
118 let workspaces = { 101 let workspaces = {
119 let mut loaded_workspaces = Vec::new(); 102 let mut loaded_workspaces = Vec::new();
@@ -131,7 +114,7 @@ pub fn main_loop(
131 if let Some(ra_project_model::CargoTomlNotFoundError { .. }) = 114 if let Some(ra_project_model::CargoTomlNotFoundError { .. }) =
132 e.downcast_ref() 115 e.downcast_ref()
133 { 116 {
134 if !feature_flags.get("notifications.cargo-toml-not-found") { 117 if !new_config.notifications.cargo_toml_not_found {
135 continue; 118 continue;
136 } 119 }
137 } 120 }
@@ -180,8 +163,7 @@ pub fn main_loop(
180 config.lru_capacity, 163 config.lru_capacity,
181 &globs, 164 &globs,
182 Watch(!config.use_client_watching), 165 Watch(!config.use_client_watching),
183 get_config(&config, text_document_caps), 166 new_config,
184 feature_flags,
185 ) 167 )
186 }; 168 };
187 169
@@ -406,7 +388,6 @@ fn loop_turn(
406 world_state.update_configuration( 388 world_state.update_configuration(
407 new_config.lru_capacity, 389 new_config.lru_capacity,
408 get_config(&new_config, text_document_caps), 390 get_config(&new_config, text_document_caps),
409 get_feature_flags(&new_config, connection),
410 ); 391 );
411 } 392 }
412 (None, Some(Err(e))) => { 393 (None, Some(Err(e))) => {
@@ -441,8 +422,8 @@ fn loop_turn(
441 }); 422 });
442 } 423 }
443 424
444 let show_progress = !loop_state.workspace_loaded 425 let show_progress =
445 && world_state.feature_flags.get("notifications.workspace-loaded"); 426 !loop_state.workspace_loaded && world_state.config.notifications.workspace_loaded;
446 427
447 if !loop_state.workspace_loaded 428 if !loop_state.workspace_loaded
448 && loop_state.roots_scanned == loop_state.roots_total 429 && loop_state.roots_scanned == loop_state.roots_total
@@ -930,7 +911,7 @@ fn update_file_notifications_on_threadpool(
930 subscriptions: Vec<FileId>, 911 subscriptions: Vec<FileId>,
931) { 912) {
932 log::trace!("updating notifications for {:?}", subscriptions); 913 log::trace!("updating notifications for {:?}", subscriptions);
933 let publish_diagnostics = world.feature_flags.get("lsp.diagnostics"); 914 let publish_diagnostics = world.config.publish_diagnostics;
934 pool.execute(move || { 915 pool.execute(move || {
935 for file_id in subscriptions { 916 for file_id in subscriptions {
936 if publish_diagnostics { 917 if publish_diagnostics {
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index bb99b38a8..d0f64f007 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -19,8 +19,8 @@ use lsp_types::{
19 TextEdit, WorkspaceEdit, 19 TextEdit, WorkspaceEdit,
20}; 20};
21use ra_ide::{ 21use ra_ide::{
22 Assist, AssistId, CompletionConfig, FileId, FilePosition, FileRange, Query, RangeInfo, 22 Assist, AssistId, FileId, FilePosition, FileRange, Query, RangeInfo, Runnable, RunnableKind,
23 Runnable, RunnableKind, SearchScope, 23 SearchScope,
24}; 24};
25use ra_prof::profile; 25use ra_prof::profile;
26use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; 26use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
@@ -426,15 +426,7 @@ pub fn handle_completion(
426 return Ok(None); 426 return Ok(None);
427 } 427 }
428 428
429 let config = CompletionConfig { 429 let items = match world.analysis().completions(position, &world.config.completion)? {
430 enable_postfix_completions: world.feature_flags.get("completion.enable-postfix"),
431 add_call_parenthesis: world.feature_flags.get("completion.insertion.add-call-parenthesis"),
432 add_call_argument_snippets: world
433 .feature_flags
434 .get("completion.insertion.add-argument-snippets"),
435 };
436
437 let items = match world.analysis().completions(position, &config)? {
438 None => return Ok(None), 430 None => return Ok(None),
439 Some(items) => items, 431 Some(items) => items,
440 }; 432 };
@@ -471,7 +463,7 @@ pub fn handle_signature_help(
471 let _p = profile("handle_signature_help"); 463 let _p = profile("handle_signature_help");
472 let position = params.try_conv_with(&world)?; 464 let position = params.try_conv_with(&world)?;
473 if let Some(call_info) = world.analysis().call_info(position)? { 465 if let Some(call_info) = world.analysis().call_info(position)? {
474 let concise = !world.feature_flags.get("call-info.full"); 466 let concise = !world.config.call_info_full;
475 let mut active_parameter = call_info.active_parameter.map(|it| it as i64); 467 let mut active_parameter = call_info.active_parameter.map(|it| it as i64);
476 if concise && call_info.signature.has_self_param { 468 if concise && call_info.signature.has_self_param {
477 active_parameter = active_parameter.map(|it| it.saturating_sub(1)); 469 active_parameter = active_parameter.map(|it| it.saturating_sub(1));
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs
index 124de4d8e..df1b7ceeb 100644
--- a/crates/rust-analyzer/src/world.rs
+++ b/crates/rust-analyzer/src/world.rs
@@ -23,7 +23,6 @@ use stdx::format_to;
23use crate::{ 23use crate::{
24 config::Config, 24 config::Config,
25 diagnostics::{CheckFixes, DiagnosticCollection}, 25 diagnostics::{CheckFixes, DiagnosticCollection},
26 feature_flags::FeatureFlags,
27 main_loop::pending_requests::{CompletedRequest, LatestRequests}, 26 main_loop::pending_requests::{CompletedRequest, LatestRequests},
28 vfs_glob::{Glob, RustPackageFilterBuilder}, 27 vfs_glob::{Glob, RustPackageFilterBuilder},
29 LspError, Result, 28 LspError, Result,
@@ -59,7 +58,6 @@ fn create_flycheck(workspaces: &[ProjectWorkspace], config: &Config) -> Option<F
59#[derive(Debug)] 58#[derive(Debug)]
60pub struct WorldState { 59pub struct WorldState {
61 pub config: Config, 60 pub config: Config,
62 pub feature_flags: Arc<FeatureFlags>,
63 pub roots: Vec<PathBuf>, 61 pub roots: Vec<PathBuf>,
64 pub workspaces: Arc<Vec<ProjectWorkspace>>, 62 pub workspaces: Arc<Vec<ProjectWorkspace>>,
65 pub analysis_host: AnalysisHost, 63 pub analysis_host: AnalysisHost,
@@ -73,7 +71,6 @@ pub struct WorldState {
73/// An immutable snapshot of the world's state at a point in time. 71/// An immutable snapshot of the world's state at a point in time.
74pub struct WorldSnapshot { 72pub struct WorldSnapshot {
75 pub config: Config, 73 pub config: Config,
76 pub feature_flags: Arc<FeatureFlags>,
77 pub workspaces: Arc<Vec<ProjectWorkspace>>, 74 pub workspaces: Arc<Vec<ProjectWorkspace>>,
78 pub analysis: Analysis, 75 pub analysis: Analysis,
79 pub latest_requests: Arc<RwLock<LatestRequests>>, 76 pub latest_requests: Arc<RwLock<LatestRequests>>,
@@ -89,7 +86,6 @@ impl WorldState {
89 exclude_globs: &[Glob], 86 exclude_globs: &[Glob],
90 watch: Watch, 87 watch: Watch,
91 config: Config, 88 config: Config,
92 feature_flags: FeatureFlags,
93 ) -> WorldState { 89 ) -> WorldState {
94 let mut change = AnalysisChange::new(); 90 let mut change = AnalysisChange::new();
95 91
@@ -197,7 +193,6 @@ impl WorldState {
197 analysis_host.apply_change(change); 193 analysis_host.apply_change(change);
198 WorldState { 194 WorldState {
199 config: config, 195 config: config,
200 feature_flags: Arc::new(feature_flags),
201 roots: folder_roots, 196 roots: folder_roots,
202 workspaces: Arc::new(workspaces), 197 workspaces: Arc::new(workspaces),
203 analysis_host, 198 analysis_host,
@@ -209,13 +204,7 @@ impl WorldState {
209 } 204 }
210 } 205 }
211 206
212 pub fn update_configuration( 207 pub fn update_configuration(&mut self, lru_capacity: Option<usize>, config: Config) {
213 &mut self,
214 lru_capacity: Option<usize>,
215 config: Config,
216 feature_flags: FeatureFlags,
217 ) {
218 self.feature_flags = Arc::new(feature_flags);
219 self.analysis_host.update_lru_capacity(lru_capacity); 208 self.analysis_host.update_lru_capacity(lru_capacity);
220 self.flycheck = create_flycheck(&self.workspaces, &config); 209 self.flycheck = create_flycheck(&self.workspaces, &config);
221 self.config = config; 210 self.config = config;
@@ -275,7 +264,6 @@ impl WorldState {
275 pub fn snapshot(&self) -> WorldSnapshot { 264 pub fn snapshot(&self) -> WorldSnapshot {
276 WorldSnapshot { 265 WorldSnapshot {
277 config: self.config.clone(), 266 config: self.config.clone(),
278 feature_flags: Arc::clone(&self.feature_flags),
279 workspaces: Arc::clone(&self.workspaces), 267 workspaces: Arc::clone(&self.workspaces),
280 analysis: self.analysis_host.analysis(), 268 analysis: self.analysis_host.analysis(),
281 vfs: Arc::clone(&self.vfs), 269 vfs: Arc::clone(&self.vfs),