From 0dde0f92dee7080b91343238ddfa312cc1a7001a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 2 Apr 2020 11:33:49 +0200 Subject: Reorder fields --- crates/rust-analyzer/src/config.rs | 91 ++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 44 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 602423919..f4c154058 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -16,20 +16,24 @@ use serde::Deserialize; #[derive(Debug, Clone)] pub struct Config { pub client_caps: ClientCapsConfig, + + pub with_sysroot: bool, pub publish_diagnostics: bool, - pub notifications: NotificationsConfig, - pub inlay_hints: InlayHintsConfig, - pub completion: CompletionConfig, - pub call_info_full: bool, - pub rustfmt: RustfmtConfig, - pub check: Option, + pub use_client_watching: bool, + // TODO: move to experimental capabilities pub vscode_lldb: bool, - pub proc_macro_srv: Option, pub lru_capacity: Option, - pub use_client_watching: bool, + pub proc_macro_srv: Option, pub exclude_globs: Vec, + pub notifications: NotificationsConfig, + pub cargo: CargoConfig, - pub with_sysroot: bool, + pub rustfmt: RustfmtConfig, + pub check: Option, + + pub inlay_hints: InlayHintsConfig, + pub completion: CompletionConfig, + pub call_info_full: bool, } #[derive(Debug, Clone)] @@ -59,12 +63,28 @@ pub struct ClientCapsConfig { impl Default for Config { fn default() -> Self { Config { + client_caps: ClientCapsConfig::default(), + + with_sysroot: true, publish_diagnostics: true, + use_client_watching: false, + vscode_lldb: false, + lru_capacity: None, + proc_macro_srv: None, + exclude_globs: Vec::new(), notifications: NotificationsConfig { workspace_loaded: true, cargo_toml_not_found: true, }, - client_caps: ClientCapsConfig::default(), + + cargo: CargoConfig::default(), + rustfmt: RustfmtConfig::Rustfmt { extra_args: Vec::new() }, + check: Some(FlycheckConfig::CargoCommand { + command: "check".to_string(), + all_targets: true, + extra_args: Vec::new(), + }), + inlay_hints: InlayHintsConfig { type_hints: true, parameter_hints: true, @@ -77,19 +97,6 @@ impl Default for Config { add_call_argument_snippets: true, }, call_info_full: true, - rustfmt: RustfmtConfig::Rustfmt { extra_args: Vec::new() }, - check: Some(FlycheckConfig::CargoCommand { - command: "check".to_string(), - all_targets: true, - extra_args: Vec::new(), - }), - vscode_lldb: false, - proc_macro_srv: None, - lru_capacity: None, - use_client_watching: false, - exclude_globs: Vec::new(), - cargo: CargoConfig::default(), - with_sysroot: true, } } } @@ -103,15 +110,22 @@ impl Config { *self = Default::default(); self.client_caps = client_caps; - set(value, "/excludeGlobs", &mut self.exclude_globs); + set(value, "/withSysroot", &mut self.with_sysroot); + set(value, "/featureFlags/lsp.diagnostics", &mut self.publish_diagnostics); set(value, "/useClientWatching", &mut self.use_client_watching); + set(value, "/vscodeLldb", &mut self.vscode_lldb); set(value, "/lruCapacity", &mut self.lru_capacity); + set(value, "/excludeGlobs", &mut self.exclude_globs); + set(value, "/featureFlags/notifications.workspace-loaded", &mut self.notifications.workspace_loaded); + set(value, "/featureFlags/notifications.cargo-toml-not-found", &mut self.notifications.cargo_toml_not_found); - set(value, "/inlayHintsType", &mut self.inlay_hints.type_hints); - set(value, "/inlayHintsParameter", &mut self.inlay_hints.parameter_hints); - set(value, "/inlayHintsChaining", &mut self.inlay_hints.chaining_hints); - set(value, "/inlayHintsMaxLength", &mut self.inlay_hints.max_length); - + set(value, "/cargoFeatures/noDefaultFeatures", &mut self.cargo.no_default_features); + set(value, "/cargoFeatures/allFeatures", &mut self.cargo.all_features); + set(value, "/cargoFeatures/features", &mut self.cargo.features); + set(value, "/cargoFeatures/loadOutDirsFromCheck", &mut self.cargo.load_out_dirs_from_check); + if let RustfmtConfig::Rustfmt { extra_args } = &mut self.rustfmt { + set(value, "/rustfmtArgs", extra_args); + } if let Some(false) = get(value, "cargo_watch_enable") { self.check = None } else { @@ -123,21 +137,10 @@ impl Config { } }; - set(value, "/withSysroot", &mut self.with_sysroot); - if let RustfmtConfig::Rustfmt { extra_args } = &mut self.rustfmt { - set(value, "/rustfmtArgs", extra_args); - } - - set(value, "/cargoFeatures/noDefaultFeatures", &mut self.cargo.no_default_features); - set(value, "/cargoFeatures/allFeatures", &mut self.cargo.all_features); - set(value, "/cargoFeatures/features", &mut self.cargo.features); - set(value, "/cargoFeatures/loadOutDirsFromCheck", &mut self.cargo.load_out_dirs_from_check); - - set(value, "/vscodeLldb", &mut self.vscode_lldb); - - set(value, "/featureFlags/lsp.diagnostics", &mut self.publish_diagnostics); - set(value, "/featureFlags/notifications.workspace-loaded", &mut self.notifications.workspace_loaded); - set(value, "/featureFlags/notifications.cargo-toml-not-found", &mut self.notifications.cargo_toml_not_found); + set(value, "/inlayHintsType", &mut self.inlay_hints.type_hints); + set(value, "/inlayHintsParameter", &mut self.inlay_hints.parameter_hints); + set(value, "/inlayHintsChaining", &mut self.inlay_hints.chaining_hints); + set(value, "/inlayHintsMaxLength", &mut self.inlay_hints.max_length); set(value, "/featureFlags/completion.enable-postfix", &mut self.completion.enable_postfix_completions); set(value, "/featureFlags/completion.insertion.add-call-parenthesis", &mut self.completion.add_call_parenthesis); set(value, "/featureFlags/completion.insertion.add-argument-snippets", &mut self.completion.add_call_argument_snippets); -- cgit v1.2.3 From e4cf40a152120c6c3cba1822e56026ae04be63f0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 2 Apr 2020 11:55:04 +0200 Subject: New config in package.json --- crates/rust-analyzer/src/config.rs | 67 +++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 26 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index f4c154058..b19421c16 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -18,13 +18,13 @@ pub struct Config { pub client_caps: ClientCapsConfig, pub with_sysroot: bool, + // TODO: verify that it means what I think it means pub publish_diagnostics: bool, - pub use_client_watching: bool, // TODO: move to experimental capabilities pub vscode_lldb: bool, pub lru_capacity: Option, pub proc_macro_srv: Option, - pub exclude_globs: Vec, + pub files: FilesConfig, pub notifications: NotificationsConfig, pub cargo: CargoConfig, @@ -36,6 +36,18 @@ pub struct Config { pub call_info_full: bool, } +#[derive(Debug, Clone)] +pub struct FilesConfig { + watcher: FilesWatcher, + exclude: Vec, +} + +#[derive(Debug, Clone)] +enum FilesWatcher { + Client, + Notify, +} + #[derive(Debug, Clone)] pub struct NotificationsConfig { pub workspace_loaded: bool, @@ -67,11 +79,10 @@ impl Default for Config { with_sysroot: true, publish_diagnostics: true, - use_client_watching: false, vscode_lldb: false, lru_capacity: None, proc_macro_srv: None, - exclude_globs: Vec::new(), + files: FilesConfig { watcher: FilesWatcher::Notify, exclude: Vec::new() }, notifications: NotificationsConfig { workspace_loaded: true, cargo_toml_not_found: true, @@ -112,39 +123,43 @@ impl Config { set(value, "/withSysroot", &mut self.with_sysroot); set(value, "/featureFlags/lsp.diagnostics", &mut self.publish_diagnostics); - set(value, "/useClientWatching", &mut self.use_client_watching); set(value, "/vscodeLldb", &mut self.vscode_lldb); set(value, "/lruCapacity", &mut self.lru_capacity); - set(value, "/excludeGlobs", &mut self.exclude_globs); - set(value, "/featureFlags/notifications.workspace-loaded", &mut self.notifications.workspace_loaded); - set(value, "/featureFlags/notifications.cargo-toml-not-found", &mut self.notifications.cargo_toml_not_found); - - set(value, "/cargoFeatures/noDefaultFeatures", &mut self.cargo.no_default_features); - set(value, "/cargoFeatures/allFeatures", &mut self.cargo.all_features); - set(value, "/cargoFeatures/features", &mut self.cargo.features); - set(value, "/cargoFeatures/loadOutDirsFromCheck", &mut self.cargo.load_out_dirs_from_check); + if let Some(watcher) = get::(value, "/files/watcher") { + self.files.watcher = match watcher.as_str() { + "client" => FilesWatcher::Client, + "notify"| _ => FilesWatcher::Notify, + } + } + set(value, "/notifications/workspaceLoaded", &mut self.notifications.workspace_loaded); + set(value, "/notifications/cargoTomlNotFound", &mut self.notifications.cargo_toml_not_found); + + set(value, "/cargo/noDefaultFeatures", &mut self.cargo.no_default_features); + set(value, "/cargo/allFeatures", &mut self.cargo.all_features); + set(value, "/cargo/features", &mut self.cargo.features); + set(value, "/cargo/loadOutDirsFromCheck", &mut self.cargo.load_out_dirs_from_check); if let RustfmtConfig::Rustfmt { extra_args } = &mut self.rustfmt { - set(value, "/rustfmtArgs", extra_args); + set(value, "/rustfmt/extraArgs", extra_args); } - if let Some(false) = get(value, "cargo_watch_enable") { + if let Some(false) = get(value, "/checkOnSave/enable") { self.check = None } else { if let Some(FlycheckConfig::CargoCommand { command, extra_args, all_targets }) = &mut self.check { - set(value, "/cargoWatchArgs", extra_args); - set(value, "/cargoWatchCommand", command); - set(value, "/cargoWatchAllTargets", all_targets); + set(value, "/checkOnSave/extraArgs", extra_args); + set(value, "/checkOnSave/command", command); + set(value, "/checkOnSave/allTargets", all_targets); } }; - set(value, "/inlayHintsType", &mut self.inlay_hints.type_hints); - set(value, "/inlayHintsParameter", &mut self.inlay_hints.parameter_hints); - set(value, "/inlayHintsChaining", &mut self.inlay_hints.chaining_hints); - set(value, "/inlayHintsMaxLength", &mut self.inlay_hints.max_length); - set(value, "/featureFlags/completion.enable-postfix", &mut self.completion.enable_postfix_completions); - set(value, "/featureFlags/completion.insertion.add-call-parenthesis", &mut self.completion.add_call_parenthesis); - set(value, "/featureFlags/completion.insertion.add-argument-snippets", &mut self.completion.add_call_argument_snippets); - set(value, "/featureFlags/call-info.full", &mut self.call_info_full); + set(value, "/inlayHints/typeHints", &mut self.inlay_hints.type_hints); + set(value, "/inlayHints/parameterHints", &mut self.inlay_hints.parameter_hints); + set(value, "/inlayHints/chainingHints", &mut self.inlay_hints.chaining_hints); + set(value, "/inlayHints/maxLength", &mut self.inlay_hints.max_length); + set(value, "/completion/postfix/enable", &mut self.completion.enable_postfix_completions); + set(value, "/completion/addCallParenthesis", &mut self.completion.add_call_parenthesis); + set(value, "/completion/addCallArgumentSnippets", &mut self.completion.add_call_argument_snippets); + set(value, "/callInfo/full", &mut self.call_info_full); log::info!("Config::update() = {:#?}", self); -- cgit v1.2.3 From 48c58309cca718701e902b05221a8e8ec81310db Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 2 Apr 2020 12:47:58 +0200 Subject: Lean onto default implementation of configs --- crates/rust-analyzer/src/config.rs | 6 +++--- crates/rust-analyzer/src/main_loop.rs | 17 +++++++++++------ crates/rust-analyzer/src/req.rs | 4 ++-- 3 files changed, 16 insertions(+), 11 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index b19421c16..15aab7f09 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -38,12 +38,12 @@ pub struct Config { #[derive(Debug, Clone)] pub struct FilesConfig { - watcher: FilesWatcher, - exclude: Vec, + pub watcher: FilesWatcher, + pub exclude: Vec, } #[derive(Debug, Clone)] -enum FilesWatcher { +pub enum FilesWatcher { Client, Notify, } diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 47fef59d4..36ea85cc6 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -30,7 +30,7 @@ use serde::{de::DeserializeOwned, Serialize}; use threadpool::ThreadPool; use crate::{ - config::Config, + config::{Config, FilesWatcher}, diagnostics::DiagnosticTask, main_loop::{ pending_requests::{PendingRequest, PendingRequests}, @@ -40,7 +40,6 @@ use crate::{ world::{WorldSnapshot, WorldState}, Result, }; -use req::ConfigurationParams; #[derive(Debug)] pub struct LspError { @@ -122,12 +121,13 @@ pub fn main_loop(ws_roots: Vec, config: Config, connection: Connection) }; let globs = config - .exclude_globs + .files + .exclude .iter() .map(|glob| crate::vfs_glob::Glob::new(glob)) .collect::, _>>()?; - if config.use_client_watching { + if let FilesWatcher::Client = config.files.watcher { let registration_options = req::DidChangeWatchedFilesRegistrationOptions { watchers: workspaces .iter() @@ -153,7 +153,7 @@ pub fn main_loop(ws_roots: Vec, config: Config, connection: Connection) workspaces, config.lru_capacity, &globs, - Watch(!config.use_client_watching), + Watch(matches!(config.files.watcher, FilesWatcher::Notify)), config, ) }; @@ -607,7 +607,12 @@ fn on_notification( let request_id = loop_state.next_request_id(); let request = request_new::( request_id.clone(), - ConfigurationParams::default(), + req::ConfigurationParams { + items: vec![req::ConfigurationItem { + scope_uri: None, + section: Some("rust-analyzer".to_string()), + }], + }, ); msg_sender.send(request.into())?; loop_state.configuration_request_id = Some(request_id); diff --git a/crates/rust-analyzer/src/req.rs b/crates/rust-analyzer/src/req.rs index ce799a683..b8b627e28 100644 --- a/crates/rust-analyzer/src/req.rs +++ b/crates/rust-analyzer/src/req.rs @@ -6,8 +6,8 @@ use serde::{Deserialize, Serialize}; pub use lsp_types::{ notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens, - CodeLensParams, CompletionParams, CompletionResponse, ConfigurationParams, DiagnosticTag, - DidChangeConfigurationParams, DidChangeWatchedFilesParams, + CodeLensParams, CompletionParams, CompletionResponse, ConfigurationItem, ConfigurationParams, + DiagnosticTag, DidChangeConfigurationParams, DidChangeWatchedFilesParams, DidChangeWatchedFilesRegistrationOptions, DocumentOnTypeFormattingParams, DocumentSymbolParams, DocumentSymbolResponse, FileSystemWatcher, Hover, InitializeResult, MessageType, PartialResultParams, ProgressParams, ProgressParamsValue, ProgressToken, -- cgit v1.2.3 From e21bf1b2b91041be601d22c3415daf9bcb7246a8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 2 Apr 2020 12:50:34 +0200 Subject: Siplify --- crates/rust-analyzer/src/config.rs | 1 - crates/rust-analyzer/src/main_loop.rs | 11 +++++------ 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 15aab7f09..07fb8f16a 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -18,7 +18,6 @@ pub struct Config { pub client_caps: ClientCapsConfig, pub with_sysroot: bool, - // TODO: verify that it means what I think it means pub publish_diagnostics: bool, // TODO: move to experimental capabilities pub vscode_lldb: bool, diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 36ea85cc6..95e676e0f 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -889,10 +889,9 @@ fn update_file_notifications_on_threadpool( subscriptions: Vec, ) { log::trace!("updating notifications for {:?}", subscriptions); - let publish_diagnostics = world.config.publish_diagnostics; - pool.execute(move || { - for file_id in subscriptions { - if publish_diagnostics { + if world.config.publish_diagnostics { + pool.execute(move || { + for file_id in subscriptions { match handlers::publish_diagnostics(&world, file_id) { Err(e) => { if !is_canceled(&e) { @@ -904,8 +903,8 @@ fn update_file_notifications_on_threadpool( } } } - } - }); + }) + } } pub fn show_message(typ: req::MessageType, message: impl Into, sender: &Sender) { -- cgit v1.2.3 From 7a4ebd2c8dfee8ca15dab7ba053a6521840aa5e3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 2 Apr 2020 12:56:14 +0200 Subject: Remove vscode_lldb setting --- crates/rust-analyzer/src/config.rs | 4 ---- crates/rust-analyzer/src/main_loop/handlers.rs | 30 ++++++++++++-------------- 2 files changed, 14 insertions(+), 20 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 07fb8f16a..f3d8773cc 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -19,8 +19,6 @@ pub struct Config { pub with_sysroot: bool, pub publish_diagnostics: bool, - // TODO: move to experimental capabilities - pub vscode_lldb: bool, pub lru_capacity: Option, pub proc_macro_srv: Option, pub files: FilesConfig, @@ -78,7 +76,6 @@ impl Default for Config { with_sysroot: true, publish_diagnostics: true, - vscode_lldb: false, lru_capacity: None, proc_macro_srv: None, files: FilesConfig { watcher: FilesWatcher::Notify, exclude: Vec::new() }, @@ -122,7 +119,6 @@ impl Config { set(value, "/withSysroot", &mut self.with_sysroot); set(value, "/featureFlags/lsp.diagnostics", &mut self.publish_diagnostics); - set(value, "/vscodeLldb", &mut self.vscode_lldb); set(value, "/lruCapacity", &mut self.lru_capacity); if let Some(watcher) = get::(value, "/files/watcher") { self.files.watcher = match watcher.as_str() { diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs index db620dca3..b207f0764 100644 --- a/crates/rust-analyzer/src/main_loop/handlers.rs +++ b/crates/rust-analyzer/src/main_loop/handlers.rs @@ -810,23 +810,21 @@ pub fn handle_code_lens( }; lenses.push(lens); - if world.config.vscode_lldb { - if r.args[0] == "run" { - r.args[0] = "build".into(); - } else { - r.args.push("--no-run".into()); - } - let debug_lens = CodeLens { - range: r.range, - command: Some(Command { - title: "Debug".into(), - command: "rust-analyzer.debugSingle".into(), - arguments: Some(vec![to_value(r).unwrap()]), - }), - data: None, - }; - lenses.push(debug_lens); + if r.args[0] == "run" { + r.args[0] = "build".into(); + } else { + r.args.push("--no-run".into()); } + let debug_lens = CodeLens { + range: r.range, + command: Some(Command { + title: "Debug".into(), + command: "rust-analyzer.debugSingle".into(), + arguments: Some(vec![to_value(r).unwrap()]), + }), + data: None, + }; + lenses.push(debug_lens); } // Handle impls -- cgit v1.2.3