Skip to content

Commit aed6bd7

Browse files
committed
Move findExecutable to extension host
Part of microsoft#101073
1 parent a9936dd commit aed6bd7

6 files changed

Lines changed: 27 additions & 9 deletions

File tree

src/vs/workbench/api/browser/mainThreadTask.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,9 @@ export class MainThreadTask implements MainThreadTaskShape {
668668
},
669669
getDefaultShellAndArgs: (): Promise<{ shell: string, args: string[] | string | undefined }> => {
670670
return Promise.resolve(this._proxy.$getDefaultShellAndArgs());
671+
},
672+
findExecutable: (command: string, cwd?: string, paths?: string[]): Promise<string | undefined> => {
673+
return this._proxy.$findExecutable(command, cwd, paths);
671674
}
672675
});
673676
}

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,7 @@ export interface ExtHostTaskShape {
14511451
$resolveVariables(workspaceFolder: UriComponents, toResolve: { process?: { name: string; cwd?: string; }, variables: string[]; }): Promise<{ process?: string; variables: { [key: string]: string; }; }>;
14521452
$getDefaultShellAndArgs(): Thenable<{ shell: string, args: string[] | string | undefined; }>;
14531453
$jsonTasksSupported(): Thenable<boolean>;
1454+
$findExecutable(command: string, cwd?: string, paths?: string[]): Promise<string | undefined>;
14541455
}
14551456

14561457
export interface IBreakpointDto {

src/vs/workbench/api/common/extHostTask.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,9 @@ export abstract class ExtHostTaskBase implements ExtHostTaskShape, IExtHostTask
679679
}
680680
}
681681

682-
public abstract async $jsonTasksSupported(): Promise<boolean>;
682+
public abstract $jsonTasksSupported(): Promise<boolean>;
683+
684+
public abstract $findExecutable(command: string, cwd?: string | undefined, paths?: string[] | undefined): Promise<string | undefined>;
683685
}
684686

685687
export class WorkerExtHostTask extends ExtHostTaskBase {
@@ -775,6 +777,10 @@ export class WorkerExtHostTask extends ExtHostTaskBase {
775777
public async $jsonTasksSupported(): Promise<boolean> {
776778
return false;
777779
}
780+
781+
public async $findExecutable(command: string, cwd?: string | undefined, paths?: string[] | undefined): Promise<string | undefined> {
782+
return undefined;
783+
}
778784
}
779785

780786
export const IExtHostTask = createDecorator<IExtHostTask>('IExtHostTask');

src/vs/workbench/api/node/extHostTask.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,8 @@ export class ExtHostTask extends ExtHostTaskBase {
195195
public async $jsonTasksSupported(): Promise<boolean> {
196196
return true;
197197
}
198+
199+
public async $findExecutable(command: string, cwd?: string, paths?: string[]): Promise<string> {
200+
return win32.findExecutable(command, cwd, paths);
201+
}
198202
}

src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -496,12 +496,15 @@ export class TerminalTaskSystem implements ITaskSystem {
496496
}
497497
}
498498

499-
private resolveAndFindExecutable(workspaceFolder: IWorkspaceFolder | undefined, task: CustomTask | ContributedTask, cwd: string | undefined, envPath: string | undefined): Promise<string> {
500-
return this.findExecutable(
501-
this.configurationResolverService.resolve(workspaceFolder, CommandString.value(task.command.name!)),
502-
cwd ? this.configurationResolverService.resolve(workspaceFolder, cwd) : undefined,
503-
envPath ? envPath.split(path.delimiter).map(p => this.configurationResolverService.resolve(workspaceFolder, p)) : undefined
504-
);
499+
private async resolveAndFindExecutable(systemInfo: TaskSystemInfo | undefined, workspaceFolder: IWorkspaceFolder | undefined, task: CustomTask | ContributedTask, cwd: string | undefined, envPath: string | undefined): Promise<string> {
500+
const command = this.configurationResolverService.resolve(workspaceFolder, CommandString.value(task.command.name!));
501+
cwd = cwd ? this.configurationResolverService.resolve(workspaceFolder, cwd) : undefined;
502+
const paths = envPath ? envPath.split(path.delimiter).map(p => this.configurationResolverService.resolve(workspaceFolder, p)) : undefined;
503+
let foundExecutable = await systemInfo?.findExecutable(command, cwd, paths);
504+
if (!foundExecutable) {
505+
foundExecutable = await this.findExecutable(command, cwd, paths);
506+
}
507+
return foundExecutable;
505508
}
506509

507510
private findUnresolvedVariables(variables: Set<string>, alreadyResolved: Map<string, string>): Set<string> {
@@ -562,7 +565,7 @@ export class TerminalTaskSystem implements ITaskSystem {
562565
if (isProcess) {
563566
let process = CommandString.value(task.command.name!);
564567
if (taskSystemInfo.platform === Platform.Platform.Windows) {
565-
process = await this.resolveAndFindExecutable(workspaceFolder, task, cwd, envPath);
568+
process = await this.resolveAndFindExecutable(taskSystemInfo, workspaceFolder, task, cwd, envPath);
566569
}
567570
resolved.variables.set(TerminalTaskSystem.ProcessVarName, process);
568571
}
@@ -581,7 +584,7 @@ export class TerminalTaskSystem implements ITaskSystem {
581584
if (isProcess) {
582585
let processVarValue: string;
583586
if (Platform.isWindows) {
584-
processVarValue = await this.resolveAndFindExecutable(workspaceFolder, task, cwd, envPath);
587+
processVarValue = await this.resolveAndFindExecutable(taskSystemInfo, workspaceFolder, task, cwd, envPath);
585588
} else {
586589
processVarValue = this.configurationResolverService.resolve(workspaceFolder, CommandString.value(task.command.name!));
587590
}

src/vs/workbench/contrib/tasks/common/taskSystem.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export interface TaskSystemInfo {
121121
uriProvider: (this: void, path: string) => URI;
122122
resolveVariables(workspaceFolder: IWorkspaceFolder, toResolve: ResolveSet, target: ConfigurationTarget): Promise<ResolvedVariables>;
123123
getDefaultShellAndArgs(): Promise<{ shell: string, args: string[] | string | undefined }>;
124+
findExecutable(command: string, cwd?: string, paths?: string[]): Promise<string | undefined>;
124125
}
125126

126127
export interface TaskSystemInfoResolver {

0 commit comments

Comments
 (0)