diff options
author | Veetaha <[email protected]> | 2020-02-14 21:04:50 +0000 |
---|---|---|
committer | Veetaha <[email protected]> | 2020-02-14 21:04:50 +0000 |
commit | 4fb427743c27c63a4aa3ccd54c488b22d4308bc2 (patch) | |
tree | 45dfb0fca0912d45e83fd33b1eb065898febec2a /editors | |
parent | fd37151ade9948398e863c38418fb4f0d0acdfa7 (diff) |
vscode: moved to getters as per matklad
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/src/client.ts | 18 | ||||
-rw-r--r-- | editors/code/src/config.ts | 40 | ||||
-rw-r--r-- | editors/code/src/highlighting.ts | 6 | ||||
-rw-r--r-- | editors/code/src/inlay_hints.ts | 6 | ||||
-rw-r--r-- | editors/code/src/status_display.ts | 2 |
5 files changed, 33 insertions, 39 deletions
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<null | lc.LanguageCl | |||
10 | // It might be a good idea to test if the uri points to a file. | 10 | // It might be a good idea to test if the uri points to a file. |
11 | const workspaceFolderPath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.'; | 11 | const workspaceFolderPath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.'; |
12 | 12 | ||
13 | const langServerPath = await ensureLanguageServerBinary(config.langServerBinarySource()); | 13 | const langServerPath = await ensureLanguageServerBinary(config.langServerBinarySource); |
14 | if (!langServerPath) return null; | 14 | if (!langServerPath) return null; |
15 | 15 | ||
16 | const run: lc.Executable = { | 16 | const run: lc.Executable = { |
@@ -24,23 +24,23 @@ export async function createClient(config: Config): Promise<null | lc.LanguageCl | |||
24 | const traceOutputChannel = vscode.window.createOutputChannel( | 24 | const traceOutputChannel = vscode.window.createOutputChannel( |
25 | 'Rust Analyzer Language Server Trace', | 25 | 'Rust Analyzer Language Server Trace', |
26 | ); | 26 | ); |
27 | const cargoWatchOpts = config.cargoWatchOptions(); | 27 | const cargoWatchOpts = config.cargoWatchOptions; |
28 | 28 | ||
29 | const clientOptions: lc.LanguageClientOptions = { | 29 | const clientOptions: lc.LanguageClientOptions = { |
30 | documentSelector: [{ scheme: 'file', language: 'rust' }], | 30 | documentSelector: [{ scheme: 'file', language: 'rust' }], |
31 | initializationOptions: { | 31 | initializationOptions: { |
32 | publishDecorations: true, | 32 | publishDecorations: true, |
33 | lruCapacity: config.lruCapacity(), | 33 | lruCapacity: config.lruCapacity, |
34 | maxInlayHintLength: config.maxInlayHintLength(), | 34 | maxInlayHintLength: config.maxInlayHintLength, |
35 | cargoWatchEnable: cargoWatchOpts.enable, | 35 | cargoWatchEnable: cargoWatchOpts.enable, |
36 | cargoWatchArgs: cargoWatchOpts.arguments, | 36 | cargoWatchArgs: cargoWatchOpts.arguments, |
37 | cargoWatchCommand: cargoWatchOpts.command, | 37 | cargoWatchCommand: cargoWatchOpts.command, |
38 | cargoWatchAllTargets: cargoWatchOpts.allTargets, | 38 | cargoWatchAllTargets: cargoWatchOpts.allTargets, |
39 | excludeGlobs: config.excludeGlobs(), | 39 | excludeGlobs: config.excludeGlobs, |
40 | useClientWatching: config.useClientWatching(), | 40 | useClientWatching: config.useClientWatching, |
41 | featureFlags: config.featureFlags(), | 41 | featureFlags: config.featureFlags, |
42 | withSysroot: config.withSysroot(), | 42 | withSysroot: config.withSysroot, |
43 | cargoFeatures: config.cargoFeatures(), | 43 | cargoFeatures: config.cargoFeatures, |
44 | }, | 44 | }, |
45 | traceOutputChannel, | 45 | traceOutputChannel, |
46 | }; | 46 | }; |
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 349f80278..3ce669330 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -68,17 +68,14 @@ export class Config { | |||
68 | * `platform` on GitHub releases. (It is also stored under the same name when | 68 | * `platform` on GitHub releases. (It is also stored under the same name when |
69 | * downloaded by the extension). | 69 | * downloaded by the extension). |
70 | */ | 70 | */ |
71 | private static prebuiltLangServerFileName( | 71 | get prebuiltLangServerFileName(): null | string { |
72 | platform: NodeJS.Platform, | ||
73 | arch: string | ||
74 | ): null | string { | ||
75 | // See possible `arch` values here: | 72 | // See possible `arch` values here: |
76 | // https://nodejs.org/api/process.html#process_process_arch | 73 | // https://nodejs.org/api/process.html#process_process_arch |
77 | 74 | ||
78 | switch (platform) { | 75 | switch (process.platform) { |
79 | 76 | ||
80 | case "linux": { | 77 | case "linux": { |
81 | switch (arch) { | 78 | switch (process.arch) { |
82 | case "arm": | 79 | case "arm": |
83 | case "arm64": return null; | 80 | case "arm64": return null; |
84 | 81 | ||
@@ -101,7 +98,7 @@ export class Config { | |||
101 | } | 98 | } |
102 | } | 99 | } |
103 | 100 | ||
104 | langServerBinarySource(): null | BinarySource { | 101 | get langServerBinarySource(): null | BinarySource { |
105 | const langServerPath = RA_LSP_DEBUG ?? this.cfg.get<null | string>("raLspServerPath"); | 102 | const langServerPath = RA_LSP_DEBUG ?? this.cfg.get<null | string>("raLspServerPath"); |
106 | 103 | ||
107 | if (langServerPath) { | 104 | if (langServerPath) { |
@@ -111,9 +108,7 @@ export class Config { | |||
111 | }; | 108 | }; |
112 | } | 109 | } |
113 | 110 | ||
114 | const prebuiltBinaryName = Config.prebuiltLangServerFileName( | 111 | const prebuiltBinaryName = this.prebuiltLangServerFileName; |
115 | process.platform, process.arch | ||
116 | ); | ||
117 | 112 | ||
118 | if (!prebuiltBinaryName) return null; | 113 | if (!prebuiltBinaryName) return null; |
119 | 114 | ||
@@ -131,17 +126,16 @@ export class Config { | |||
131 | // We don't do runtime config validation here for simplicity. More on stackoverflow: | 126 | // We don't do runtime config validation here for simplicity. More on stackoverflow: |
132 | // https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension | 127 | // https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension |
133 | 128 | ||
134 | // FIXME: add codegen for primitive configurations | 129 | get highlightingOn() { return this.cfg.get("highlightingOn") as boolean; } |
135 | highlightingOn() { return this.cfg.get("highlightingOn") as boolean; } | 130 | get rainbowHighlightingOn() { return this.cfg.get("rainbowHighlightingOn") as boolean; } |
136 | rainbowHighlightingOn() { return this.cfg.get("rainbowHighlightingOn") as boolean; } | 131 | get lruCapacity() { return this.cfg.get("lruCapacity") as null | number; } |
137 | lruCapacity() { return this.cfg.get("lruCapacity") as null | number; } | 132 | get displayInlayHints() { return this.cfg.get("displayInlayHints") as boolean; } |
138 | displayInlayHints() { return this.cfg.get("displayInlayHints") as boolean; } | 133 | get maxInlayHintLength() { return this.cfg.get("maxInlayHintLength") as number; } |
139 | maxInlayHintLength() { return this.cfg.get("maxInlayHintLength") as number; } | 134 | get excludeGlobs() { return this.cfg.get("excludeGlobs") as string[]; } |
140 | excludeGlobs() { return this.cfg.get("excludeGlobs") as string[]; } | 135 | get useClientWatching() { return this.cfg.get("useClientWatching") as boolean; } |
141 | useClientWatching() { return this.cfg.get("useClientWatching") as boolean; } | 136 | get featureFlags() { return this.cfg.get("featureFlags") as Record<string, boolean>; } |
142 | featureFlags() { return this.cfg.get("featureFlags") as Record<string, boolean>; } | 137 | |
143 | 138 | get cargoWatchOptions(): CargoWatchOptions { | |
144 | cargoWatchOptions(): CargoWatchOptions { | ||
145 | return { | 139 | return { |
146 | enable: this.cfg.get("cargo-watch.enable") as boolean, | 140 | enable: this.cfg.get("cargo-watch.enable") as boolean, |
147 | arguments: this.cfg.get("cargo-watch.arguments") as string[], | 141 | arguments: this.cfg.get("cargo-watch.arguments") as string[], |
@@ -150,7 +144,7 @@ export class Config { | |||
150 | }; | 144 | }; |
151 | } | 145 | } |
152 | 146 | ||
153 | cargoFeatures(): CargoFeatures { | 147 | get cargoFeatures(): CargoFeatures { |
154 | return { | 148 | return { |
155 | noDefaultFeatures: this.cfg.get("cargoFeatures.noDefaultFeatures") as boolean, | 149 | noDefaultFeatures: this.cfg.get("cargoFeatures.noDefaultFeatures") as boolean, |
156 | allFeatures: this.cfg.get("cargoFeatures.allFeatures") as boolean, | 150 | allFeatures: this.cfg.get("cargoFeatures.allFeatures") as boolean, |
@@ -159,5 +153,5 @@ export class Config { | |||
159 | } | 153 | } |
160 | 154 | ||
161 | // for internal use | 155 | // for internal use |
162 | withSysroot() { return this.cfg.get("withSysroot", false); } | 156 | get withSysroot() { return this.cfg.get("withSysroot", false); } |
163 | } | 157 | } |
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) { | |||
11 | client.onNotification( | 11 | client.onNotification( |
12 | 'rust-analyzer/publishDecorations', | 12 | 'rust-analyzer/publishDecorations', |
13 | (params: PublishDecorationsParams) => { | 13 | (params: PublishDecorationsParams) => { |
14 | if (!ctx.config.highlightingOn()) return; | 14 | if (!ctx.config.highlightingOn) return; |
15 | 15 | ||
16 | const targetEditor = vscode.window.visibleTextEditors.find( | 16 | const targetEditor = vscode.window.visibleTextEditors.find( |
17 | editor => { | 17 | editor => { |
@@ -39,7 +39,7 @@ export function activateHighlighting(ctx: Ctx) { | |||
39 | vscode.window.onDidChangeActiveTextEditor( | 39 | vscode.window.onDidChangeActiveTextEditor( |
40 | async (editor: vscode.TextEditor | undefined) => { | 40 | async (editor: vscode.TextEditor | undefined) => { |
41 | if (!editor || editor.document.languageId !== 'rust') return; | 41 | if (!editor || editor.document.languageId !== 'rust') return; |
42 | if (!ctx.config.highlightingOn()) return; | 42 | if (!ctx.config.highlightingOn) return; |
43 | const client = ctx.client; | 43 | const client = ctx.client; |
44 | if (!client) return; | 44 | if (!client) return; |
45 | 45 | ||
@@ -122,7 +122,7 @@ class Highlighter { | |||
122 | string, | 122 | string, |
123 | [vscode.Range[], boolean] | 123 | [vscode.Range[], boolean] |
124 | > = new Map(); | 124 | > = new Map(); |
125 | const rainbowTime = this.ctx.config.rainbowHighlightingOn(); | 125 | const rainbowTime = this.ctx.config.rainbowHighlightingOn; |
126 | 126 | ||
127 | for (const tag of this.decorations.keys()) { | 127 | for (const tag of this.decorations.keys()) { |
128 | byTag.set(tag, []); | 128 | 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) { | |||
22 | ); | 22 | ); |
23 | 23 | ||
24 | vscode.workspace.onDidChangeConfiguration( | 24 | vscode.workspace.onDidChangeConfiguration( |
25 | async _ => hintsUpdater.setEnabled(ctx.config.displayInlayHints()), | 25 | async _ => hintsUpdater.setEnabled(ctx.config.displayInlayHints), |
26 | null, | 26 | null, |
27 | ctx.subscriptions | 27 | ctx.subscriptions |
28 | ); | 28 | ); |
29 | 29 | ||
30 | ctx.onDidRestart(_ => hintsUpdater.setEnabled(ctx.config.displayInlayHints())); | 30 | ctx.onDidRestart(_ => hintsUpdater.setEnabled(ctx.config.displayInlayHints)); |
31 | } | 31 | } |
32 | 32 | ||
33 | interface InlayHintsParams { | 33 | interface InlayHintsParams { |
@@ -59,7 +59,7 @@ class HintsUpdater { | |||
59 | 59 | ||
60 | constructor(ctx: Ctx) { | 60 | constructor(ctx: Ctx) { |
61 | this.ctx = ctx; | 61 | this.ctx = ctx; |
62 | this.enabled = ctx.config.displayInlayHints(); | 62 | this.enabled = ctx.config.displayInlayHints; |
63 | } | 63 | } |
64 | 64 | ||
65 | async setEnabled(enabled: boolean) { | 65 | 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'; | |||
7 | const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; | 7 | const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; |
8 | 8 | ||
9 | export function activateStatusDisplay(ctx: Ctx) { | 9 | export function activateStatusDisplay(ctx: Ctx) { |
10 | const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions().command); | 10 | const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command); |
11 | ctx.pushCleanup(statusDisplay); | 11 | ctx.pushCleanup(statusDisplay); |
12 | ctx.onDidRestart(client => ctx.pushCleanup(client.onProgress( | 12 | ctx.onDidRestart(client => ctx.pushCleanup(client.onProgress( |
13 | WorkDoneProgress.type, | 13 | WorkDoneProgress.type, |