diff options
Diffstat (limited to 'editors/code/src/config.ts')
-rw-r--r-- | editors/code/src/config.ts | 77 |
1 files changed, 69 insertions, 8 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 524620433..d5f3da2ed 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 } 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,11 @@ export interface CargoFeatures { | |||
16 | } | 18 | } |
17 | 19 | ||
18 | export class Config { | 20 | export class Config { |
21 | langServerSource!: null | BinarySource; | ||
22 | |||
19 | highlightingOn = true; | 23 | highlightingOn = true; |
20 | rainbowHighlightingOn = false; | 24 | rainbowHighlightingOn = false; |
21 | enableEnhancedTyping = true; | 25 | enableEnhancedTyping = true; |
22 | raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server'; | ||
23 | lruCapacity: null | number = null; | 26 | lruCapacity: null | number = null; |
24 | displayInlayHints = true; | 27 | displayInlayHints = true; |
25 | maxInlayHintLength: null | number = null; | 28 | maxInlayHintLength: null | number = null; |
@@ -45,11 +48,72 @@ export class Config { | |||
45 | private prevCargoWatchOptions: null | CargoWatchOptions = null; | 48 | private prevCargoWatchOptions: null | CargoWatchOptions = null; |
46 | 49 | ||
47 | constructor(ctx: vscode.ExtensionContext) { | 50 | constructor(ctx: vscode.ExtensionContext) { |
48 | vscode.workspace.onDidChangeConfiguration(_ => this.refresh(), null, ctx.subscriptions); | 51 | vscode.workspace.onDidChangeConfiguration(_ => this.refresh(ctx), null, ctx.subscriptions); |
49 | this.refresh(); | 52 | this.refresh(ctx); |
53 | } | ||
54 | |||
55 | private static expandPathResolving(path: string) { | ||
56 | if (path.startsWith('~/')) { | ||
57 | return path.replace('~', os.homedir()); | ||
58 | } | ||
59 | return path; | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * Name of the binary artifact for `ra_lsp_server` that is published for | ||
64 | * `platform` on GitHub releases. (It is also stored under the same name when | ||
65 | * downloaded by the extension). | ||
66 | */ | ||
67 | private static prebuiltLangServerFileName(platform: NodeJS.Platform): null | string { | ||
68 | switch (platform) { | ||
69 | case "linux": return "ra_lsp_server-linux"; | ||
70 | case "darwin": return "ra_lsp_server-mac"; | ||
71 | case "win32": return "ra_lsp_server-windows.exe"; | ||
72 | |||
73 | // Users on these platforms yet need to manually build from sources | ||
74 | case "aix": | ||
75 | case "android": | ||
76 | case "freebsd": | ||
77 | case "openbsd": | ||
78 | case "sunos": | ||
79 | case "cygwin": | ||
80 | case "netbsd": return null; | ||
81 | // The list of platforms is exhaustive (see `NodeJS.Platform` type definition) | ||
82 | } | ||
83 | } | ||
84 | |||
85 | private static langServerBinarySource( | ||
86 | ctx: vscode.ExtensionContext, | ||
87 | config: vscode.WorkspaceConfiguration | ||
88 | ): null | BinarySource { | ||
89 | const langServerPath = RA_LSP_DEBUG ?? config.get<null | string>("raLspServerPath"); | ||
90 | |||
91 | if (langServerPath) { | ||
92 | return { | ||
93 | type: BinarySource.Type.ExplicitPath, | ||
94 | path: Config.expandPathResolving(langServerPath) | ||
95 | }; | ||
96 | } | ||
97 | |||
98 | const prebuiltBinaryName = Config.prebuiltLangServerFileName(process.platform); | ||
99 | |||
100 | if (!prebuiltBinaryName) return null; | ||
101 | |||
102 | return { | ||
103 | type: BinarySource.Type.GithubRelease, | ||
104 | dir: ctx.globalStoragePath, | ||
105 | file: prebuiltBinaryName, | ||
106 | repo: { | ||
107 | name: "rust-analyzer", | ||
108 | owner: "rust-analyzer", | ||
109 | } | ||
110 | }; | ||
50 | } | 111 | } |
51 | 112 | ||
52 | private refresh() { | 113 | |
114 | // FIXME: revisit the logic for `if (.has(...)) config.get(...)` set default | ||
115 | // values only in one place (i.e. remove default values from non-readonly members declarations) | ||
116 | private refresh(ctx: vscode.ExtensionContext) { | ||
53 | const config = vscode.workspace.getConfiguration('rust-analyzer'); | 117 | const config = vscode.workspace.getConfiguration('rust-analyzer'); |
54 | 118 | ||
55 | let requireReloadMessage = null; | 119 | let requireReloadMessage = null; |
@@ -82,10 +146,7 @@ export class Config { | |||
82 | this.prevEnhancedTyping = this.enableEnhancedTyping; | 146 | this.prevEnhancedTyping = this.enableEnhancedTyping; |
83 | } | 147 | } |
84 | 148 | ||
85 | if (config.has('raLspServerPath')) { | 149 | this.langServerSource = Config.langServerBinarySource(ctx, config); |
86 | this.raLspServerPath = | ||
87 | RA_LSP_DEBUG || (config.get('raLspServerPath') as string); | ||
88 | } | ||
89 | 150 | ||
90 | if (config.has('cargo-watch.enable')) { | 151 | if (config.has('cargo-watch.enable')) { |
91 | this.cargoWatchOptions.enable = config.get<boolean>( | 152 | this.cargoWatchOptions.enable = config.get<boolean>( |