From 6af4bf7a8d27e653d2e6316172fe140871054d27 Mon Sep 17 00:00:00 2001 From: Emil Lauridsen Date: Wed, 25 Dec 2019 16:50:38 +0100 Subject: Configuration plumbing for cargo watcher --- editors/code/package.json | 40 ++++++++----------------------- editors/code/src/config.ts | 59 ++++++++++++---------------------------------- editors/code/src/server.ts | 3 +++ 3 files changed, 28 insertions(+), 74 deletions(-) (limited to 'editors') diff --git a/editors/code/package.json b/editors/code/package.json index 6cb24a3ce..5f4123397 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -188,20 +188,10 @@ "default": "ra_lsp_server", "description": "Path to ra_lsp_server executable" }, - "rust-analyzer.enableCargoWatchOnStartup": { - "type": "string", - "default": "ask", - "enum": [ - "ask", - "enabled", - "disabled" - ], - "enumDescriptions": [ - "Asks each time whether to run `cargo watch`", - "`cargo watch` is always started", - "Don't start `cargo watch`" - ], - "description": "Whether to run `cargo watch` on startup" + "rust-analyzer.enableCargoCheck": { + "type": "boolean", + "default": true, + "description": "Run `cargo check` for diagnostics on save" }, "rust-analyzer.excludeGlobs": { "type": "array", @@ -213,25 +203,15 @@ "default": true, "description": "client provided file watching instead of notify watching." }, - "rust-analyzer.cargo-watch.arguments": { - "type": "string", - "description": "`cargo-watch` arguments. (e.g: `--features=\"shumway,pdf\"` will run as `cargo watch -x \"check --features=\"shumway,pdf\"\"` )", - "default": "" - }, - "rust-analyzer.cargo-watch.command": { - "type": "string", - "description": "`cargo-watch` command. (e.g: `clippy` will run as `cargo watch -x clippy` )", - "default": "check" - }, - "rust-analyzer.cargo-watch.ignore": { + "rust-analyzer.cargo-check.arguments": { "type": "array", - "description": "A list of patterns for cargo-watch to ignore (will be passed as `--ignore`)", + "description": "`cargo-check` arguments. (e.g: `--features=\"shumway,pdf\"` will run as `cargo check --features=\"shumway,pdf\"` )", "default": [] }, - "rust-analyzer.cargo-watch.allTargets": { - "type": "boolean", - "description": "Check all targets and tests (will be passed as `--all-targets`)", - "default": true + "rust-analyzer.cargo-check.command": { + "type": "string", + "description": "`cargo-check` command. (e.g: `clippy` will run as `cargo clippy` )", + "default": "check" }, "rust-analyzer.trace.server": { "type": "string", diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index e131f09df..96532e2c9 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -4,16 +4,10 @@ import { Server } from './server'; const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; -export type CargoWatchStartupOptions = 'ask' | 'enabled' | 'disabled'; -export type CargoWatchTraceOptions = 'off' | 'error' | 'verbose'; - -export interface CargoWatchOptions { - enableOnStartup: CargoWatchStartupOptions; - arguments: string; - command: string; - trace: CargoWatchTraceOptions; - ignore: string[]; - allTargets: boolean; +export interface CargoCheckOptions { + enabled: boolean; + arguments: string[]; + command: null | string; } export interface CargoFeatures { @@ -35,13 +29,10 @@ export class Config { public featureFlags = {}; // for internal use public withSysroot: null | boolean = null; - public cargoWatchOptions: CargoWatchOptions = { - enableOnStartup: 'ask', - trace: 'off', - arguments: '', - command: '', - ignore: [], - allTargets: true, + public cargoCheckOptions: CargoCheckOptions = { + enabled: true, + arguments: [], + command: null, }; public cargoFeatures: CargoFeatures = { noDefaultFeatures: false, @@ -100,47 +91,27 @@ export class Config { RA_LSP_DEBUG || (config.get('raLspServerPath') as string); } - if (config.has('enableCargoWatchOnStartup')) { - this.cargoWatchOptions.enableOnStartup = config.get< - CargoWatchStartupOptions - >('enableCargoWatchOnStartup', 'ask'); - } - - if (config.has('trace.cargo-watch')) { - this.cargoWatchOptions.trace = config.get( - 'trace.cargo-watch', - 'off', + if (config.has('enableCargoCheck')) { + this.cargoCheckOptions.enabled = config.get( + 'enableCargoCheck', + true, ); } if (config.has('cargo-watch.arguments')) { - this.cargoWatchOptions.arguments = config.get( + this.cargoCheckOptions.arguments = config.get( 'cargo-watch.arguments', - '', + [], ); } if (config.has('cargo-watch.command')) { - this.cargoWatchOptions.command = config.get( + this.cargoCheckOptions.command = config.get( 'cargo-watch.command', '', ); } - if (config.has('cargo-watch.ignore')) { - this.cargoWatchOptions.ignore = config.get( - 'cargo-watch.ignore', - [], - ); - } - - if (config.has('cargo-watch.allTargets')) { - this.cargoWatchOptions.allTargets = config.get( - 'cargo-watch.allTargets', - true, - ); - } - if (config.has('lruCapacity')) { this.lruCapacity = config.get('lruCapacity') as number; } diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts index 5ace1d0fa..409d3b4b7 100644 --- a/editors/code/src/server.ts +++ b/editors/code/src/server.ts @@ -55,6 +55,9 @@ export class Server { publishDecorations: true, lruCapacity: Server.config.lruCapacity, maxInlayHintLength: Server.config.maxInlayHintLength, + cargoCheckEnable: Server.config.cargoCheckOptions.enabled, + cargoCheckCommand: Server.config.cargoCheckOptions.command, + cargoCheckArgs: Server.config.cargoCheckOptions.arguments, excludeGlobs: Server.config.excludeGlobs, useClientWatching: Server.config.useClientWatching, featureFlags: Server.config.featureFlags, -- cgit v1.2.3