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