From 768aa4259fce15f313042892739ed4d8b7e518b4 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 30 Mar 2020 18:12:22 +0100 Subject: Add basic task support This adds basic support for running `cargo build`, `cargo run`, etc. --- editors/code/src/main.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'editors/code/src/main.ts') diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index a46dbde33..40701e4f5 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -13,6 +13,7 @@ import { log, assert } from './util'; import { PersistentState } from './persistent_state'; import { fetchRelease, download } from './net'; import { spawnSync } from 'child_process'; +import { activateTaskProvider } from './tasks'; let ctx: Ctx | undefined; @@ -41,11 +42,13 @@ export async function activate(context: vscode.ExtensionContext) { const state = new PersistentState(context.globalState); const serverPath = await bootstrap(config, state); + const workspaceFolder = vscode.workspace.workspaceFolders?.[0] ?? null; + // Note: we try to start the server before we activate type hints so that it // registers its `onDidChangeDocument` handler before us. // // This a horribly, horribly wrong way to deal with this problem. - ctx = await Ctx.create(config, context, serverPath); + ctx = await Ctx.create(config, context, serverPath, workspaceFolder); // Commands which invokes manually via command palette, shortcut, etc. @@ -85,6 +88,10 @@ export async function activate(context: vscode.ExtensionContext) { ctx.registerCommand('applySourceChange', commands.applySourceChange); ctx.registerCommand('selectAndApplySourceChange', commands.selectAndApplySourceChange); + if (workspaceFolder !== null) { + ctx.pushCleanup(activateTaskProvider(workspaceFolder)); + } + activateStatusDisplay(ctx); if (!ctx.config.highlightingSemanticTokens) { -- cgit v1.2.3 From a781a58fe2cefefbf9bf505247df78fd750a8f13 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 31 Mar 2020 09:05:22 +0100 Subject: Throw error if no folder is opened --- editors/code/src/main.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'editors/code/src/main.ts') diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 40701e4f5..ee6e712a4 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -42,7 +42,12 @@ export async function activate(context: vscode.ExtensionContext) { const state = new PersistentState(context.globalState); const serverPath = await bootstrap(config, state); - const workspaceFolder = vscode.workspace.workspaceFolders?.[0] ?? null; + const workspaceFolder = vscode.workspace.workspaceFolders?.[0]; + if (workspaceFolder === undefined) { + const err = "Cannot activate rust-analyzer when no folder is opened"; + void vscode.window.showErrorMessage(err); + throw new Error(err); + } // Note: we try to start the server before we activate type hints so that it // registers its `onDidChangeDocument` handler before us. -- cgit v1.2.3 From 9ef1e9efc6039c9299cbb866118ff92cb4467202 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 31 Mar 2020 09:11:22 +0100 Subject: Remove unnecessary null check --- editors/code/src/main.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'editors/code/src/main.ts') diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index ee6e712a4..c1e2b97c3 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -93,9 +93,7 @@ export async function activate(context: vscode.ExtensionContext) { ctx.registerCommand('applySourceChange', commands.applySourceChange); ctx.registerCommand('selectAndApplySourceChange', commands.selectAndApplySourceChange); - if (workspaceFolder !== null) { - ctx.pushCleanup(activateTaskProvider(workspaceFolder)); - } + ctx.pushCleanup(activateTaskProvider(workspaceFolder)); activateStatusDisplay(ctx); -- cgit v1.2.3 From 3eb45b99223ae6a708d82c52d656c697bc993c3b Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 31 Mar 2020 10:23:18 +0100 Subject: Pass string instread of WorkspaceFolder --- editors/code/src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors/code/src/main.ts') diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index c1e2b97c3..7ba16120c 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -53,7 +53,7 @@ export async function activate(context: vscode.ExtensionContext) { // registers its `onDidChangeDocument` handler before us. // // This a horribly, horribly wrong way to deal with this problem. - ctx = await Ctx.create(config, context, serverPath, workspaceFolder); + ctx = await Ctx.create(config, context, serverPath, workspaceFolder.uri.fsPath); // Commands which invokes manually via command palette, shortcut, etc. -- cgit v1.2.3