From af4eb266457eb784010da28d80535f9fd38d4d1e Mon Sep 17 00:00:00 2001 From: oxalica Date: Fri, 13 Dec 2019 18:16:34 +0800 Subject: Support setting cargo features --- editors/code/package.json | 15 ++++++++++ editors/code/src/config.ts | 70 +++++++++++++++++++++++++++++++++++++--------- editors/code/src/server.ts | 1 + 3 files changed, 73 insertions(+), 13 deletions(-) (limited to 'editors/code') diff --git a/editors/code/package.json b/editors/code/package.json index 7bc08ec31..8ed95fda7 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -278,6 +278,21 @@ "type": "number", "default": 20, "description": "Maximum length for inlay hints" + }, + "rust-analyzer.cargoFeatures.noDefaultFeatures": { + "type": "boolean", + "default": false, + "description": "Do not activate the `default` feature" + }, + "rust-analyzer.cargoFeatures.allFeatures": { + "type": "boolean", + "default": false, + "description": "Activate all available features" + }, + "rust-analyzer.cargoFeatures.features": { + "type": "array", + "default": [], + "description": "List of features to activate" } } }, diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 2d3b6a54e..6d709f7a8 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -15,6 +15,12 @@ export interface CargoWatchOptions { ignore: string[]; } +export interface CargoFeatures { + noDefaultFeatures: boolean; + allFeatures: boolean; + features: string[]; +} + export class Config { public highlightingOn = true; public rainbowHighlightingOn = false; @@ -35,8 +41,14 @@ export class Config { command: '', ignore: [], }; + public cargoFeatures: CargoFeatures = { + noDefaultFeatures: false, + allFeatures: false, + features: [], + }; private prevEnhancedTyping: null | boolean = null; + private prevCargoFeatures: null | CargoFeatures = null; constructor() { vscode.workspace.onDidChangeConfiguration(_ => @@ -47,6 +59,8 @@ export class Config { public userConfigChanged() { const config = vscode.workspace.getConfiguration('rust-analyzer'); + let requireReloadMessage = null; + if (config.has('highlightingOn')) { this.highlightingOn = config.get('highlightingOn') as boolean; } @@ -74,19 +88,7 @@ export class Config { } if (this.prevEnhancedTyping !== this.enableEnhancedTyping) { - const reloadAction = 'Reload now'; - vscode.window - .showInformationMessage( - 'Changing enhanced typing setting requires a reload', - reloadAction, - ) - .then(selectedAction => { - if (selectedAction === reloadAction) { - vscode.commands.executeCommand( - 'workbench.action.reloadWindow', - ); - } - }); + requireReloadMessage = 'Changing enhanced typing setting requires a reload'; this.prevEnhancedTyping = this.enableEnhancedTyping; } @@ -153,5 +155,47 @@ export class Config { if (config.has('withSysroot')) { this.withSysroot = config.get('withSysroot') || false; } + + if (config.has('cargoFeatures.noDefaultFeatures')) { + this.cargoFeatures.noDefaultFeatures = config.get( + 'cargoFeatures.noDefaultFeatures', + false, + ); + } + if (config.has('cargoFeatures.allFeatures')) { + this.cargoFeatures.allFeatures = config.get( + 'cargoFeatures.allFeatures', + false, + ); + } + if (config.has('cargoFeatures.features')) { + this.cargoFeatures.features = config.get( + 'cargoFeatures.features', + [], + ); + } + + if (this.prevCargoFeatures !== null && ( + this.cargoFeatures.allFeatures !== this.prevCargoFeatures.allFeatures || + this.cargoFeatures.noDefaultFeatures !== this.prevCargoFeatures.noDefaultFeatures || + this.cargoFeatures.features.length !== this.prevCargoFeatures.features.length || + this.cargoFeatures.features.some((v, i) => v !== this.prevCargoFeatures!.features[i]) + )) { + requireReloadMessage = 'Changing cargo features requires a reload'; + } + this.prevCargoFeatures = { ...this.cargoFeatures }; + + if (requireReloadMessage !== null) { + const reloadAction = 'Reload now'; + vscode.window + .showInformationMessage(requireReloadMessage, reloadAction) + .then(selectedAction => { + if (selectedAction === reloadAction) { + vscode.commands.executeCommand( + 'workbench.action.reloadWindow', + ); + } + }); + } } } diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts index 2fe45f1ed..5ace1d0fa 100644 --- a/editors/code/src/server.ts +++ b/editors/code/src/server.ts @@ -59,6 +59,7 @@ export class Server { useClientWatching: Server.config.useClientWatching, featureFlags: Server.config.featureFlags, withSysroot: Server.config.withSysroot, + cargoFeatures: Server.config.cargoFeatures, }, traceOutputChannel, }; -- cgit v1.2.3 From f56a2a079069edafd74ef92b7e545f18be88b243 Mon Sep 17 00:00:00 2001 From: oxalica Date: Sat, 14 Dec 2019 00:48:47 +0800 Subject: Enable `allFeatures` by default and fix lints --- editors/code/package.json | 2 +- editors/code/src/config.ts | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) (limited to 'editors/code') diff --git a/editors/code/package.json b/editors/code/package.json index 8ed95fda7..e3bb07be7 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -286,7 +286,7 @@ }, "rust-analyzer.cargoFeatures.allFeatures": { "type": "boolean", - "default": false, + "default": true, "description": "Activate all available features" }, "rust-analyzer.cargoFeatures.features": { diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 6d709f7a8..defdfeb9c 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -43,7 +43,7 @@ export class Config { }; public cargoFeatures: CargoFeatures = { noDefaultFeatures: false, - allFeatures: false, + allFeatures: true, features: [], }; @@ -88,7 +88,8 @@ export class Config { } if (this.prevEnhancedTyping !== this.enableEnhancedTyping) { - requireReloadMessage = 'Changing enhanced typing setting requires a reload'; + requireReloadMessage = + 'Changing enhanced typing setting requires a reload'; this.prevEnhancedTyping = this.enableEnhancedTyping; } @@ -165,7 +166,7 @@ export class Config { if (config.has('cargoFeatures.allFeatures')) { this.cargoFeatures.allFeatures = config.get( 'cargoFeatures.allFeatures', - false, + true, ); } if (config.has('cargoFeatures.features')) { @@ -175,12 +176,18 @@ export class Config { ); } - if (this.prevCargoFeatures !== null && ( - this.cargoFeatures.allFeatures !== this.prevCargoFeatures.allFeatures || - this.cargoFeatures.noDefaultFeatures !== this.prevCargoFeatures.noDefaultFeatures || - this.cargoFeatures.features.length !== this.prevCargoFeatures.features.length || - this.cargoFeatures.features.some((v, i) => v !== this.prevCargoFeatures!.features[i]) - )) { + if ( + this.prevCargoFeatures !== null && + (this.cargoFeatures.allFeatures !== + this.prevCargoFeatures.allFeatures || + this.cargoFeatures.noDefaultFeatures !== + this.prevCargoFeatures.noDefaultFeatures || + this.cargoFeatures.features.length !== + this.prevCargoFeatures.features.length || + this.cargoFeatures.features.some( + (v, i) => v !== this.prevCargoFeatures!.features[i], + )) + ) { requireReloadMessage = 'Changing cargo features requires a reload'; } this.prevCargoFeatures = { ...this.cargoFeatures }; -- cgit v1.2.3