Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ export interface ITaskEntry {
readonly script?: string;
readonly type?: string;
readonly command?: string;
readonly args?: CommandString[];
readonly inSessions?: boolean;
readonly windows?: { command?: string };
readonly osx?: { command?: string };
readonly linux?: { command?: string };
readonly windows?: { command?: string; args?: CommandString[] };
readonly osx?: { command?: string; args?: CommandString[] };
readonly linux?: { command?: string; args?: CommandString[] };
readonly [key: string]: unknown;
}

Expand Down Expand Up @@ -293,21 +294,42 @@ export class SessionsConfigurationService extends Disposable implements ISession
if (!task.script) {
return undefined;
}
if (task.path) {
return `npm --prefix ${task.path} run ${task.script}`;
}
return `npm run ${task.script}`;
const base = task.path
? `npm --prefix ${task.path} run ${task.script}`
: `npm run ${task.script}`;
return this._appendArgs(base, task.args);
}

let command: string | undefined;
let platformArgs: CommandString[] | undefined;

if (isWindows && task.windows?.command) {
return task.windows.command;
command = task.windows.command;
platformArgs = task.windows.args;
} else if (isMacintosh && task.osx?.command) {
command = task.osx.command;
platformArgs = task.osx.args;
} else if (!isWindows && !isMacintosh && task.linux?.command) {
command = task.linux.command;
platformArgs = task.linux.args;
} else {
command = task.command;
Comment thread
benibenj marked this conversation as resolved.
Resolved
}
if (isMacintosh && task.osx?.command) {
return task.osx.command;

// Platform-specific args override task-level args
const args = platformArgs ?? task.args;
return this._appendArgs(command, args);
}

private _appendArgs(command: string | undefined, args: CommandString[] | undefined): string | undefined {
if (!command) {
return undefined;
}
if (!isWindows && !isMacintosh && task.linux?.command) {
return task.linux.command;
if (!args || args.length === 0) {
return command;
}
return task.command;
const resolvedArgs = args.map(a => CommandString.value(a)).join(' ');
return `${command} ${resolvedArgs}`;
}

private _ensureFileWatch(folder: URI): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,54 @@ suite('SessionsConfigurationService', () => {
assert.strictEqual(createdTerminals[1].name, 'test');
});

test('runTask appends args to shell command', async () => {
const session = makeSession({ worktree: worktreeUri, repository: repoUri });
const task: ITaskEntry = { label: 'build', type: 'shell', command: 'dotnet', args: ['build', '--configuration', 'Release'], inSessions: true };

await service.runTask(task, session);

assert.strictEqual(sentCommands.length, 1);
assert.strictEqual(sentCommands[0].command, 'dotnet build --configuration Release');
});

test('runTask appends args to npm task', async () => {
const session = makeSession({ worktree: worktreeUri, repository: repoUri });
const task: ITaskEntry = { label: 'test', type: 'npm', script: 'test', args: ['--', '--coverage'], inSessions: true };

await service.runTask(task, session);

assert.strictEqual(sentCommands.length, 1);
assert.strictEqual(sentCommands[0].command, 'npm run test -- --coverage');
});

test('runTask resolves CommandString objects in args', async () => {
const session = makeSession({ worktree: worktreeUri, repository: repoUri });
const task: ITaskEntry = {
label: 'build', type: 'shell', command: 'gcc',
args: [
{ value: '-o', quoting: 'escape' as const },
'output.exe',
'main.c',
],
inSessions: true
};

await service.runTask(task, session);

assert.strictEqual(sentCommands.length, 1);
assert.strictEqual(sentCommands[0].command, 'gcc -o output.exe main.c');
});

test('runTask sends only command when args is empty', async () => {
const session = makeSession({ worktree: worktreeUri, repository: repoUri });
const task: ITaskEntry = { label: 'build', type: 'shell', command: 'make', args: [], inSessions: true };

await service.runTask(task, session);

assert.strictEqual(sentCommands.length, 1);
assert.strictEqual(sentCommands[0].command, 'make');
});

test('runTask creates different terminals for same command in different worktrees', async () => {
const wt1 = URI.parse('file:///worktree1');
const wt2 = URI.parse('file:///worktree2');
Expand Down
Loading