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(-) 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 ++++++---- editors/code/package.json | 245 +++++++++++++++++++------------------ 2 files changed, 166 insertions(+), 146 deletions(-) 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); diff --git a/editors/code/package.json b/editors/code/package.json index 946145df8..df8adfe0e 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -177,81 +177,71 @@ "type": "object", "title": "Rust Analyzer", "properties": { - "rust-analyzer.highlighting.semanticTokens": { + "rust-analyzer.diagnostics.enable": { "type": "boolean", - "default": false, - "description": "Use proposed semantic tokens API for syntax highlighting" + "default": true, + "markdownDescription": "Whether to show native rust-analyzer diagnostics." }, - "rust-analyzer.featureFlags": { - "type": "object", - "default": {}, - "description": "Fine grained feature flags to disable annoying features", - "properties": { - "lsp.diagnostics": { - "type": "boolean", - "markdownDescription": "Whether to show diagnostics from `cargo check`" - }, - "completion.insertion.add-call-parenthesis": { - "type": "boolean", - "description": "Whether to add parenthesis when completing functions" - }, - "completion.insertion.add-argument-snippets": { - "type": "boolean", - "description": "Whether to add argument snippets when completing functions" - }, - "completion.enable-postfix": { - "type": "boolean", - "markdownDescription": "Whether to show postfix snippets like `dbg`, `if`, `not`, etc." - }, - "call-info.full": { - "type": "boolean", - "description": "Show function name and docs in parameter hints" - }, - "notifications.workspace-loaded": { - "type": "boolean", - "markdownDescription": "Whether to show `workspace loaded` message" - }, - "notifications.cargo-toml-not-found": { - "type": "boolean", - "markdownDescription": "Whether to show `can't find Cargo.toml` error message" - } - } + "rust-analyzer.lruCapacity": { + "type": [ + "null", + "integer" + ], + "default": null, + "minimum": 0, + "exclusiveMinimum": true, + "description": "Number of syntax trees rust-analyzer keeps in memory." }, - "rust-analyzer.updates.channel": { + "rust-analyzer.files.watcher": { "type": "string", "enum": [ - "stable", - "nightly" + "client", + "notify" ], - "default": "stable", - "markdownEnumDescriptions": [ - "`\"stable\"` updates are shipped weekly, they don't contain cutting-edge features from VSCode proposed APIs but have less bugs in general", - "`\"nightly\"` updates are shipped daily (extension updates automatically by downloading artifacts directly from GitHub), they contain cutting-edge features and latest bug fixes. These releases help us get your feedback very quickly and speed up rust-analyzer development **drastically**" - ], - "markdownDescription": "Choose `\"nightly\"` updates to get the latest features and bug fixes every day. While `\"stable\"` releases occur weekly and don't contain cutting-edge features from VSCode proposed APIs" + "default": "client", + "description": "Controls file watching implementation." }, - "rust-analyzer.updates.askBeforeDownload": { + "rust-analyzer.files.exclude": { + "type": "array", + "items": { + "type": "string" + }, + "default": [], + "description": "Paths to exclude from analysis." + }, + "rust-analyzer.notifications.workspaceLoaded": { "type": "boolean", - "default": true, - "description": "Whether to ask for permission before downloading any files from the Internet" + "markdownDescription": "Whether to show `workspace loaded` message." }, - "rust-analyzer.serverPath": { - "type": [ - "null", - "string" - ], - "default": null, - "description": "Path to rust-analyzer executable (points to bundled binary by default). If this is set, then \"rust-analyzer.updates.channel\" setting is not used" + "rust-analyzer.notifications.cargoTomlNotFound": { + "type": "boolean", + "markdownDescription": "Whether to show `can't find Cargo.toml` error message" + }, + + "rust-analyzer.cargo.noDefaultFeatures": { + "type": "boolean", + "default": false, + "markdownDescription": "Do not activate the `default` feature" }, - "rust-analyzer.excludeGlobs": { + "rust-analyzer.cargo.allFeatures": { + "type": "boolean", + "default": true, + "description": "Activate all available features" + }, + "rust-analyzer.cargo.features": { "type": "array", "items": { "type": "string" }, "default": [], - "description": "Paths to exclude from analysis" + "description": "List of features to activate" }, - "rust-analyzer.rustfmtArgs": { + "rust-analyzer.cargo.loadOutDirsFromCheck": { + "type": "boolean", + "default": false, + "markdownDescription": "Run `cargo check` on startup to get the correct value for package OUT_DIRs" + }, + "rust-analyzer.rustfmt.extraArgs": { "type": "array", "items": { "type": "string" @@ -259,65 +249,30 @@ "default": [], "description": "Additional arguments to rustfmt" }, - "rust-analyzer.useClientWatching": { + "rust-analyzer.checkOnSave.enable": { "type": "boolean", "default": true, - "description": "client provided file watching instead of notify watching." + "markdownDescription": "Run specified `cargo check` command for diagnostics on save" }, - "rust-analyzer.cargo-watch.enable": { - "type": "boolean", - "default": true, - "markdownDescription": "Run specified `cargo-watch` command for diagnostics on save" - }, - "rust-analyzer.cargo-watch.arguments": { + "rust-analyzer.checkOnSave.extraArgs": { "type": "array", "items": { "type": "string" }, - "markdownDescription": "`cargo-watch` arguments. (e.g: `--features=\"shumway,pdf\"` will run as `cargo watch -x \"check --features=\"shumway,pdf\"\"` )", + "markdownDescription": "Extra arguments for `cargo check`", "default": [] }, - "rust-analyzer.cargo-watch.command": { - "type": "string", - "markdownDescription": "`cargo-watch` command. (e.g: `clippy` will run as `cargo watch -x clippy` )", - "default": "check" - }, - "rust-analyzer.cargo-watch.allTargets": { - "type": "boolean", - "markdownDescription": "Check all targets and tests (will be passed as `--all-targets`)", - "default": true - }, - "rust-analyzer.trace.server": { + "rust-analyzer.checkOnSave.command": { "type": "string", - "scope": "window", - "enum": [ - "off", - "messages", - "verbose" - ], - "enumDescriptions": [ - "No traces", - "Error only", - "Full log" - ], - "default": "off", - "description": "Trace requests to the rust-analyzer" + "default": "check", + "markdownDescription": "Cargo command to use for `cargo check`" }, - "rust-analyzer.trace.extension": { - "description": "Enable logging of VS Code extensions itself", + "rust-analyzer.checkOnSave.allTargets": { "type": "boolean", - "default": false - }, - "rust-analyzer.lruCapacity": { - "type": [ - "null", - "integer" - ], - "default": null, - "minimum": 0, - "exclusiveMinimum": true, - "description": "Number of syntax trees rust-analyzer keeps in memory" + "default": true, + "markdownDescription": "Check all targets and tests (will be passed as `--all-targets`)" }, + "rust-analyzer.inlayHints.typeHints": { "type": "boolean", "default": true, @@ -343,29 +298,79 @@ "exclusiveMinimum": true, "description": "Maximum length for inlay hints" }, - "rust-analyzer.cargoFeatures.noDefaultFeatures": { + + "rust-analyzer.completion.addCallParenthesis": { "type": "boolean", - "default": false, - "markdownDescription": "Do not activate the `default` feature" + "default": true, + "description": "Whether to add parenthesis when completing functions" }, - "rust-analyzer.cargoFeatures.allFeatures": { + "rust-analyzer.completion.addCallArgumentSnippets": { "type": "boolean", "default": true, - "description": "Activate all available features" + "description": "Whether to add argument snippets when completing functions" }, - "rust-analyzer.cargoFeatures.features": { - "type": "array", - "items": { - "type": "string" - }, - "default": [], - "description": "List of features to activate" + "rust-analyzer.completion.postfix.enable": { + "type": "boolean", + "default": true, + "markdownDescription": "Whether to show postfix snippets like `dbg`, `if`, `not`, etc." + }, + "rust-analyzer.callInfo.full": { + "type": "boolean", + "description": "Show function name and docs in parameter hints" }, - "rust-analyzer.cargoFeatures.loadOutDirsFromCheck": { + + "rust-analyzer.highlighting.semanticTokens": { "type": "boolean", "default": false, - "markdownDescription": "Run `cargo check` on startup to get the correct value for package OUT_DIRs" - } + "description": "Use proposed semantic tokens API for syntax highlighting" + }, + "rust-analyzer.updates.channel": { + "type": "string", + "enum": [ + "stable", + "nightly" + ], + "default": "stable", + "markdownEnumDescriptions": [ + "`\"stable\"` updates are shipped weekly, they don't contain cutting-edge features from VSCode proposed APIs but have less bugs in general", + "`\"nightly\"` updates are shipped daily (extension updates automatically by downloading artifacts directly from GitHub), they contain cutting-edge features and latest bug fixes. These releases help us get your feedback very quickly and speed up rust-analyzer development **drastically**" + ], + "markdownDescription": "Choose `\"nightly\"` updates to get the latest features and bug fixes every day. While `\"stable\"` releases occur weekly and don't contain cutting-edge features from VSCode proposed APIs" + }, + "rust-analyzer.updates.askBeforeDownload": { + "type": "boolean", + "default": true, + "description": "Whether to ask for permission before downloading any files from the Internet" + }, + "rust-analyzer.serverPath": { + "type": [ + "null", + "string" + ], + "default": null, + "description": "Path to rust-analyzer executable (points to bundled binary by default). If this is set, then \"rust-analyzer.updates.channel\" setting is not used" + }, + "rust-analyzer.trace.server": { + "type": "string", + "scope": "window", + "enum": [ + "off", + "messages", + "verbose" + ], + "enumDescriptions": [ + "No traces", + "Error only", + "Full log" + ], + "default": "off", + "description": "Trace requests to the rust-analyzer" + }, + "rust-analyzer.trace.extension": { + "description": "Enable logging of VS Code extensions itself", + "type": "boolean", + "default": false + }, } }, "problemPatterns": [ -- 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 ++-- editors/code/package.json | 6 +----- editors/code/src/client.ts | 26 +------------------------- editors/code/src/config.ts | 30 ++++-------------------------- editors/code/src/ctx.ts | 3 +-- editors/code/src/status_display.ts | 2 +- 8 files changed, 24 insertions(+), 70 deletions(-) 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, diff --git a/editors/code/package.json b/editors/code/package.json index df8adfe0e..1f95cd130 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -217,7 +217,6 @@ "type": "boolean", "markdownDescription": "Whether to show `can't find Cargo.toml` error message" }, - "rust-analyzer.cargo.noDefaultFeatures": { "type": "boolean", "default": false, @@ -272,7 +271,6 @@ "default": true, "markdownDescription": "Check all targets and tests (will be passed as `--all-targets`)" }, - "rust-analyzer.inlayHints.typeHints": { "type": "boolean", "default": true, @@ -298,7 +296,6 @@ "exclusiveMinimum": true, "description": "Maximum length for inlay hints" }, - "rust-analyzer.completion.addCallParenthesis": { "type": "boolean", "default": true, @@ -318,7 +315,6 @@ "type": "boolean", "description": "Show function name and docs in parameter hints" }, - "rust-analyzer.highlighting.semanticTokens": { "type": "boolean", "default": false, @@ -370,7 +366,7 @@ "description": "Enable logging of VS Code extensions itself", "type": "boolean", "default": false - }, + } } }, "problemPatterns": [ diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 8ddc1cdca..3b1d00bca 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -5,30 +5,6 @@ import { Config } from './config'; import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed'; import { SemanticTokensFeature, DocumentSemanticsTokensSignature } from 'vscode-languageclient/lib/semanticTokens.proposed'; -export function configToServerOptions(config: Config) { - return { - lruCapacity: config.lruCapacity, - - inlayHintsType: config.inlayHints.typeHints, - inlayHintsParameter: config.inlayHints.parameterHints, - inlayHintsChaining: config.inlayHints.chainingHints, - inlayHintsMaxLength: config.inlayHints.maxLength, - - cargoWatchEnable: config.cargoWatchOptions.enable, - cargoWatchArgs: config.cargoWatchOptions.arguments, - cargoWatchCommand: config.cargoWatchOptions.command, - cargoWatchAllTargets: config.cargoWatchOptions.allTargets, - - excludeGlobs: config.excludeGlobs, - useClientWatching: config.useClientWatching, - featureFlags: config.featureFlags, - withSysroot: config.withSysroot, - cargoFeatures: config.cargoFeatures, - rustfmtArgs: config.rustfmtArgs, - vscodeLldb: vscode.extensions.getExtension("vadimcn.vscode-lldb") != null, - }; -} - export async function createClient(config: Config, serverPath: string, cwd: string): Promise { // '.' Is the fallback if no folder is open // TODO?: Workspace folders support Uri's (eg: file://test.txt). @@ -48,7 +24,7 @@ export async function createClient(config: Config, serverPath: string, cwd: stri const clientOptions: lc.LanguageClientOptions = { documentSelector: [{ scheme: 'file', language: 'rust' }], - initializationOptions: configToServerOptions(config), + initializationOptions: vscode.workspace.getConfiguration("rust-analyzer"), traceOutputChannel, middleware: { // Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576 diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index c37c6276b..1f45f1de0 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -11,9 +11,8 @@ export class Config { private readonly rootSection = "rust-analyzer"; private readonly requiresReloadOpts = [ "serverPath", - "cargoFeatures", - "excludeGlobs", - "useClientWatching", + "cargo", + "files", "highlighting", "updates.channel", ] @@ -71,17 +70,8 @@ export class Config { get channel() { return this.cfg.get("updates.channel")!; } get askBeforeDownload() { return this.cfg.get("updates.askBeforeDownload")!; } get highlightingSemanticTokens() { return this.cfg.get("highlighting.semanticTokens")!; } - get lruCapacity() { return this.cfg.get("lruCapacity")!; } - get excludeGlobs() { return this.cfg.get("excludeGlobs")!; } - get useClientWatching() { return this.cfg.get("useClientWatching")!; } - get featureFlags() { return this.cfg.get>("featureFlags")!; } - get rustfmtArgs() { return this.cfg.get("rustfmtArgs")!; } - get loadOutDirsFromCheck() { return this.cfg.get("loadOutDirsFromCheck")!; } get traceExtension() { return this.cfg.get("trace.extension")!; } - // for internal use - get withSysroot() { return this.cfg.get("withSysroot", true)!; } - get inlayHints() { return { typeHints: this.cfg.get("inlayHints.typeHints")!, @@ -91,21 +81,9 @@ export class Config { }; } - get cargoWatchOptions() { - return { - enable: this.cfg.get("cargo-watch.enable")!, - arguments: this.cfg.get("cargo-watch.arguments")!, - allTargets: this.cfg.get("cargo-watch.allTargets")!, - command: this.cfg.get("cargo-watch.command")!, - }; - } - - get cargoFeatures() { + get checkOnSave() { return { - noDefaultFeatures: this.cfg.get("cargoFeatures.noDefaultFeatures")!, - allFeatures: this.cfg.get("cargoFeatures.allFeatures")!, - features: this.cfg.get("cargoFeatures.features")!, - loadOutDirsFromCheck: this.cfg.get("cargoFeatures.loadOutDirsFromCheck")!, + command: this.cfg.get("checkOnSave.command")!, }; } } diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index 86b5f3629..bd1c3de07 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -2,7 +2,7 @@ import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; import { Config } from './config'; -import { createClient, configToServerOptions } from './client'; +import { createClient } from './client'; import { isRustEditor, RustEditor } from './util'; export class Ctx { @@ -25,7 +25,6 @@ export class Ctx { const res = new Ctx(config, extCtx, client, serverPath); res.pushCleanup(client.start()); await client.onReady(); - client.onRequest('workspace/configuration', _ => [configToServerOptions(config)]); return res; } diff --git a/editors/code/src/status_display.ts b/editors/code/src/status_display.ts index 0f5f6ef99..f9cadc8a2 100644 --- a/editors/code/src/status_display.ts +++ b/editors/code/src/status_display.ts @@ -7,7 +7,7 @@ import { Ctx } from './ctx'; const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; export function activateStatusDisplay(ctx: Ctx) { - const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command); + const statusDisplay = new StatusDisplay(ctx.config.checkOnSave.command); ctx.pushCleanup(statusDisplay); const client = ctx.client; if (client != null) { -- 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(-) 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 ++++++++++++-------------- editors/code/src/commands/runnables.ts | 4 ++++ 3 files changed, 18 insertions(+), 20 deletions(-) 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 diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 357155163..2635a1440 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -66,6 +66,10 @@ export function debugSingle(ctx: Ctx): Cmd { return async (config: ra.Runnable) => { const editor = ctx.activeRustEditor; if (!editor) return; + if (!vscode.extensions.getExtension("vadimcn.vscode-lldb")) { + vscode.window.showErrorMessage("Install `vadimcn.vscode-lldb` extension for debugging"); + return; + } const debugConfig = { type: "lldb", -- cgit v1.2.3