2018-10-07 15:59:02 -05:00
|
|
|
import * as vscode from 'vscode';
|
|
|
|
|
2019-01-18 04:59:08 -06:00
|
|
|
const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
|
|
|
|
|
2019-12-25 13:23:44 -06:00
|
|
|
export interface CargoWatchOptions {
|
|
|
|
enable: boolean;
|
2019-12-25 09:50:38 -06:00
|
|
|
arguments: string[];
|
2019-12-25 13:23:44 -06:00
|
|
|
command: string;
|
|
|
|
allTargets: boolean;
|
2019-04-02 01:43:02 -05:00
|
|
|
}
|
2019-03-21 06:56:25 -05:00
|
|
|
|
2019-12-13 04:16:34 -06:00
|
|
|
export interface CargoFeatures {
|
|
|
|
noDefaultFeatures: boolean;
|
|
|
|
allFeatures: boolean;
|
|
|
|
features: string[];
|
|
|
|
}
|
|
|
|
|
2018-10-07 15:59:02 -05:00
|
|
|
export class Config {
|
2019-12-31 10:28:27 -06:00
|
|
|
highlightingOn = true;
|
|
|
|
rainbowHighlightingOn = false;
|
|
|
|
enableEnhancedTyping = true;
|
|
|
|
raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server';
|
|
|
|
lruCapacity: null | number = null;
|
|
|
|
displayInlayHints = true;
|
|
|
|
maxInlayHintLength: null | number = null;
|
|
|
|
excludeGlobs = [];
|
|
|
|
useClientWatching = true;
|
|
|
|
featureFlags = {};
|
2019-12-09 11:05:49 -06:00
|
|
|
// for internal use
|
2019-12-31 10:28:27 -06:00
|
|
|
withSysroot: null | boolean = null;
|
|
|
|
cargoWatchOptions: CargoWatchOptions = {
|
2019-12-25 13:23:44 -06:00
|
|
|
enable: true,
|
2019-12-25 09:50:38 -06:00
|
|
|
arguments: [],
|
2019-12-25 13:23:44 -06:00
|
|
|
command: '',
|
|
|
|
allTargets: true,
|
2019-04-02 01:43:02 -05:00
|
|
|
};
|
2019-12-31 10:28:27 -06:00
|
|
|
cargoFeatures: CargoFeatures = {
|
2019-12-13 04:16:34 -06:00
|
|
|
noDefaultFeatures: false,
|
2019-12-13 10:48:47 -06:00
|
|
|
allFeatures: true,
|
2019-12-13 04:16:34 -06:00
|
|
|
features: [],
|
|
|
|
};
|
2018-10-07 15:59:02 -05:00
|
|
|
|
2019-02-07 04:37:36 -06:00
|
|
|
private prevEnhancedTyping: null | boolean = null;
|
2019-12-13 04:16:34 -06:00
|
|
|
private prevCargoFeatures: null | CargoFeatures = null;
|
2019-02-07 04:37:36 -06:00
|
|
|
|
2019-12-31 10:34:52 -06:00
|
|
|
constructor(ctx: vscode.ExtensionContext) {
|
|
|
|
vscode.workspace.onDidChangeConfiguration(_ => this.refresh(), ctx.subscriptions);
|
|
|
|
this.refresh();
|
2018-10-08 16:36:47 -05:00
|
|
|
}
|
2018-10-07 15:59:02 -05:00
|
|
|
|
2019-12-31 10:34:52 -06:00
|
|
|
private refresh() {
|
2019-01-28 05:43:07 -06:00
|
|
|
const config = vscode.workspace.getConfiguration('rust-analyzer');
|
2019-11-09 10:23:30 -06:00
|
|
|
|
2019-12-13 04:16:34 -06:00
|
|
|
let requireReloadMessage = null;
|
|
|
|
|
2018-10-08 16:38:33 -05:00
|
|
|
if (config.has('highlightingOn')) {
|
|
|
|
this.highlightingOn = config.get('highlightingOn') as boolean;
|
|
|
|
}
|
|
|
|
|
2019-05-27 04:26:15 -05:00
|
|
|
if (config.has('rainbowHighlightingOn')) {
|
|
|
|
this.rainbowHighlightingOn = config.get(
|
2019-12-09 12:57:55 -06:00
|
|
|
'rainbowHighlightingOn',
|
2019-05-27 04:26:15 -05:00
|
|
|
) as boolean;
|
|
|
|
}
|
|
|
|
|
2019-02-07 04:37:36 -06:00
|
|
|
if (config.has('enableEnhancedTyping')) {
|
2019-02-07 04:54:41 -06:00
|
|
|
this.enableEnhancedTyping = config.get(
|
2019-12-09 12:57:55 -06:00
|
|
|
'enableEnhancedTyping',
|
2019-02-07 04:54:41 -06:00
|
|
|
) as boolean;
|
2019-02-07 04:37:36 -06:00
|
|
|
|
|
|
|
if (this.prevEnhancedTyping === null) {
|
|
|
|
this.prevEnhancedTyping = this.enableEnhancedTyping;
|
|
|
|
}
|
|
|
|
} else if (this.prevEnhancedTyping === null) {
|
|
|
|
this.prevEnhancedTyping = this.enableEnhancedTyping;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.prevEnhancedTyping !== this.enableEnhancedTyping) {
|
2019-12-13 10:48:47 -06:00
|
|
|
requireReloadMessage =
|
|
|
|
'Changing enhanced typing setting requires a reload';
|
2019-02-07 04:37:36 -06:00
|
|
|
this.prevEnhancedTyping = this.enableEnhancedTyping;
|
|
|
|
}
|
|
|
|
|
2019-01-05 09:28:41 -06:00
|
|
|
if (config.has('raLspServerPath')) {
|
2019-01-18 04:59:08 -06:00
|
|
|
this.raLspServerPath =
|
|
|
|
RA_LSP_DEBUG || (config.get('raLspServerPath') as string);
|
2019-01-05 09:28:41 -06:00
|
|
|
}
|
2019-03-18 16:35:47 -05:00
|
|
|
|
2019-12-25 13:23:44 -06:00
|
|
|
if (config.has('cargo-watch.enable')) {
|
|
|
|
this.cargoWatchOptions.enable = config.get<boolean>(
|
|
|
|
'cargo-watch.enable',
|
2019-12-25 09:50:38 -06:00
|
|
|
true,
|
2019-04-02 01:43:02 -05:00
|
|
|
);
|
|
|
|
}
|
2019-04-02 00:07:40 -05:00
|
|
|
|
2019-06-24 05:50:34 -05:00
|
|
|
if (config.has('cargo-watch.arguments')) {
|
2019-12-25 13:23:44 -06:00
|
|
|
this.cargoWatchOptions.arguments = config.get<string[]>(
|
2019-06-24 05:50:34 -05:00
|
|
|
'cargo-watch.arguments',
|
2019-12-25 09:50:38 -06:00
|
|
|
[],
|
2019-04-02 01:43:02 -05:00
|
|
|
);
|
2019-03-18 16:35:47 -05:00
|
|
|
}
|
2019-06-24 05:02:20 -05:00
|
|
|
|
2019-06-24 05:50:34 -05:00
|
|
|
if (config.has('cargo-watch.command')) {
|
2019-12-25 13:23:44 -06:00
|
|
|
this.cargoWatchOptions.command = config.get<string>(
|
2019-06-24 05:50:34 -05:00
|
|
|
'cargo-watch.command',
|
2019-12-09 12:57:55 -06:00
|
|
|
'',
|
2019-06-24 05:02:20 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-12-25 13:23:44 -06:00
|
|
|
if (config.has('cargo-watch.allTargets')) {
|
|
|
|
this.cargoWatchOptions.allTargets = config.get<boolean>(
|
|
|
|
'cargo-watch.allTargets',
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-07 12:49:29 -05:00
|
|
|
if (config.has('lruCapacity')) {
|
|
|
|
this.lruCapacity = config.get('lruCapacity') as number;
|
|
|
|
}
|
2019-07-23 08:38:21 -05:00
|
|
|
|
|
|
|
if (config.has('displayInlayHints')) {
|
|
|
|
this.displayInlayHints = config.get('displayInlayHints') as boolean;
|
|
|
|
}
|
2019-10-18 06:40:03 -05:00
|
|
|
if (config.has('maxInlayHintLength')) {
|
|
|
|
this.maxInlayHintLength = config.get(
|
2019-12-09 12:57:55 -06:00
|
|
|
'maxInlayHintLength',
|
2019-10-18 06:40:03 -05:00
|
|
|
) as number;
|
|
|
|
}
|
2019-08-06 06:34:28 -05:00
|
|
|
if (config.has('excludeGlobs')) {
|
|
|
|
this.excludeGlobs = config.get('excludeGlobs') || [];
|
|
|
|
}
|
2019-09-06 08:25:24 -05:00
|
|
|
if (config.has('useClientWatching')) {
|
2019-12-17 05:41:44 -06:00
|
|
|
this.useClientWatching = config.get('useClientWatching') || true;
|
2019-09-06 08:25:24 -05:00
|
|
|
}
|
2019-08-22 06:44:16 -05:00
|
|
|
if (config.has('featureFlags')) {
|
|
|
|
this.featureFlags = config.get('featureFlags') || {};
|
|
|
|
}
|
2019-12-09 11:05:49 -06:00
|
|
|
if (config.has('withSysroot')) {
|
|
|
|
this.withSysroot = config.get('withSysroot') || false;
|
|
|
|
}
|
2019-12-13 04:16:34 -06:00
|
|
|
|
|
|
|
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',
|
2019-12-13 10:48:47 -06:00
|
|
|
true,
|
2019-12-13 04:16:34 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if (config.has('cargoFeatures.features')) {
|
|
|
|
this.cargoFeatures.features = config.get(
|
|
|
|
'cargoFeatures.features',
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-12-13 10:48:47 -06:00
|
|
|
if (
|
|
|
|
this.prevCargoFeatures !== null &&
|
|
|
|
(this.cargoFeatures.allFeatures !==
|
|
|
|
this.prevCargoFeatures.allFeatures ||
|
|
|
|
this.cargoFeatures.noDefaultFeatures !==
|
2019-12-30 16:30:35 -06:00
|
|
|
this.prevCargoFeatures.noDefaultFeatures ||
|
2019-12-13 10:48:47 -06:00
|
|
|
this.cargoFeatures.features.length !==
|
2019-12-30 16:30:35 -06:00
|
|
|
this.prevCargoFeatures.features.length ||
|
2019-12-13 10:48:47 -06:00
|
|
|
this.cargoFeatures.features.some(
|
|
|
|
(v, i) => v !== this.prevCargoFeatures!.features[i],
|
|
|
|
))
|
|
|
|
) {
|
2019-12-13 04:16:34 -06:00
|
|
|
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',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-10-07 15:59:02 -05:00
|
|
|
}
|
|
|
|
}
|