diff options
Diffstat (limited to 'editors/code/src/config.ts')
-rw-r--r-- | editors/code/src/config.ts | 89 |
1 files changed, 53 insertions, 36 deletions
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 @@ | |||
1 | import * as os from "os"; | 1 | import * as os from "os"; |
2 | import * as vscode from 'vscode'; | 2 | import * as vscode from 'vscode'; |
3 | import { BinarySource, BinarySourceType } from "./installation/interfaces"; | 3 | import { BinarySource } from "./installation/interfaces"; |
4 | 4 | ||
5 | const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; | 5 | const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; |
6 | 6 | ||
@@ -18,20 +18,7 @@ export interface CargoFeatures { | |||
18 | } | 18 | } |
19 | 19 | ||
20 | export class Config { | 20 | export class Config { |
21 | readonly raLspServerGithubArtifactName = { | 21 | langServerSource!: null | BinarySource; |
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 | 22 | ||
36 | highlightingOn = true; | 23 | highlightingOn = true; |
37 | rainbowHighlightingOn = false; | 24 | rainbowHighlightingOn = false; |
@@ -72,6 +59,56 @@ export class Config { | |||
72 | return path; | 59 | return path; |
73 | } | 60 | } |
74 | 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 raLspServerPath = RA_LSP_DEBUG ?? config.get<null | string>("raLspServerPath"); | ||
90 | |||
91 | if (raLspServerPath) { | ||
92 | return { | ||
93 | type: BinarySource.Type.ExplicitPath, | ||
94 | path: Config.expandPathResolving(raLspServerPath) | ||
95 | }; | ||
96 | } | ||
97 | |||
98 | const prebuiltBinaryName = Config.prebuiltLangServerFileName(process.platform); | ||
99 | |||
100 | return !prebuiltBinaryName ? null : { | ||
101 | type: BinarySource.Type.GithubRelease, | ||
102 | dir: ctx.globalStoragePath, | ||
103 | file: prebuiltBinaryName, | ||
104 | repo: { | ||
105 | name: "rust-analyzer", | ||
106 | owner: "rust-analyzer", | ||
107 | } | ||
108 | }; | ||
109 | } | ||
110 | |||
111 | |||
75 | // FIXME: revisit the logic for `if (.has(...)) config.get(...)` set default | 112 | // 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) | 113 | // values only in one place (i.e. remove default values from non-readonly members declarations) |
77 | private refresh(ctx: vscode.ExtensionContext) { | 114 | private refresh(ctx: vscode.ExtensionContext) { |
@@ -107,27 +144,7 @@ export class Config { | |||
107 | this.prevEnhancedTyping = this.enableEnhancedTyping; | 144 | this.prevEnhancedTyping = this.enableEnhancedTyping; |
108 | } | 145 | } |
109 | 146 | ||
110 | { | 147 | this.langServerSource = Config.langServerBinarySource(ctx, config); |
111 | const raLspServerPath = RA_LSP_DEBUG ?? config.get<null | string>("raLspServerPath"); | ||
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 | } | ||
130 | } | ||
131 | 148 | ||
132 | if (config.has('cargo-watch.enable')) { | 149 | if (config.has('cargo-watch.enable')) { |
133 | this.cargoWatchOptions.enable = config.get<boolean>( | 150 | this.cargoWatchOptions.enable = config.get<boolean>( |