diff options
author | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
---|---|---|
committer | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
commit | f05d7b41a719d848844b054a16477b29d0f063c6 (patch) | |
tree | 0a8a0946e8aef2ce64d4c13d0035ba41cce2daf3 /editors/code/src/main.ts | |
parent | 73ff610e41959e3e7c78a2b4b25b086883132956 (diff) | |
parent | 6b7cb8b5ab539fc4333ce34bc29bf77c976f232a (diff) |
Merge remote-tracking branch 'upstream/master' into 503-hover-doc-links
Hasn't fixed tests yet.
Diffstat (limited to 'editors/code/src/main.ts')
-rw-r--r-- | editors/code/src/main.ts | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 5ceab8b44..bd99d696a 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -19,6 +19,16 @@ let ctx: Ctx | undefined; | |||
19 | const RUST_PROJECT_CONTEXT_NAME = "inRustProject"; | 19 | const RUST_PROJECT_CONTEXT_NAME = "inRustProject"; |
20 | 20 | ||
21 | export async function activate(context: vscode.ExtensionContext) { | 21 | export async function activate(context: vscode.ExtensionContext) { |
22 | // For some reason vscode not always shows pop-up error notifications | ||
23 | // when an extension fails to activate, so we do it explicitly by ourselves. | ||
24 | // FIXME: remove this bit of code once vscode fixes this issue: https://github.com/microsoft/vscode/issues/101242 | ||
25 | await tryActivate(context).catch(err => { | ||
26 | void vscode.window.showErrorMessage(`Cannot activate rust-analyzer: ${err.message}`); | ||
27 | throw err; | ||
28 | }); | ||
29 | } | ||
30 | |||
31 | async function tryActivate(context: vscode.ExtensionContext) { | ||
22 | // Register a "dumb" onEnter command for the case where server fails to | 32 | // Register a "dumb" onEnter command for the case where server fails to |
23 | // start. | 33 | // start. |
24 | // | 34 | // |
@@ -44,13 +54,13 @@ export async function activate(context: vscode.ExtensionContext) { | |||
44 | const serverPath = await bootstrap(config, state).catch(err => { | 54 | const serverPath = await bootstrap(config, state).catch(err => { |
45 | let message = "bootstrap error. "; | 55 | let message = "bootstrap error. "; |
46 | 56 | ||
47 | if (err.code === "EBUSY" || err.code === "ETXTBSY") { | 57 | if (err.code === "EBUSY" || err.code === "ETXTBSY" || err.code === "EPERM") { |
48 | message += "Other vscode windows might be using rust-analyzer, "; | 58 | message += "Other vscode windows might be using rust-analyzer, "; |
49 | message += "you should close them and reload this window to retry. "; | 59 | message += "you should close them and reload this window to retry. "; |
50 | } | 60 | } |
51 | 61 | ||
52 | message += 'Open "Help > Toggle Developer Tools > Console" to see the logs '; | 62 | message += 'See the logs in "OUTPUT > Rust Analyzer Client" (should open automatically). '; |
53 | message += '(enable verbose logs with "rust-analyzer.trace.extension")'; | 63 | message += 'To enable verbose logs use { "rust-analyzer.trace.extension": true }'; |
54 | 64 | ||
55 | log.error("Bootstrap error", err); | 65 | log.error("Bootstrap error", err); |
56 | throw new Error(message); | 66 | throw new Error(message); |
@@ -58,9 +68,7 @@ export async function activate(context: vscode.ExtensionContext) { | |||
58 | 68 | ||
59 | const workspaceFolder = vscode.workspace.workspaceFolders?.[0]; | 69 | const workspaceFolder = vscode.workspace.workspaceFolders?.[0]; |
60 | if (workspaceFolder === undefined) { | 70 | if (workspaceFolder === undefined) { |
61 | const err = "Cannot activate rust-analyzer when no folder is opened"; | 71 | throw new Error("no folder is opened"); |
62 | void vscode.window.showErrorMessage(err); | ||
63 | throw new Error(err); | ||
64 | } | 72 | } |
65 | 73 | ||
66 | // Note: we try to start the server before we activate type hints so that it | 74 | // Note: we try to start the server before we activate type hints so that it |
@@ -88,7 +96,8 @@ export async function activate(context: vscode.ExtensionContext) { | |||
88 | }); | 96 | }); |
89 | 97 | ||
90 | ctx.registerCommand('analyzerStatus', commands.analyzerStatus); | 98 | ctx.registerCommand('analyzerStatus', commands.analyzerStatus); |
91 | ctx.registerCommand('collectGarbage', commands.collectGarbage); | 99 | ctx.registerCommand('memoryUsage', commands.memoryUsage); |
100 | ctx.registerCommand('reloadWorkspace', commands.reloadWorkspace); | ||
92 | ctx.registerCommand('matchingBrace', commands.matchingBrace); | 101 | ctx.registerCommand('matchingBrace', commands.matchingBrace); |
93 | ctx.registerCommand('joinLines', commands.joinLines); | 102 | ctx.registerCommand('joinLines', commands.joinLines); |
94 | ctx.registerCommand('parentModule', commands.parentModule); | 103 | ctx.registerCommand('parentModule', commands.parentModule); |
@@ -152,13 +161,17 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi | |||
152 | return; | 161 | return; |
153 | }; | 162 | }; |
154 | 163 | ||
155 | const lastCheck = state.lastCheck; | ||
156 | const now = Date.now(); | 164 | const now = Date.now(); |
165 | if (config.package.releaseTag === NIGHTLY_TAG) { | ||
166 | // Check if we should poll github api for the new nightly version | ||
167 | // if we haven't done it during the past hour | ||
168 | const lastCheck = state.lastCheck; | ||
157 | 169 | ||
158 | const anHour = 60 * 60 * 1000; | 170 | const anHour = 60 * 60 * 1000; |
159 | const shouldDownloadNightly = state.releaseId === undefined || (now - (lastCheck ?? 0)) > anHour; | 171 | const shouldCheckForNewNightly = state.releaseId === undefined || (now - (lastCheck ?? 0)) > anHour; |
160 | 172 | ||
161 | if (!shouldDownloadNightly) return; | 173 | if (!shouldCheckForNewNightly) return; |
174 | } | ||
162 | 175 | ||
163 | const release = await fetchRelease("nightly").catch((e) => { | 176 | const release = await fetchRelease("nightly").catch((e) => { |
164 | log.error(e); | 177 | log.error(e); |
@@ -202,7 +215,7 @@ async function bootstrapServer(config: Config, state: PersistentState): Promise< | |||
202 | ); | 215 | ); |
203 | } | 216 | } |
204 | 217 | ||
205 | log.debug("Using server binary at", path); | 218 | log.info("Using server binary at", path); |
206 | 219 | ||
207 | if (!isValidExecutable(path)) { | 220 | if (!isValidExecutable(path)) { |
208 | throw new Error(`Failed to execute ${path} --version`); | 221 | throw new Error(`Failed to execute ${path} --version`); |
@@ -261,13 +274,13 @@ async function getServer(config: Config, state: PersistentState): Promise<string | |||
261 | }; | 274 | }; |
262 | if (config.package.releaseTag === null) return "rust-analyzer"; | 275 | if (config.package.releaseTag === null) return "rust-analyzer"; |
263 | 276 | ||
264 | let binaryName: string | undefined = undefined; | 277 | let platform: string | undefined; |
265 | if (process.arch === "x64" || process.arch === "ia32") { | 278 | if (process.arch === "x64" || process.arch === "ia32") { |
266 | if (process.platform === "linux") binaryName = "rust-analyzer-linux"; | 279 | if (process.platform === "linux") platform = "linux"; |
267 | if (process.platform === "darwin") binaryName = "rust-analyzer-mac"; | 280 | if (process.platform === "darwin") platform = "mac"; |
268 | if (process.platform === "win32") binaryName = "rust-analyzer-windows.exe"; | 281 | if (process.platform === "win32") platform = "windows"; |
269 | } | 282 | } |
270 | if (binaryName === undefined) { | 283 | if (platform === undefined) { |
271 | vscode.window.showErrorMessage( | 284 | vscode.window.showErrorMessage( |
272 | "Unfortunately we don't ship binaries for your platform yet. " + | 285 | "Unfortunately we don't ship binaries for your platform yet. " + |
273 | "You need to manually clone rust-analyzer repository and " + | 286 | "You need to manually clone rust-analyzer repository and " + |
@@ -278,8 +291,8 @@ async function getServer(config: Config, state: PersistentState): Promise<string | |||
278 | ); | 291 | ); |
279 | return undefined; | 292 | return undefined; |
280 | } | 293 | } |
281 | 294 | const ext = platform === "windows" ? ".exe" : ""; | |
282 | const dest = path.join(config.globalStoragePath, binaryName); | 295 | const dest = path.join(config.globalStoragePath, `rust-analyzer-${platform}${ext}`); |
283 | const exists = await fs.stat(dest).then(() => true, () => false); | 296 | const exists = await fs.stat(dest).then(() => true, () => false); |
284 | if (!exists) { | 297 | if (!exists) { |
285 | await state.updateServerVersion(undefined); | 298 | await state.updateServerVersion(undefined); |
@@ -296,7 +309,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string | |||
296 | } | 309 | } |
297 | 310 | ||
298 | const release = await fetchRelease(config.package.releaseTag); | 311 | const release = await fetchRelease(config.package.releaseTag); |
299 | const artifact = release.assets.find(artifact => artifact.name === binaryName); | 312 | const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`); |
300 | assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); | 313 | assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); |
301 | 314 | ||
302 | // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error. | 315 | // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error. |
@@ -308,6 +321,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string | |||
308 | url: artifact.browser_download_url, | 321 | url: artifact.browser_download_url, |
309 | dest, | 322 | dest, |
310 | progressTitle: "Downloading rust-analyzer server", | 323 | progressTitle: "Downloading rust-analyzer server", |
324 | gunzip: true, | ||
311 | mode: 0o755 | 325 | mode: 0o755 |
312 | }); | 326 | }); |
313 | 327 | ||