Skip to content

Commit b4015b6

Browse files
Merge #8995
8995: fix: Create tasks for all workspaces r=matklad a=SomeoneToIgnore Follow-up of #8955 (comment) Before: <img width="593" alt="image" src="https://user-images.githubusercontent.com/2690773/119575267-712b5300-bdbf-11eb-833c-f688f7a7dd0f.png"> After: <img width="643" alt="image" src="https://user-images.githubusercontent.com/2690773/119575273-74264380-bdbf-11eb-8283-a78bbcb7346e.png"> This is the first time I've used multiple workspaces feature in VSCode, but so far looks like * opening detached files works * run and debug lens work * Rust Analyzer: Run action works * run task works and now shows tasks for all workspaces * there are no platform-specific changes involved Co-authored-by: Kirill Bulatov <[email protected]>
2 parents 666fc1c + a05163d commit b4015b6

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

editors/code/src/client.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,9 @@ export function createClient(serverPath: string, workspace: Workspace, extraEnv:
3232
const newEnv = Object.assign({}, process.env);
3333
Object.assign(newEnv, extraEnv);
3434

35-
let cwd = undefined;
36-
if (workspace.kind === "Workspace Folder") {
37-
cwd = workspace.folder.fsPath;
38-
};
39-
4035
const run: lc.Executable = {
4136
command: serverPath,
42-
options: { cwd, env: newEnv },
37+
options: { env: newEnv },
4338
};
4439
const serverOptions: lc.ServerOptions = {
4540
run,

editors/code/src/ctx.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { ServerStatusParams } from './lsp_ext';
1010
export type Workspace =
1111
{
1212
kind: 'Workspace Folder';
13-
folder: vscode.Uri;
1413
}
1514
| {
1615
kind: 'Detached Files';

editors/code/src/main.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
4545
throw new Error(message);
4646
});
4747

48-
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
49-
if (workspaceFolder === undefined) {
48+
if (vscode.workspace.workspaceFolders?.length === 0) {
5049
const rustDocuments = vscode.workspace.textDocuments.filter(document => isRustDocument(document));
5150
if (rustDocuments.length > 0) {
5251
ctx = await Ctx.create(config, context, serverPath, { kind: 'Detached Files', files: rustDocuments });
@@ -58,8 +57,8 @@ async function tryActivate(context: vscode.ExtensionContext) {
5857
// registers its `onDidChangeDocument` handler before us.
5958
//
6059
// This a horribly, horribly wrong way to deal with this problem.
61-
ctx = await Ctx.create(config, context, serverPath, { kind: "Workspace Folder", folder: workspaceFolder.uri });
62-
ctx.pushCleanup(activateTaskProvider(workspaceFolder, ctx.config));
60+
ctx = await Ctx.create(config, context, serverPath, { kind: "Workspace Folder" });
61+
ctx.pushCleanup(activateTaskProvider(ctx.config));
6362
}
6463
await initCommonContext(context, ctx);
6564

editors/code/src/tasks.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ export interface CargoTaskDefinition extends vscode.TaskDefinition {
1717
}
1818

1919
class CargoTaskProvider implements vscode.TaskProvider {
20-
private readonly target: vscode.WorkspaceFolder;
2120
private readonly config: Config;
2221

23-
constructor(target: vscode.WorkspaceFolder, config: Config) {
24-
this.target = target;
22+
constructor(config: Config) {
2523
this.config = config;
2624
}
2725

@@ -40,10 +38,12 @@ class CargoTaskProvider implements vscode.TaskProvider {
4038
];
4139

4240
const tasks: vscode.Task[] = [];
43-
for (const def of defs) {
44-
const vscodeTask = await buildCargoTask(this.target, { type: TASK_TYPE, command: def.command }, `cargo ${def.command}`, [def.command], this.config.cargoRunner);
45-
vscodeTask.group = def.group;
46-
tasks.push(vscodeTask);
41+
for (const workspaceTarget of vscode.workspace.workspaceFolders || []) {
42+
for (const def of defs) {
43+
const vscodeTask = await buildCargoTask(workspaceTarget, { type: TASK_TYPE, command: def.command }, `cargo ${def.command}`, [def.command], this.config.cargoRunner);
44+
vscodeTask.group = def.group;
45+
tasks.push(vscodeTask);
46+
}
4747
}
4848

4949
return tasks;
@@ -58,14 +58,19 @@ class CargoTaskProvider implements vscode.TaskProvider {
5858

5959
if (definition.type === TASK_TYPE && definition.command) {
6060
const args = [definition.command].concat(definition.args ?? []);
61-
62-
return await buildCargoTask(this.target, definition, task.name, args, this.config.cargoRunner);
61+
if (isWorkspaceFolder(task.scope)) {
62+
return await buildCargoTask(task.scope, definition, task.name, args, this.config.cargoRunner);
63+
}
6364
}
6465

6566
return undefined;
6667
}
6768
}
6869

70+
function isWorkspaceFolder(scope?: any): scope is vscode.WorkspaceFolder {
71+
return (scope as vscode.WorkspaceFolder).name !== undefined;
72+
}
73+
6974
export async function buildCargoTask(
7075
target: vscode.WorkspaceFolder,
7176
definition: CargoTaskDefinition,
@@ -119,7 +124,7 @@ export async function buildCargoTask(
119124
);
120125
}
121126

122-
export function activateTaskProvider(target: vscode.WorkspaceFolder, config: Config): vscode.Disposable {
123-
const provider = new CargoTaskProvider(target, config);
127+
export function activateTaskProvider(config: Config): vscode.Disposable {
128+
const provider = new CargoTaskProvider(config);
124129
return vscode.tasks.registerTaskProvider(TASK_TYPE, provider);
125130
}

0 commit comments

Comments
 (0)