From 4fb427743c27c63a4aa3ccd54c488b22d4308bc2 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Fri, 14 Feb 2020 23:04:50 +0200 Subject: vscode: moved to getters as per matklad --- editors/code/src/client.ts | 18 ++++++++--------- editors/code/src/config.ts | 40 ++++++++++++++++---------------------- editors/code/src/highlighting.ts | 6 +++--- editors/code/src/inlay_hints.ts | 6 +++--- editors/code/src/status_display.ts | 2 +- 5 files changed, 33 insertions(+), 39 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index a6fb04536..4484b2167 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -10,7 +10,7 @@ export async function createClient(config: Config): Promise("raLspServerPath"); if (langServerPath) { @@ -111,9 +108,7 @@ export class Config { }; } - const prebuiltBinaryName = Config.prebuiltLangServerFileName( - process.platform, process.arch - ); + const prebuiltBinaryName = this.prebuiltLangServerFileName; if (!prebuiltBinaryName) return null; @@ -131,17 +126,16 @@ export class Config { // 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 - // FIXME: add codegen for primitive configurations - highlightingOn() { return this.cfg.get("highlightingOn") as boolean; } - rainbowHighlightingOn() { return this.cfg.get("rainbowHighlightingOn") as boolean; } - lruCapacity() { return this.cfg.get("lruCapacity") as null | number; } - displayInlayHints() { return this.cfg.get("displayInlayHints") as boolean; } - maxInlayHintLength() { return this.cfg.get("maxInlayHintLength") as number; } - excludeGlobs() { return this.cfg.get("excludeGlobs") as string[]; } - useClientWatching() { return this.cfg.get("useClientWatching") as boolean; } - featureFlags() { return this.cfg.get("featureFlags") as Record; } - - cargoWatchOptions(): CargoWatchOptions { + get highlightingOn() { return this.cfg.get("highlightingOn") as boolean; } + get rainbowHighlightingOn() { return this.cfg.get("rainbowHighlightingOn") as boolean; } + get lruCapacity() { return this.cfg.get("lruCapacity") as null | number; } + get displayInlayHints() { return this.cfg.get("displayInlayHints") as boolean; } + get maxInlayHintLength() { return this.cfg.get("maxInlayHintLength") as number; } + 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; } + + get cargoWatchOptions(): CargoWatchOptions { return { enable: this.cfg.get("cargo-watch.enable") as boolean, arguments: this.cfg.get("cargo-watch.arguments") as string[], @@ -150,7 +144,7 @@ export class Config { }; } - cargoFeatures(): CargoFeatures { + get cargoFeatures(): CargoFeatures { return { noDefaultFeatures: this.cfg.get("cargoFeatures.noDefaultFeatures") as boolean, allFeatures: this.cfg.get("cargoFeatures.allFeatures") as boolean, @@ -159,5 +153,5 @@ export class Config { } // for internal use - withSysroot() { return this.cfg.get("withSysroot", false); } + get withSysroot() { return this.cfg.get("withSysroot", false); } } diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index e2ae31d29..4fbbe3ddc 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts @@ -11,7 +11,7 @@ export function activateHighlighting(ctx: Ctx) { client.onNotification( 'rust-analyzer/publishDecorations', (params: PublishDecorationsParams) => { - if (!ctx.config.highlightingOn()) return; + if (!ctx.config.highlightingOn) return; const targetEditor = vscode.window.visibleTextEditors.find( editor => { @@ -39,7 +39,7 @@ export function activateHighlighting(ctx: Ctx) { vscode.window.onDidChangeActiveTextEditor( async (editor: vscode.TextEditor | undefined) => { if (!editor || editor.document.languageId !== 'rust') return; - if (!ctx.config.highlightingOn()) return; + if (!ctx.config.highlightingOn) return; const client = ctx.client; if (!client) return; @@ -122,7 +122,7 @@ class Highlighter { string, [vscode.Range[], boolean] > = new Map(); - const rainbowTime = this.ctx.config.rainbowHighlightingOn(); + const rainbowTime = this.ctx.config.rainbowHighlightingOn; for (const tag of this.decorations.keys()) { byTag.set(tag, []); diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index 3ff45a625..1c019a51b 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts @@ -22,12 +22,12 @@ export function activateInlayHints(ctx: Ctx) { ); vscode.workspace.onDidChangeConfiguration( - async _ => hintsUpdater.setEnabled(ctx.config.displayInlayHints()), + async _ => hintsUpdater.setEnabled(ctx.config.displayInlayHints), null, ctx.subscriptions ); - ctx.onDidRestart(_ => hintsUpdater.setEnabled(ctx.config.displayInlayHints())); + ctx.onDidRestart(_ => hintsUpdater.setEnabled(ctx.config.displayInlayHints)); } interface InlayHintsParams { @@ -59,7 +59,7 @@ class HintsUpdater { constructor(ctx: Ctx) { this.ctx = ctx; - this.enabled = ctx.config.displayInlayHints(); + this.enabled = ctx.config.displayInlayHints; } async setEnabled(enabled: boolean) { diff --git a/editors/code/src/status_display.ts b/editors/code/src/status_display.ts index ae9a7b1b5..993e79d70 100644 --- a/editors/code/src/status_display.ts +++ b/editors/code/src/status_display.ts @@ -7,7 +7,7 @@ import { Ctx } from './ctx'; const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; export function activateStatusDisplay(ctx: Ctx) { - const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions().command); + const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command); ctx.pushCleanup(statusDisplay); ctx.onDidRestart(client => ctx.pushCleanup(client.onProgress( WorkDoneProgress.type, -- cgit v1.2.3