2018-10-07 20:59:02 +00:00
|
|
|
import * as vscode from 'vscode';
|
2020-03-17 11:44:31 +00:00
|
|
|
import { log } from "./util";
|
2019-01-18 10:59:08 +00:00
|
|
|
|
2020-03-10 07:55:46 +00:00
|
|
|
export interface InlayHintOptions {
|
2020-03-12 03:14:39 +00:00
|
|
|
typeHints: boolean;
|
|
|
|
parameterHints: boolean;
|
2020-03-12 15:43:07 +00:00
|
|
|
maxLength: number | null;
|
2020-03-10 07:55:46 +00:00
|
|
|
}
|
|
|
|
|
2019-12-25 19:23:44 +00:00
|
|
|
export interface CargoWatchOptions {
|
|
|
|
enable: boolean;
|
2019-12-25 15:50:38 +00:00
|
|
|
arguments: string[];
|
2019-12-25 19:23:44 +00:00
|
|
|
command: string;
|
|
|
|
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[];
|
2020-03-16 12:43:29 +00:00
|
|
|
loadOutDirsFromCheck: boolean;
|
2019-12-13 10:16:34 +00:00
|
|
|
}
|
2020-03-09 17:57:13 +00:00
|
|
|
|
2020-03-17 11:44:31 +00:00
|
|
|
export type UpdatesChannel = "stable" | "nightly";
|
2020-03-09 17:57:13 +00:00
|
|
|
|
|
|
|
export const NIGHTLY_TAG = "nightly";
|
2018-10-07 20:59:02 +00:00
|
|
|
export class Config {
|
2020-03-09 17:57:13 +00:00
|
|
|
readonly extensionId = "matklad.rust-analyzer";
|
|
|
|
|
|
|
|
private readonly rootSection = "rust-analyzer";
|
|
|
|
private readonly requiresReloadOpts = [
|
2020-03-14 00:00:34 +00:00
|
|
|
"serverPath",
|
2020-02-13 20:48:20 +00:00
|
|
|
"cargoFeatures",
|
|
|
|
"cargo-watch",
|
2020-03-10 18:21:56 +00:00
|
|
|
"highlighting.semanticTokens",
|
2020-03-12 03:14:39 +00:00
|
|
|
"inlayHints",
|
2020-03-17 11:44:31 +00:00
|
|
|
"updates.channel",
|
2020-02-13 20:48:20 +00:00
|
|
|
]
|
2020-03-09 17:57:13 +00:00
|
|
|
.map(opt => `${this.rootSection}.${opt}`);
|
2020-02-13 20:48:20 +00:00
|
|
|
|
2020-03-19 08:32:57 +00:00
|
|
|
readonly packageJsonVersion: string = vscode
|
2020-03-14 01:01:14 +00:00
|
|
|
.extensions
|
|
|
|
.getExtension(this.extensionId)!
|
|
|
|
.packageJSON
|
2020-03-19 08:32:57 +00:00
|
|
|
.version;
|
2020-03-14 01:01:14 +00:00
|
|
|
|
2020-03-20 11:50:50 +00:00
|
|
|
readonly releaseTag: string | undefined = vscode
|
2020-03-19 08:32:57 +00:00
|
|
|
.extensions
|
|
|
|
.getExtension(this.extensionId)!
|
|
|
|
.packageJSON
|
2020-03-20 11:50:50 +00:00
|
|
|
.releaseTag ?? undefined;
|
2020-02-16 01:08:36 +00:00
|
|
|
|
2020-02-13 20:48:20 +00:00
|
|
|
private cfg!: vscode.WorkspaceConfiguration;
|
|
|
|
|
2020-02-13 21:05:32 +00:00
|
|
|
constructor(private readonly ctx: vscode.ExtensionContext) {
|
|
|
|
vscode.workspace.onDidChangeConfiguration(this.onConfigChange, this, ctx.subscriptions);
|
|
|
|
this.refreshConfig();
|
|
|
|
}
|
|
|
|
|
2020-02-13 20:48:20 +00:00
|
|
|
private refreshConfig() {
|
2020-03-09 17:57:13 +00:00
|
|
|
this.cfg = vscode.workspace.getConfiguration(this.rootSection);
|
2020-02-21 14:59:46 +00:00
|
|
|
const enableLogging = this.cfg.get("trace.extension") as boolean;
|
|
|
|
log.setEnabled(enableLogging);
|
2020-03-14 01:01:14 +00:00
|
|
|
log.debug(
|
|
|
|
"Extension version:", this.packageJsonVersion,
|
|
|
|
"using configuration:", this.cfg
|
|
|
|
);
|
2020-02-13 20:48:20 +00:00
|
|
|
}
|
2020-02-08 02:22:44 +00:00
|
|
|
|
2020-02-14 21:06:11 +00:00
|
|
|
private async onConfigChange(event: vscode.ConfigurationChangeEvent) {
|
2020-02-13 20:48:20 +00:00
|
|
|
this.refreshConfig();
|
|
|
|
|
2020-03-09 17:57:13 +00:00
|
|
|
const requiresReloadOpt = this.requiresReloadOpts.find(
|
2020-02-13 20:48:20 +00:00
|
|
|
opt => event.affectsConfiguration(opt)
|
|
|
|
);
|
2018-10-07 20:59:02 +00:00
|
|
|
|
2020-02-13 20:48:20 +00:00
|
|
|
if (!requiresReloadOpt) return;
|
2019-02-07 10:37:36 +00:00
|
|
|
|
2020-02-13 20:48:20 +00:00
|
|
|
const userResponse = await vscode.window.showInformationMessage(
|
|
|
|
`Changing "${requiresReloadOpt}" requires a reload`,
|
|
|
|
"Reload now"
|
|
|
|
);
|
|
|
|
|
|
|
|
if (userResponse === "Reload now") {
|
2020-03-17 11:44:31 +00:00
|
|
|
await vscode.commands.executeCommand("workbench.action.reloadWindow");
|
2020-02-08 22:27:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-17 11:44:31 +00:00
|
|
|
get globalStoragePath(): string { return this.ctx.globalStoragePath; }
|
2020-03-09 17:57:13 +00:00
|
|
|
|
2020-02-13 20:48:20 +00:00
|
|
|
// We don't do runtime config validation here for simplicity. More on stackoverflow:
|
|
|
|
// https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension
|
2020-02-08 22:27:04 +00:00
|
|
|
|
2020-03-17 11:44:31 +00:00
|
|
|
get serverPath() { return this.cfg.get("serverPath") as null | string; }
|
|
|
|
get channel() { return this.cfg.get<"stable" | "nightly">("updates.channel")!; }
|
2020-03-09 17:57:13 +00:00
|
|
|
get askBeforeDownload() { return this.cfg.get("updates.askBeforeDownload") as boolean; }
|
2020-02-26 15:03:30 +00:00
|
|
|
get highlightingSemanticTokens() { return this.cfg.get("highlighting.semanticTokens") as boolean; }
|
2020-02-17 22:42:25 +00:00
|
|
|
get highlightingOn() { return this.cfg.get("highlightingOn") as boolean; }
|
2020-02-14 21:04:50 +00:00
|
|
|
get rainbowHighlightingOn() { return this.cfg.get("rainbowHighlightingOn") as boolean; }
|
2020-02-17 22:42:25 +00:00
|
|
|
get lruCapacity() { return this.cfg.get("lruCapacity") as null | number; }
|
2020-03-12 03:14:39 +00:00
|
|
|
get inlayHints(): InlayHintOptions {
|
2020-03-10 07:55:46 +00:00
|
|
|
return {
|
2020-03-12 03:14:39 +00:00
|
|
|
typeHints: this.cfg.get("inlayHints.typeHints") as boolean,
|
|
|
|
parameterHints: this.cfg.get("inlayHints.parameterHints") as boolean,
|
2020-03-12 15:43:07 +00:00
|
|
|
maxLength: this.cfg.get("inlayHints.maxLength") as null | number,
|
2020-03-10 07:55:46 +00:00
|
|
|
};
|
|
|
|
}
|
2020-02-17 22:42:25 +00:00
|
|
|
get excludeGlobs() { return this.cfg.get("excludeGlobs") as string[]; }
|
|
|
|
get useClientWatching() { return this.cfg.get("useClientWatching") as boolean; }
|
|
|
|
get featureFlags() { return this.cfg.get("featureFlags") as Record<string, boolean>; }
|
|
|
|
get rustfmtArgs() { return this.cfg.get("rustfmtArgs") as string[]; }
|
2020-03-16 12:43:29 +00:00
|
|
|
get loadOutDirsFromCheck() { return this.cfg.get("loadOutDirsFromCheck") as boolean; }
|
2020-02-17 22:42:25 +00:00
|
|
|
|
2020-02-14 21:04:50 +00:00
|
|
|
get cargoWatchOptions(): CargoWatchOptions {
|
2020-02-13 20:48:20 +00:00
|
|
|
return {
|
2020-02-17 22:42:25 +00:00
|
|
|
enable: this.cfg.get("cargo-watch.enable") as boolean,
|
|
|
|
arguments: this.cfg.get("cargo-watch.arguments") as string[],
|
2020-02-13 20:48:20 +00:00
|
|
|
allTargets: this.cfg.get("cargo-watch.allTargets") as boolean,
|
2020-02-17 22:42:25 +00:00
|
|
|
command: this.cfg.get("cargo-watch.command") as string,
|
2020-02-13 20:48:20 +00:00
|
|
|
};
|
|
|
|
}
|
2019-12-13 10:16:34 +00:00
|
|
|
|
2020-02-14 21:04:50 +00:00
|
|
|
get cargoFeatures(): CargoFeatures {
|
2020-02-13 20:48:20 +00:00
|
|
|
return {
|
|
|
|
noDefaultFeatures: this.cfg.get("cargoFeatures.noDefaultFeatures") as boolean,
|
2020-02-17 22:42:25 +00:00
|
|
|
allFeatures: this.cfg.get("cargoFeatures.allFeatures") as boolean,
|
|
|
|
features: this.cfg.get("cargoFeatures.features") as string[],
|
2020-03-16 12:43:29 +00:00
|
|
|
loadOutDirsFromCheck: this.cfg.get("cargoFeatures.loadOutDirsFromCheck") as boolean,
|
2020-02-13 20:48:20 +00:00
|
|
|
};
|
2018-10-07 20:59:02 +00:00
|
|
|
}
|
2020-02-13 20:48:20 +00:00
|
|
|
|
|
|
|
// for internal use
|
2020-02-16 09:15:19 +00:00
|
|
|
get withSysroot() { return this.cfg.get("withSysroot", true) as boolean; }
|
2018-10-07 20:59:02 +00:00
|
|
|
}
|