diff options
Diffstat (limited to 'editors/code/src/config.ts')
-rw-r--r-- | editors/code/src/config.ts | 56 |
1 files changed, 49 insertions, 7 deletions
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 @@ | |||
1 | import * as os from "os"; | ||
1 | import * as vscode from 'vscode'; | 2 | import * as vscode from 'vscode'; |
3 | import { BinarySource, BinarySourceType } from "./installation/interfaces"; | ||
2 | 4 | ||
3 | const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; | 5 | const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; |
4 | 6 | ||
@@ -16,10 +18,24 @@ export interface CargoFeatures { | |||
16 | } | 18 | } |
17 | 19 | ||
18 | export class Config { | 20 | export class Config { |
21 | readonly raLspServerGithubArtifactName = { | ||
22 | linux: "ra_lsp_server-linux", | ||
23 | darwin: "ra_lsp_server-mac", | ||
24 | win32: "ra_lsp_server-windows.exe", | ||
25 | aix: null, | ||
26 | android: null, | ||
27 | freebsd: null, | ||
28 | openbsd: null, | ||
29 | sunos: null, | ||
30 | cygwin: null, | ||
31 | netbsd: null, | ||
32 | }[process.platform]; | ||
33 | |||
34 | raLspServerSource!: null | BinarySource; | ||
35 | |||
19 | highlightingOn = true; | 36 | highlightingOn = true; |
20 | rainbowHighlightingOn = false; | 37 | rainbowHighlightingOn = false; |
21 | enableEnhancedTyping = true; | 38 | enableEnhancedTyping = true; |
22 | raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server'; | ||
23 | lruCapacity: null | number = null; | 39 | lruCapacity: null | number = null; |
24 | displayInlayHints = true; | 40 | displayInlayHints = true; |
25 | maxInlayHintLength: null | number = null; | 41 | maxInlayHintLength: null | number = null; |
@@ -45,11 +61,20 @@ export class Config { | |||
45 | private prevCargoWatchOptions: null | CargoWatchOptions = null; | 61 | private prevCargoWatchOptions: null | CargoWatchOptions = null; |
46 | 62 | ||
47 | constructor(ctx: vscode.ExtensionContext) { | 63 | constructor(ctx: vscode.ExtensionContext) { |
48 | vscode.workspace.onDidChangeConfiguration(_ => this.refresh(), null, ctx.subscriptions); | 64 | vscode.workspace.onDidChangeConfiguration(_ => this.refresh(ctx), null, ctx.subscriptions); |
49 | this.refresh(); | 65 | this.refresh(ctx); |
66 | } | ||
67 | |||
68 | private static expandPathResolving(path: string) { | ||
69 | if (path.startsWith('~/')) { | ||
70 | return path.replace('~', os.homedir()); | ||
71 | } | ||
72 | return path; | ||
50 | } | 73 | } |
51 | 74 | ||
52 | private refresh() { | 75 | // FIXME: revisit the logic for `if (.has(...)) config.get(...)` set default |
76 | // values only in one place (i.e. remove default values from non-readonly members declarations) | ||
77 | private refresh(ctx: vscode.ExtensionContext) { | ||
53 | const config = vscode.workspace.getConfiguration('rust-analyzer'); | 78 | const config = vscode.workspace.getConfiguration('rust-analyzer'); |
54 | 79 | ||
55 | let requireReloadMessage = null; | 80 | let requireReloadMessage = null; |
@@ -82,9 +107,26 @@ export class Config { | |||
82 | this.prevEnhancedTyping = this.enableEnhancedTyping; | 107 | this.prevEnhancedTyping = this.enableEnhancedTyping; |
83 | } | 108 | } |
84 | 109 | ||
85 | if (config.has('raLspServerPath')) { | 110 | { |
86 | this.raLspServerPath = | 111 | const raLspServerPath = RA_LSP_DEBUG ?? config.get<null | string>("raLspServerPath"); |
87 | RA_LSP_DEBUG || (config.get('raLspServerPath') as string); | 112 | if (raLspServerPath) { |
113 | this.raLspServerSource = { | ||
114 | type: BinarySourceType.ExplicitPath, | ||
115 | path: Config.expandPathResolving(raLspServerPath) | ||
116 | }; | ||
117 | } else if (this.raLspServerGithubArtifactName) { | ||
118 | this.raLspServerSource = { | ||
119 | type: BinarySourceType.GithubBinary, | ||
120 | dir: ctx.globalStoragePath, | ||
121 | file: this.raLspServerGithubArtifactName, | ||
122 | repo: { | ||
123 | name: "rust-analyzer", | ||
124 | owner: "rust-analyzer", | ||
125 | } | ||
126 | }; | ||
127 | } else { | ||
128 | this.raLspServerSource = null; | ||
129 | } | ||
88 | } | 130 | } |
89 | 131 | ||
90 | if (config.has('cargo-watch.enable')) { | 132 | if (config.has('cargo-watch.enable')) { |