const newEnv = Object.assign({}, process.env);
Object.assign(newEnv, extraEnv);
- let cwd = undefined;
- if (workspace.kind === "Workspace Folder") {
- cwd = workspace.folder.fsPath;
- };
-
const run: lc.Executable = {
command: serverPath,
- options: { cwd, env: newEnv },
+ options: { env: newEnv },
};
const serverOptions: lc.ServerOptions = {
run,
throw new Error(message);
});
- const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
- if (workspaceFolder === undefined) {
+ if (vscode.workspace.workspaceFolders?.length === 0) {
const rustDocuments = vscode.workspace.textDocuments.filter(document => isRustDocument(document));
if (rustDocuments.length > 0) {
ctx = await Ctx.create(config, context, serverPath, { kind: 'Detached Files', files: rustDocuments });
// registers its `onDidChangeDocument` handler before us.
//
// This a horribly, horribly wrong way to deal with this problem.
- ctx = await Ctx.create(config, context, serverPath, { kind: "Workspace Folder", folder: workspaceFolder.uri });
- ctx.pushCleanup(activateTaskProvider(workspaceFolder, ctx.config));
+ ctx = await Ctx.create(config, context, serverPath, { kind: "Workspace Folder" });
+ ctx.pushCleanup(activateTaskProvider(ctx.config));
}
await initCommonContext(context, ctx);
}
class CargoTaskProvider implements vscode.TaskProvider {
- private readonly target: vscode.WorkspaceFolder;
private readonly config: Config;
- constructor(target: vscode.WorkspaceFolder, config: Config) {
- this.target = target;
+ constructor(config: Config) {
this.config = config;
}
];
const tasks: vscode.Task[] = [];
- for (const def of defs) {
- const vscodeTask = await buildCargoTask(this.target, { type: TASK_TYPE, command: def.command }, `cargo ${def.command}`, [def.command], this.config.cargoRunner);
- vscodeTask.group = def.group;
- tasks.push(vscodeTask);
+ for (const workspaceTarget of vscode.workspace.workspaceFolders || []) {
+ for (const def of defs) {
+ const vscodeTask = await buildCargoTask(workspaceTarget, { type: TASK_TYPE, command: def.command }, `cargo ${def.command}`, [def.command], this.config.cargoRunner);
+ vscodeTask.group = def.group;
+ tasks.push(vscodeTask);
+ }
}
return tasks;
if (definition.type === TASK_TYPE && definition.command) {
const args = [definition.command].concat(definition.args ?? []);
-
- return await buildCargoTask(this.target, definition, task.name, args, this.config.cargoRunner);
+ if (isWorkspaceFolder(task.scope)) {
+ return await buildCargoTask(task.scope, definition, task.name, args, this.config.cargoRunner);
+ }
}
return undefined;
}
}
+function isWorkspaceFolder(scope?: any): scope is vscode.WorkspaceFolder {
+ return (scope as vscode.WorkspaceFolder).name !== undefined;
+}
+
export async function buildCargoTask(
target: vscode.WorkspaceFolder,
definition: CargoTaskDefinition,
);
}
-export function activateTaskProvider(target: vscode.WorkspaceFolder, config: Config): vscode.Disposable {
- const provider = new CargoTaskProvider(target, config);
+export function activateTaskProvider(config: Config): vscode.Disposable {
+ const provider = new CargoTaskProvider(config);
return vscode.tasks.registerTaskProvider(TASK_TYPE, provider);
}