Skip to content

Commit 39f6d1b

Browse files
authored
fix #256516 (#284)
1 parent f88b90e commit 39f6d1b

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

src/extension/tools/node/newWorkspace/createAndRunTaskTool.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { joinPath } from '../../../../util/vs/base/common/resources';
1818
import { LanguageModelTextPart, LanguageModelToolResult, MarkdownString, Uri } from '../../../../vscodeTypes';
1919
import { ToolName } from '../../common/toolNames';
2020
import { ToolRegistry } from '../../common/toolsRegistry';
21+
import { getTaskRepresentation } from '../toolUtils.task';
2122

2223
interface ICreateAndRunTaskToolInput {
2324
workspaceFolder: string;
@@ -107,6 +108,23 @@ export class CreateAndRunTaskTool implements vscode.LanguageModelTool<ICreateAnd
107108
confirmationMessages: undefined
108109
};
109110
}
111+
if (this.tasksService.hasTask(workspaceFolder, task)) {
112+
const position = workspaceFolder && task && await this.tasksService.getTaskConfigPosition(workspaceFolder, task);
113+
const link = (s: string) => position ? `[${s}](${position.uri.toString()}#${position.range.startLineNumber}-${position.range.endLineNumber})` : s;
114+
const trustedMark = (value: string) => {
115+
const s = new MarkdownString(value);
116+
s.isTrusted = true;
117+
return s;
118+
};
119+
120+
return {
121+
invocationMessage: trustedMark(l10n.t`Running ${link(task.label)}`),
122+
pastTenseMessage: trustedMark(task?.isBackground ? l10n.t`Started ${link(task.label)}` : l10n.t`Ran ${link(task.label)}`),
123+
confirmationMessages: task && task.group !== 'build'
124+
? { title: l10n.t`Allow task run?`, message: trustedMark(l10n.t`Allow Copilot to run the \`${task.type}\` task ${link(`\`${getTaskRepresentation(task)}\``)}?`) }
125+
: undefined
126+
};
127+
}
110128
try {
111129
await this.fileSystemService.stat(Uri.parse(tasksFilePath));
112130
return {
@@ -125,7 +143,6 @@ export class CreateAndRunTaskTool implements vscode.LanguageModelTool<ICreateAnd
125143
)
126144
}
127145
};
128-
129146
}
130147
}
131148
}

src/extension/tools/node/runTaskTool.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { CancellationToken } from '../../../util/vs/base/common/cancellation';
1818
import { ChatLocation, LanguageModelTextPart, LanguageModelToolResult, MarkdownString } from '../../../vscodeTypes';
1919
import { ToolName } from '../common/toolNames';
2020
import { ToolRegistry } from '../common/toolsRegistry';
21+
import { getTaskRepresentation } from './toolUtils.task';
2122

2223
interface IRunTaskToolInput {
2324
id: string;
@@ -173,22 +174,11 @@ class RunTaskTool implements vscode.LanguageModelTool<IRunTaskToolInput> {
173174
invocationMessage: trustedMark(l10n.t`Running ${taskLabel ?? link(options.input.id)}`),
174175
pastTenseMessage: trustedMark(task?.isBackground ? l10n.t`Started ${link(taskLabel ?? options.input.id)}` : l10n.t`Ran ${link(taskLabel ?? options.input.id)}`),
175176
confirmationMessages: task && task.group !== 'build'
176-
? { title: l10n.t`Allow task run?`, message: trustedMark(l10n.t`Allow Copilot to run the \`${task.type}\` task ${link(`\`${this.getTaskRepresentation(task)}\``)}?`) }
177+
? { title: l10n.t`Allow task run?`, message: trustedMark(l10n.t`Allow Copilot to run the \`${task.type}\` task ${link(`\`${getTaskRepresentation(task)}\``)}?`) }
177178
: undefined
178179
};
179180
}
180181

181-
private getTaskRepresentation(task: vscode.TaskDefinition): string {
182-
if ('label' in task) {
183-
return task.label;
184-
} else if ('script' in task) {
185-
return task.script;
186-
} else if ('command' in task) {
187-
return task.command;
188-
}
189-
return '';
190-
}
191-
192182
private getTaskDefinition(input: IRunTaskToolInput) {
193183
const idx = input.id.indexOf(': ');
194184
const taskType = input.id.substring(0, idx);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
import type * as vscode from 'vscode';
6+
7+
export function getTaskRepresentation(task: vscode.TaskDefinition): string {
8+
if ('label' in task) {
9+
return task.label;
10+
} else if ('script' in task) {
11+
return task.script;
12+
} else if ('command' in task) {
13+
return task.command;
14+
}
15+
return '';
16+
}

0 commit comments

Comments
 (0)