diff options
Diffstat (limited to 'editors/code/src')
-rw-r--r-- | editors/code/src/commands.ts | 4 | ||||
-rw-r--r-- | editors/code/src/lsp_ext.ts | 2 | ||||
-rw-r--r-- | editors/code/src/main.ts | 28 |
3 files changed, 23 insertions, 11 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 0e78f5101..19a9c2a0d 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts | |||
@@ -330,8 +330,8 @@ export function expandMacro(ctx: Ctx): Cmd { | |||
330 | }; | 330 | }; |
331 | } | 331 | } |
332 | 332 | ||
333 | export function collectGarbage(ctx: Ctx): Cmd { | 333 | export function reloadWorkspace(ctx: Ctx): Cmd { |
334 | return async () => ctx.client.sendRequest(ra.collectGarbage, null); | 334 | return async () => ctx.client.sendRequest(ra.reloadWorkspace, null); |
335 | } | 335 | } |
336 | 336 | ||
337 | export function showReferences(ctx: Ctx): Cmd { | 337 | export function showReferences(ctx: Ctx): Cmd { |
diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index fdb99956b..981b6f40e 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts | |||
@@ -6,7 +6,7 @@ import * as lc from "vscode-languageclient"; | |||
6 | 6 | ||
7 | export const analyzerStatus = new lc.RequestType<null, string, void>("rust-analyzer/analyzerStatus"); | 7 | export const analyzerStatus = new lc.RequestType<null, string, void>("rust-analyzer/analyzerStatus"); |
8 | 8 | ||
9 | export const collectGarbage = new lc.RequestType<null, null, void>("rust-analyzer/collectGarbage"); | 9 | export const reloadWorkspace = new lc.RequestType<null, null, void>("rust-analyzer/reloadWorkspace"); |
10 | 10 | ||
11 | export interface SyntaxTreeParams { | 11 | export interface SyntaxTreeParams { |
12 | textDocument: lc.TextDocumentIdentifier; | 12 | textDocument: lc.TextDocumentIdentifier; |
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 5ceab8b44..a1521a93b 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 | // |
@@ -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,7 @@ 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('reloadWorkspace', commands.reloadWorkspace); |
92 | ctx.registerCommand('matchingBrace', commands.matchingBrace); | 100 | ctx.registerCommand('matchingBrace', commands.matchingBrace); |
93 | ctx.registerCommand('joinLines', commands.joinLines); | 101 | ctx.registerCommand('joinLines', commands.joinLines); |
94 | ctx.registerCommand('parentModule', commands.parentModule); | 102 | ctx.registerCommand('parentModule', commands.parentModule); |
@@ -152,13 +160,17 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi | |||
152 | return; | 160 | return; |
153 | }; | 161 | }; |
154 | 162 | ||
155 | const lastCheck = state.lastCheck; | ||
156 | const now = Date.now(); | 163 | const now = Date.now(); |
164 | if (config.package.releaseTag === NIGHTLY_TAG) { | ||
165 | // Check if we should poll github api for the new nightly version | ||
166 | // if we haven't done it during the past hour | ||
167 | const lastCheck = state.lastCheck; | ||
157 | 168 | ||
158 | const anHour = 60 * 60 * 1000; | 169 | const anHour = 60 * 60 * 1000; |
159 | const shouldDownloadNightly = state.releaseId === undefined || (now - (lastCheck ?? 0)) > anHour; | 170 | const shouldCheckForNewNightly = state.releaseId === undefined || (now - (lastCheck ?? 0)) > anHour; |
160 | 171 | ||
161 | if (!shouldDownloadNightly) return; | 172 | if (!shouldCheckForNewNightly) return; |
173 | } | ||
162 | 174 | ||
163 | const release = await fetchRelease("nightly").catch((e) => { | 175 | const release = await fetchRelease("nightly").catch((e) => { |
164 | log.error(e); | 176 | log.error(e); |