diff options
author | Aleksey Kladov <[email protected]> | 2020-03-17 11:44:31 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-03-19 08:04:59 +0000 |
commit | fb6e655de8a44c65275ad45a27bf5bd684670ba0 (patch) | |
tree | 9c307ac69c8fc59465ee2fb6f9a8a619fc064167 /editors/code/src/config.ts | |
parent | f0a1b64d7ee3baa7ccf980b35b85f0a4a3b85b1a (diff) |
Rewrite auto-update
Everything now happens in main.ts, in the bootstrap family of
functions. The current flow is:
* check everything only on extension installation.
* if the user is on nightly channel, try to download the nightly
extension and reload.
* when we install nightly extension, we persist its release id, so
that we can check if the current release is different.
* if server binary was not downloaded by the current version of the
extension, redownload it (we persist the version of ext that
downloaded the server).
Diffstat (limited to 'editors/code/src/config.ts')
-rw-r--r-- | editors/code/src/config.ts | 103 |
1 files changed, 7 insertions, 96 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index b45b14bef..28698ab8e 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -1,9 +1,5 @@ | |||
1 | import * as os from "os"; | ||
2 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
3 | import { ArtifactSource } from "./installation/interfaces"; | 2 | import { log } from "./util"; |
4 | import { log, vscodeReloadWindow } from "./util"; | ||
5 | |||
6 | const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; | ||
7 | 3 | ||
8 | export interface InlayHintOptions { | 4 | export interface InlayHintOptions { |
9 | typeHints: boolean; | 5 | typeHints: boolean; |
@@ -25,10 +21,7 @@ export interface CargoFeatures { | |||
25 | loadOutDirsFromCheck: boolean; | 21 | loadOutDirsFromCheck: boolean; |
26 | } | 22 | } |
27 | 23 | ||
28 | export const enum UpdatesChannel { | 24 | export type UpdatesChannel = "stable" | "nightly"; |
29 | Stable = "stable", | ||
30 | Nightly = "nightly" | ||
31 | } | ||
32 | 25 | ||
33 | export const NIGHTLY_TAG = "nightly"; | 26 | export const NIGHTLY_TAG = "nightly"; |
34 | export class Config { | 27 | export class Config { |
@@ -41,6 +34,7 @@ export class Config { | |||
41 | "cargo-watch", | 34 | "cargo-watch", |
42 | "highlighting.semanticTokens", | 35 | "highlighting.semanticTokens", |
43 | "inlayHints", | 36 | "inlayHints", |
37 | "updates.channel", | ||
44 | ] | 38 | ] |
45 | .map(opt => `${this.rootSection}.${opt}`); | 39 | .map(opt => `${this.rootSection}.${opt}`); |
46 | 40 | ||
@@ -94,100 +88,17 @@ export class Config { | |||
94 | ); | 88 | ); |
95 | 89 | ||
96 | if (userResponse === "Reload now") { | 90 | if (userResponse === "Reload now") { |
97 | await vscodeReloadWindow(); | 91 | await vscode.commands.executeCommand("workbench.action.reloadWindow"); |
98 | } | 92 | } |
99 | } | 93 | } |
100 | 94 | ||
101 | private static replaceTildeWithHomeDir(path: string) { | 95 | get globalStoragePath(): string { return this.ctx.globalStoragePath; } |
102 | if (path.startsWith("~/")) { | ||
103 | return os.homedir() + path.slice("~".length); | ||
104 | } | ||
105 | return path; | ||
106 | } | ||
107 | |||
108 | /** | ||
109 | * Name of the binary artifact for `rust-analyzer` that is published for | ||
110 | * `platform` on GitHub releases. (It is also stored under the same name when | ||
111 | * downloaded by the extension). | ||
112 | */ | ||
113 | get prebuiltServerFileName(): null | string { | ||
114 | // See possible `arch` values here: | ||
115 | // https://nodejs.org/api/process.html#process_process_arch | ||
116 | |||
117 | switch (process.platform) { | ||
118 | |||
119 | case "linux": { | ||
120 | switch (process.arch) { | ||
121 | case "arm": | ||
122 | case "arm64": return null; | ||
123 | |||
124 | default: return "rust-analyzer-linux"; | ||
125 | } | ||
126 | } | ||
127 | |||
128 | case "darwin": return "rust-analyzer-mac"; | ||
129 | case "win32": return "rust-analyzer-windows.exe"; | ||
130 | |||
131 | // Users on these platforms yet need to manually build from sources | ||
132 | case "aix": | ||
133 | case "android": | ||
134 | case "freebsd": | ||
135 | case "openbsd": | ||
136 | case "sunos": | ||
137 | case "cygwin": | ||
138 | case "netbsd": return null; | ||
139 | // The list of platforms is exhaustive (see `NodeJS.Platform` type definition) | ||
140 | } | ||
141 | } | ||
142 | |||
143 | get installedExtensionUpdateChannel(): UpdatesChannel { | ||
144 | return this.extensionReleaseTag === NIGHTLY_TAG | ||
145 | ? UpdatesChannel.Nightly | ||
146 | : UpdatesChannel.Stable; | ||
147 | } | ||
148 | |||
149 | get serverSource(): null | ArtifactSource { | ||
150 | const serverPath = RA_LSP_DEBUG ?? this.serverPath; | ||
151 | |||
152 | if (serverPath) { | ||
153 | return { | ||
154 | type: ArtifactSource.Type.ExplicitPath, | ||
155 | path: Config.replaceTildeWithHomeDir(serverPath) | ||
156 | }; | ||
157 | } | ||
158 | |||
159 | const prebuiltBinaryName = this.prebuiltServerFileName; | ||
160 | |||
161 | if (!prebuiltBinaryName) return null; | ||
162 | |||
163 | return this.createGithubReleaseSource( | ||
164 | prebuiltBinaryName, | ||
165 | this.extensionReleaseTag | ||
166 | ); | ||
167 | } | ||
168 | |||
169 | private createGithubReleaseSource(file: string, tag: string): ArtifactSource.GithubRelease { | ||
170 | return { | ||
171 | type: ArtifactSource.Type.GithubRelease, | ||
172 | file, | ||
173 | tag, | ||
174 | dir: this.ctx.globalStoragePath, | ||
175 | repo: { | ||
176 | name: "rust-analyzer", | ||
177 | owner: "rust-analyzer", | ||
178 | } | ||
179 | }; | ||
180 | } | ||
181 | |||
182 | get nightlyVsixSource(): ArtifactSource.GithubRelease { | ||
183 | return this.createGithubReleaseSource("rust-analyzer.vsix", NIGHTLY_TAG); | ||
184 | } | ||
185 | 96 | ||
186 | // We don't do runtime config validation here for simplicity. More on stackoverflow: | 97 | // We don't do runtime config validation here for simplicity. More on stackoverflow: |
187 | // https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension | 98 | // https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension |
188 | 99 | ||
189 | private get serverPath() { return this.cfg.get("serverPath") as null | string; } | 100 | get serverPath() { return this.cfg.get("serverPath") as null | string; } |
190 | get updatesChannel() { return this.cfg.get("updates.channel") as UpdatesChannel; } | 101 | get channel() { return this.cfg.get<"stable" | "nightly">("updates.channel")!; } |
191 | get askBeforeDownload() { return this.cfg.get("updates.askBeforeDownload") as boolean; } | 102 | get askBeforeDownload() { return this.cfg.get("updates.askBeforeDownload") as boolean; } |
192 | get highlightingSemanticTokens() { return this.cfg.get("highlighting.semanticTokens") as boolean; } | 103 | get highlightingSemanticTokens() { return this.cfg.get("highlighting.semanticTokens") as boolean; } |
193 | get highlightingOn() { return this.cfg.get("highlightingOn") as boolean; } | 104 | get highlightingOn() { return this.cfg.get("highlightingOn") as boolean; } |