X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=editors%2Fcode%2Fsrc%2Fconfig.ts;h=e8abf8284eb7380c8f641f369c5c006fcba8c776;hb=5dab5e737909532e4a65390541393af6ee72f65b;hp=16ac50a0a8218fbb62adc55b4870458ce413c36d;hpb=65e2d8a0c805431ea8cef0e947a9dfff1c0c78f8;p=rust.git diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 16ac50a0a82..e8abf8284eb 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -8,28 +8,26 @@ export const NIGHTLY_TAG = "nightly"; export class Config { readonly extensionId = "matklad.rust-analyzer"; - private readonly rootSection = "rust-analyzer"; + readonly rootSection = "rust-analyzer"; private readonly requiresReloadOpts = [ "serverPath", - "cargoFeatures", - "cargo-watch", - "highlighting.semanticTokens", - "inlayHints", + "cargo", + "procMacro", + "files", + "highlighting", "updates.channel", + "lens.enable", + "lens.run", + "lens.debug", + "lens.implementations", ] .map(opt => `${this.rootSection}.${opt}`); - readonly packageJsonVersion: string = vscode - .extensions - .getExtension(this.extensionId)! - .packageJSON - .version; - - readonly releaseTag: string | undefined = vscode - .extensions - .getExtension(this.extensionId)! - .packageJSON - .releaseTag ?? undefined; + readonly package: { + version: string; + releaseTag: string | null; + enableProposedApi: boolean | undefined; + } = vscode.extensions.getExtension(this.extensionId)!.packageJSON; readonly globalStoragePath: string; @@ -42,7 +40,7 @@ export class Config { private refreshLogging() { log.setEnabled(this.traceExtension); log.debug( - "Extension version:", this.packageJsonVersion, + "Extension version:", this.package.version, "using configuration:", this.cfg ); } @@ -73,46 +71,65 @@ export class Config { return vscode.workspace.getConfiguration(this.rootSection); } - get serverPath() { return this.cfg.get("serverPath")!; } - get channel() { return this.cfg.get("updates.channel")!; } - get askBeforeDownload() { return this.cfg.get("updates.askBeforeDownload")!; } - get highlightingSemanticTokens() { return this.cfg.get("highlighting.semanticTokens")!; } - get highlightingOn() { return this.cfg.get("highlightingOn")!; } - get rainbowHighlightingOn() { return this.cfg.get("rainbowHighlightingOn")!; } - get lruCapacity() { return this.cfg.get("lruCapacity")!; } - get excludeGlobs() { return this.cfg.get("excludeGlobs")!; } - get useClientWatching() { return this.cfg.get("useClientWatching")!; } - get featureFlags() { return this.cfg.get>("featureFlags")!; } - get rustfmtArgs() { return this.cfg.get("rustfmtArgs")!; } - get loadOutDirsFromCheck() { return this.cfg.get("loadOutDirsFromCheck")!; } - get traceExtension() { return this.cfg.get("trace.extension")!; } - - // for internal use - get withSysroot() { return this.cfg.get("withSysroot", true)!; } + /** + * Beware that postfix `!` operator erases both `null` and `undefined`. + * This is why the following doesn't work as expected: + * + * ```ts + * const nullableNum = vscode + * .workspace + * .getConfiguration + * .getConfiguration("rust-analyer") + * .get(path)!; + * + * // What happens is that type of `nullableNum` is `number` but not `null | number`: + * const fullFledgedNum: number = nullableNum; + * ``` + * So this getter handles this quirk by not requiring the caller to use postfix `!` + */ + private get(path: string): T { + return this.cfg.get(path)!; + } + + get serverPath() { return this.get("serverPath"); } + get channel() { return this.get("updates.channel"); } + get askBeforeDownload() { return this.get("updates.askBeforeDownload"); } + get traceExtension() { return this.get("trace.extension"); } get inlayHints() { return { - typeHints: this.cfg.get("inlayHints.typeHints")!, - parameterHints: this.cfg.get("inlayHints.parameterHints")!, - maxLength: this.cfg.get("inlayHints.maxLength")!, + enable: this.get("inlayHints.enable"), + typeHints: this.get("inlayHints.typeHints"), + parameterHints: this.get("inlayHints.parameterHints"), + chainingHints: this.get("inlayHints.chainingHints"), + maxLength: this.get("inlayHints.maxLength"), + }; + } + + get checkOnSave() { + return { + command: this.get("checkOnSave.command"), }; } - get cargoWatchOptions() { + get debug() { + // "/rustc/" used by suggestions only. + const { ["/rustc/"]: _, ...sourceFileMap } = this.get>("debug.sourceFileMap"); + return { - enable: this.cfg.get("cargo-watch.enable")!, - arguments: this.cfg.get("cargo-watch.arguments")!, - allTargets: this.cfg.get("cargo-watch.allTargets")!, - command: this.cfg.get("cargo-watch.command")!, + engine: this.get("debug.engine"), + engineSettings: this.get("debug.engineSettings"), + openUpDebugPane: this.get("debug.openUpDebugPane"), + sourceFileMap: sourceFileMap }; } - get cargoFeatures() { + get lens() { return { - noDefaultFeatures: this.cfg.get("cargoFeatures.noDefaultFeatures")!, - allFeatures: this.cfg.get("cargoFeatures.allFeatures")!, - features: this.cfg.get("cargoFeatures.features")!, - loadOutDirsFromCheck: this.cfg.get("cargoFeatures.loadOutDirsFromCheck")!, + enable: this.get("lens.enable"), + run: this.get("lens.run"), + debug: this.get("lens.debug"), + implementations: this.get("lens.implementations"), }; } }