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