From b89b22e43eb7e821674e0022f4061442b9e29394 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Wed, 5 Feb 2020 00:13:46 +0200 Subject: vscode: yet another refactor commit --- editors/code/src/client.ts | 29 ++++++++++++----------------- editors/code/src/color_theme.ts | 18 +++++++++--------- editors/code/src/commands/on_enter.ts | 2 +- editors/code/src/config.ts | 4 ++-- editors/code/src/highlighting.ts | 8 ++++---- editors/code/src/main.ts | 2 +- 6 files changed, 29 insertions(+), 34 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 1778c4e9f..7e7e909dd 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -7,25 +7,21 @@ import { Config } from './config'; export function createClient(config: Config): lc.LanguageClient { // '.' Is the fallback if no folder is open - // TODO?: Workspace folders support Uri's (eg: file://test.txt). It might be a good idea to test if the uri points to a file. - let folder: string = '.'; - if (workspace.workspaceFolders !== undefined) { - folder = workspace.workspaceFolders[0].uri.fsPath.toString(); - } + // TODO?: Workspace folders support Uri's (eg: file://test.txt). + // It might be a good idea to test if the uri points to a file. + const workspaceFolderPath = workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.'; - const command = expandPathResolving(config.raLspServerPath); - if (spawnSync(command, ["--version"]).status !== 0) { + const raLspServerPath = expandPathResolving(config.raLspServerPath); + if (spawnSync(raLspServerPath, ["--version"]).status !== 0) { window.showErrorMessage( - `Unable to execute '${command} --version' - -Perhaps it is not in $PATH? - -PATH=${process.env.PATH} -`); + `Unable to execute '${raLspServerPath} --version'\n\n` + + `Perhaps it is not in $PATH?\n\n` + + `PATH=${process.env.PATH}\n` + ); } const run: lc.Executable = { - command, - options: { cwd: folder }, + command: raLspServerPath, + options: { cwd: workspaceFolderPath }, }; const serverOptions: lc.ServerOptions = { run, @@ -43,8 +39,7 @@ PATH=${process.env.PATH} cargoWatchEnable: config.cargoWatchOptions.enable, cargoWatchArgs: config.cargoWatchOptions.arguments, cargoWatchCommand: config.cargoWatchOptions.command, - cargoWatchAllTargets: - config.cargoWatchOptions.allTargets, + cargoWatchAllTargets: config.cargoWatchOptions.allTargets, excludeGlobs: config.excludeGlobs, useClientWatching: config.useClientWatching, featureFlags: config.featureFlags, diff --git a/editors/code/src/color_theme.ts b/editors/code/src/color_theme.ts index 7e10c7f79..a6957a76e 100644 --- a/editors/code/src/color_theme.ts +++ b/editors/code/src/color_theme.ts @@ -33,6 +33,7 @@ export class ColorTheme { : typeof rule.scope === 'string' ? [rule.scope] : rule.scope; + for (const scope of scopes) { res.rules.set(scope, rule.settings); } @@ -69,13 +70,13 @@ function loadThemeNamed(themeName: string): ColorTheme { ); } - const themePaths = vscode.extensions.all + const themePaths: string[] = vscode.extensions.all .filter(isTheme) - .flatMap(ext => { - return ext.packageJSON.contributes.themes + .flatMap( + ext => ext.packageJSON.contributes.themes .filter((it: any) => (it.id || it.label) === themeName) - .map((it: any) => path.join(ext.extensionPath, it.path)); - }); + .map((it: any) => path.join(ext.extensionPath, it.path)) + ); const res = new ColorTheme(); for (const themePath of themePaths) { @@ -96,13 +97,12 @@ function loadThemeFile(themePath: string): ColorTheme { return new ColorTheme(); } const obj = jsonc.parse(text); - const tokenColors = obj?.tokenColors ?? []; + const tokenColors: TextMateRule[] = obj?.tokenColors ?? []; const res = ColorTheme.fromRules(tokenColors); - for (const include in obj?.include ?? []) { + for (const include of obj?.include ?? []) { const includePath = path.join(path.dirname(themePath), include); - const tmp = loadThemeFile(includePath); - res.mergeFrom(tmp); + res.mergeFrom(loadThemeFile(includePath)); } return res; diff --git a/editors/code/src/commands/on_enter.ts b/editors/code/src/commands/on_enter.ts index c636234da..25eaebcbe 100644 --- a/editors/code/src/commands/on_enter.ts +++ b/editors/code/src/commands/on_enter.ts @@ -7,7 +7,7 @@ import { Cmd, Ctx } from '../ctx'; async function handleKeypress(ctx: Ctx) { const editor = ctx.activeRustEditor; const client = ctx.client; - if (!editor) return false; + if (!editor || !client) return false; const request: lc.TextDocumentPositionParams = { diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index fc21c8813..c750b2d5c 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -23,9 +23,9 @@ export class Config { lruCapacity: null | number = null; displayInlayHints = true; maxInlayHintLength: null | number = null; - excludeGlobs = []; + excludeGlobs: string[] = []; useClientWatching = true; - featureFlags = {}; + featureFlags: Record = {}; // for internal use withSysroot: null | boolean = null; cargoWatchOptions: CargoWatchOptions = { diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index 66216e0fc..e90fb8acc 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts @@ -69,7 +69,7 @@ interface Decoration { // Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76 function fancify(seed: string, shade: 'light' | 'dark') { - const random = randomU32Numbers(hashString(seed)) + const random = randomU32Numbers(hashString(seed)); const randomInt = (min: number, max: number) => { return Math.abs(random()) % (max - min + 1) + min; }; @@ -253,14 +253,14 @@ function randomU32Numbers(seed: number) { random ^= random >> 17; random ^= random << 5; random |= 0; - return random - } + return random; + }; } function hashString(str: string): number { let res = 0; for (let i = 0; i < str.length; ++i) { - const c = str.codePointAt(i)!!; + const c = str.codePointAt(i)!; res = (res * 31 + c) & ~0; } return res; diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index efc31b2e2..5efce41f4 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -6,7 +6,7 @@ import { activateStatusDisplay } from './status_display'; import { Ctx } from './ctx'; import { activateHighlighting } from './highlighting'; -let ctx!: Ctx; +let ctx: Ctx | undefined; export async function activate(context: vscode.ExtensionContext) { ctx = new Ctx(context); -- cgit v1.2.3