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/config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'editors/code/src/config.ts') 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 = { -- cgit v1.2.3 From 8153b60e1d8abdcefbf6c7c9657f1ce65a216d7a Mon Sep 17 00:00:00 2001 From: Veetaha Date: Wed, 5 Feb 2020 22:39:47 +0200 Subject: vscode: eliminate floating promises and insane amount of resource handle leaks --- editors/code/src/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors/code/src/config.ts') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index fc21c8813..585229ed0 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -45,7 +45,7 @@ export class Config { private prevCargoWatchOptions: null | CargoWatchOptions = null; constructor(ctx: vscode.ExtensionContext) { - vscode.workspace.onDidChangeConfiguration(_ => this.refresh(), ctx.subscriptions); + vscode.workspace.onDidChangeConfiguration(_ => this.refresh(), null, ctx.subscriptions); this.refresh(); } -- cgit v1.2.3 From 5d88c1db38200896d2e4af7836fec95097adf509 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sat, 8 Feb 2020 04:22:44 +0200 Subject: vscode: amended config to use binary from globalStoragePath, added ui for downloading --- editors/code/src/config.ts | 56 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 7 deletions(-) (limited to 'editors/code/src/config.ts') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 524620433..aca5dab5a 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -1,4 +1,6 @@ +import * as os from "os"; import * as vscode from 'vscode'; +import { BinarySource, BinarySourceType } from "./installation/interfaces"; const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; @@ -16,10 +18,24 @@ export interface CargoFeatures { } export class Config { + readonly raLspServerGithubArtifactName = { + linux: "ra_lsp_server-linux", + darwin: "ra_lsp_server-mac", + win32: "ra_lsp_server-windows.exe", + aix: null, + android: null, + freebsd: null, + openbsd: null, + sunos: null, + cygwin: null, + netbsd: null, + }[process.platform]; + + raLspServerSource!: null | BinarySource; + highlightingOn = true; rainbowHighlightingOn = false; enableEnhancedTyping = true; - raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server'; lruCapacity: null | number = null; displayInlayHints = true; maxInlayHintLength: null | number = null; @@ -45,11 +61,20 @@ export class Config { private prevCargoWatchOptions: null | CargoWatchOptions = null; constructor(ctx: vscode.ExtensionContext) { - vscode.workspace.onDidChangeConfiguration(_ => this.refresh(), null, ctx.subscriptions); - this.refresh(); + vscode.workspace.onDidChangeConfiguration(_ => this.refresh(ctx), null, ctx.subscriptions); + this.refresh(ctx); + } + + private static expandPathResolving(path: string) { + if (path.startsWith('~/')) { + return path.replace('~', os.homedir()); + } + return path; } - private refresh() { + // FIXME: revisit the logic for `if (.has(...)) config.get(...)` set default + // values only in one place (i.e. remove default values from non-readonly members declarations) + private refresh(ctx: vscode.ExtensionContext) { const config = vscode.workspace.getConfiguration('rust-analyzer'); let requireReloadMessage = null; @@ -82,9 +107,26 @@ export class Config { this.prevEnhancedTyping = this.enableEnhancedTyping; } - if (config.has('raLspServerPath')) { - this.raLspServerPath = - RA_LSP_DEBUG || (config.get('raLspServerPath') as string); + { + const raLspServerPath = RA_LSP_DEBUG ?? config.get("raLspServerPath"); + if (raLspServerPath) { + this.raLspServerSource = { + type: BinarySourceType.ExplicitPath, + path: Config.expandPathResolving(raLspServerPath) + }; + } else if (this.raLspServerGithubArtifactName) { + this.raLspServerSource = { + type: BinarySourceType.GithubBinary, + dir: ctx.globalStoragePath, + file: this.raLspServerGithubArtifactName, + repo: { + name: "rust-analyzer", + owner: "rust-analyzer", + } + }; + } else { + this.raLspServerSource = null; + } } if (config.has('cargo-watch.enable')) { -- cgit v1.2.3 From 539daf4454e3f11424a469e8fba26cacb325176a Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 9 Feb 2020 00:27:04 +0200 Subject: vscode: refactor platform artifact name query to switch statement, move BinarySource union variants into a namespace --- editors/code/src/config.ts | 89 +++++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 36 deletions(-) (limited to 'editors/code/src/config.ts') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index aca5dab5a..f216ab461 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -1,6 +1,6 @@ import * as os from "os"; import * as vscode from 'vscode'; -import { BinarySource, BinarySourceType } from "./installation/interfaces"; +import { BinarySource } from "./installation/interfaces"; const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; @@ -18,20 +18,7 @@ export interface CargoFeatures { } export class Config { - readonly raLspServerGithubArtifactName = { - linux: "ra_lsp_server-linux", - darwin: "ra_lsp_server-mac", - win32: "ra_lsp_server-windows.exe", - aix: null, - android: null, - freebsd: null, - openbsd: null, - sunos: null, - cygwin: null, - netbsd: null, - }[process.platform]; - - raLspServerSource!: null | BinarySource; + langServerSource!: null | BinarySource; highlightingOn = true; rainbowHighlightingOn = false; @@ -72,6 +59,56 @@ export class Config { return path; } + /** + * Name of the binary artifact for `ra_lsp_server` that is published for + * `platform` on GitHub releases. (It is also stored under the same name when + * downloaded by the extension). + */ + private static prebuiltLangServerFileName(platform: NodeJS.Platform): null | string { + switch (platform) { + case "linux": return "ra_lsp_server-linux"; + case "darwin": return "ra_lsp_server-mac"; + case "win32": return "ra_lsp_server-windows.exe"; + + // Users on these platforms yet need to manually build from sources + case "aix": + case "android": + case "freebsd": + case "openbsd": + case "sunos": + case "cygwin": + case "netbsd": return null; + // The list of platforms is exhaustive see (`NodeJS.Platform` type definition) + } + } + + private static langServerBinarySource( + ctx: vscode.ExtensionContext, + config: vscode.WorkspaceConfiguration + ): null | BinarySource { + const raLspServerPath = RA_LSP_DEBUG ?? config.get("raLspServerPath"); + + if (raLspServerPath) { + return { + type: BinarySource.Type.ExplicitPath, + path: Config.expandPathResolving(raLspServerPath) + }; + } + + const prebuiltBinaryName = Config.prebuiltLangServerFileName(process.platform); + + return !prebuiltBinaryName ? null : { + type: BinarySource.Type.GithubRelease, + dir: ctx.globalStoragePath, + file: prebuiltBinaryName, + repo: { + name: "rust-analyzer", + owner: "rust-analyzer", + } + }; + } + + // FIXME: revisit the logic for `if (.has(...)) config.get(...)` set default // values only in one place (i.e. remove default values from non-readonly members declarations) private refresh(ctx: vscode.ExtensionContext) { @@ -107,27 +144,7 @@ export class Config { this.prevEnhancedTyping = this.enableEnhancedTyping; } - { - const raLspServerPath = RA_LSP_DEBUG ?? config.get("raLspServerPath"); - if (raLspServerPath) { - this.raLspServerSource = { - type: BinarySourceType.ExplicitPath, - path: Config.expandPathResolving(raLspServerPath) - }; - } else if (this.raLspServerGithubArtifactName) { - this.raLspServerSource = { - type: BinarySourceType.GithubBinary, - dir: ctx.globalStoragePath, - file: this.raLspServerGithubArtifactName, - repo: { - name: "rust-analyzer", - owner: "rust-analyzer", - } - }; - } else { - this.raLspServerSource = null; - } - } + this.langServerSource = Config.langServerBinarySource(ctx, config); if (config.has('cargo-watch.enable')) { this.cargoWatchOptions.enable = config.get( -- cgit v1.2.3 From 8f291c0089700ab17fafddde33dc12515ba45662 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 9 Feb 2020 00:28:32 +0200 Subject: vscode: refactor comment --- editors/code/src/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors/code/src/config.ts') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index f216ab461..5aed8c9f3 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -78,7 +78,7 @@ export class Config { case "sunos": case "cygwin": case "netbsd": return null; - // The list of platforms is exhaustive see (`NodeJS.Platform` type definition) + // The list of platforms is exhaustive (see `NodeJS.Platform` type definition) } } -- cgit v1.2.3 From fd6a98ef6e8cb3ee4d578bf90ad327df548dd1c5 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 9 Feb 2020 00:42:51 +0200 Subject: vscode: rename raLspServer variable to langServer --- editors/code/src/config.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'editors/code/src/config.ts') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 5aed8c9f3..46394600b 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -86,12 +86,12 @@ export class Config { ctx: vscode.ExtensionContext, config: vscode.WorkspaceConfiguration ): null | BinarySource { - const raLspServerPath = RA_LSP_DEBUG ?? config.get("raLspServerPath"); + const langServerPath = RA_LSP_DEBUG ?? config.get("raLspServerPath"); - if (raLspServerPath) { + if (langServerPath) { return { type: BinarySource.Type.ExplicitPath, - path: Config.expandPathResolving(raLspServerPath) + path: Config.expandPathResolving(langServerPath) }; } -- cgit v1.2.3 From 7a09274e52dc00f7d4e3a040686aa1eb1e075671 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 9 Feb 2020 13:45:06 +0200 Subject: vscode: refactor inverted ternaries to if statements as per @matklad --- editors/code/src/config.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'editors/code/src/config.ts') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 46394600b..d5f3da2ed 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -97,7 +97,9 @@ export class Config { const prebuiltBinaryName = Config.prebuiltLangServerFileName(process.platform); - return !prebuiltBinaryName ? null : { + if (!prebuiltBinaryName) return null; + + return { type: BinarySource.Type.GithubRelease, dir: ctx.globalStoragePath, file: prebuiltBinaryName, -- cgit v1.2.3