Skip to content

Commit be15710

Browse files
authored
Name of contributed prompt not showing (microsoft#269566)
1 parent 491e090 commit be15710

5 files changed

Lines changed: 35 additions & 14 deletions

File tree

src/vs/workbench/contrib/chat/browser/promptSyntax/promptCodingAgentActionOverlay.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import { ChatContextKeys } from '../../common/chatContextKeys.js';
1111
import { IRemoteCodingAgentsService } from '../../../remoteCodingAgents/common/remoteCodingAgentsService.js';
1212
import { localize } from '../../../../../nls.js';
1313
import { Button } from '../../../../../base/browser/ui/button/button.js';
14-
import { getPromptCommandName } from '../../common/promptSyntax/service/promptsServiceImpl.js';
1514
import { PROMPT_LANGUAGE_ID } from '../../common/promptSyntax/promptTypes.js';
1615
import { $ } from '../../../../../base/browser/dom.js';
16+
import { IPromptsService } from '../../common/promptSyntax/service/promptsService.js';
1717

1818
export class PromptCodingAgentActionOverlayWidget extends Disposable implements IOverlayWidget {
1919

@@ -27,7 +27,8 @@ export class PromptCodingAgentActionOverlayWidget extends Disposable implements
2727
private readonly _editor: ICodeEditor,
2828
@ICommandService private readonly _commandService: ICommandService,
2929
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
30-
@IRemoteCodingAgentsService private readonly _remoteCodingAgentService: IRemoteCodingAgentsService
30+
@IRemoteCodingAgentsService private readonly _remoteCodingAgentService: IRemoteCodingAgentsService,
31+
@IPromptsService private readonly _promptsService: IPromptsService,
3132
) {
3233
super();
3334

@@ -105,7 +106,7 @@ export class PromptCodingAgentActionOverlayWidget extends Disposable implements
105106
this._button.enabled = false;
106107
try {
107108
const promptContent = model.getValue();
108-
const promptName = getPromptCommandName(model.uri.path);
109+
const promptName = await this._promptsService.getPromptCommandName(model.uri);
109110

110111
const agents = this._remoteCodingAgentService.getAvailableAgents();
111112
const agent = agents[0]; // Use the first available agent

src/vs/workbench/contrib/chat/browser/promptSyntax/runPromptAction.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { KeybindingWeight } from '../../../../../platform/keybinding/common/keyb
2929
import { Action2, MenuId, registerAction2 } from '../../../../../platform/actions/common/actions.js';
3030
import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';
3131
import { IOpenerService } from '../../../../../platform/opener/common/opener.js';
32-
import { getPromptCommandName } from '../../common/promptSyntax/service/promptsServiceImpl.js';
32+
import { IPromptsService } from '../../common/promptSyntax/service/promptsService.js';
3333

3434
/**
3535
* Condition for the `Run Current Prompt` action.
@@ -134,6 +134,7 @@ abstract class RunPromptBaseAction extends Action2 {
134134
): Promise<IChatWidget | undefined> {
135135
const viewsService = accessor.get(IViewsService);
136136
const commandService = accessor.get(ICommandService);
137+
const promptsService = accessor.get(IPromptsService);
137138

138139
resource ||= getActivePromptFileUri(accessor);
139140
assertDefined(
@@ -147,7 +148,7 @@ abstract class RunPromptBaseAction extends Action2 {
147148

148149
const widget = await showChatView(viewsService);
149150
if (widget) {
150-
widget.setInput(`/${getPromptCommandName(resource.path)}`);
151+
widget.setInput(`/${await promptsService.getPromptCommandName(resource)}`);
151152
// submit the prompt immediately
152153
await widget.acceptInput();
153154
}
@@ -209,6 +210,7 @@ class RunSelectedPromptAction extends Action2 {
209210
const viewsService = accessor.get(IViewsService);
210211
const commandService = accessor.get(ICommandService);
211212
const instaService = accessor.get(IInstantiationService);
213+
const promptsService = accessor.get(IPromptsService);
212214

213215
const pickers = instaService.createInstance(PromptFilePickers);
214216

@@ -232,7 +234,7 @@ class RunSelectedPromptAction extends Action2 {
232234

233235
const widget = await showChatView(viewsService);
234236
if (widget) {
235-
widget.setInput(`/${getPromptCommandName(promptFile.path)}`);
237+
widget.setInput(`/${await promptsService.getPromptCommandName(promptFile)}`);
236238
// submit the prompt immediately
237239
await widget.acceptInput();
238240
widget.focusInput();

src/vs/workbench/contrib/chat/common/promptSyntax/service/promptsService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ export interface IPromptsService extends IDisposable {
192192
*/
193193
findPromptSlashCommands(): Promise<IChatPromptSlashCommand[]>;
194194

195+
/**
196+
* Returns the prompt command name for the given URI.
197+
*/
198+
getPromptCommandName(uri: URI): Promise<string>;
199+
195200
/**
196201
* Event that is triggered when the list of custom chat modes changes.
197202
*/

src/vs/workbench/contrib/chat/common/promptSyntax/service/promptsServiceImpl.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { ResourceMap } from '../../../../../../base/common/map.js';
2828
import { CancellationError } from '../../../../../../base/common/errors.js';
2929
import { OffsetRange } from '../../../../../../editor/common/core/ranges/offsetRange.js';
3030
import { IChatModeInstructions, IVariableReference } from '../../chatModes.js';
31-
import { dirname } from '../../../../../../base/common/resources.js';
31+
import { dirname, isEqual } from '../../../../../../base/common/resources.js';
3232
import { IExtensionDescription } from '../../../../../../platform/extensions/common/extensions.js';
3333
import { Delayer } from '../../../../../../base/common/async.js';
3434

@@ -190,23 +190,32 @@ export class PromptsService extends Disposable implements IPromptsService {
190190
return data.promptPath.uri;
191191
}
192192

193-
const files = await this.listPromptFiles(PromptsType.prompt, CancellationToken.None);
193+
const promptPaths = await this.listPromptFiles(PromptsType.prompt, CancellationToken.None);
194194
const command = data.command;
195-
const result = files.find(file => getPromptCommandName(file.uri.path) === command);
195+
const result = promptPaths.find(promptPath => getCommandNameFromPromptPath(promptPath) === command);
196196
if (result) {
197197
return result.uri;
198198
}
199-
const textModel = this.modelService.getModels().find(model => model.getLanguageId() === PROMPT_LANGUAGE_ID && getPromptCommandName(model.uri.path) === command);
199+
const textModel = this.modelService.getModels().find(model => model.getLanguageId() === PROMPT_LANGUAGE_ID && getCommandNameFromURI(model.uri) === command);
200200
if (textModel) {
201201
return textModel.uri;
202202
}
203203
return undefined;
204204
}
205205

206+
public async getPromptCommandName(uri: URI): Promise<string> {
207+
const promptPaths = await this.listPromptFiles(PromptsType.prompt, CancellationToken.None);
208+
const promptPath = promptPaths.find(promptPath => isEqual(promptPath.uri, uri));
209+
if (!promptPath) {
210+
return getCommandNameFromURI(uri);
211+
}
212+
return getCommandNameFromPromptPath(promptPath);
213+
}
214+
206215
public async findPromptSlashCommands(): Promise<IChatPromptSlashCommand[]> {
207216
const promptFiles = await this.listPromptFiles(PromptsType.prompt, CancellationToken.None);
208217
return promptFiles.map(promptPath => {
209-
const command = getPromptCommandName(promptPath.uri.path);
218+
const command = getCommandNameFromPromptPath(promptPath);
210219
return {
211220
command,
212221
detail: localize('prompt.file.detail', 'Prompt file: {0}', this.labelService.getUriLabel(promptPath.uri, { relative: true })),
@@ -325,9 +334,12 @@ export class PromptsService extends Disposable implements IPromptsService {
325334
}
326335
}
327336

328-
export function getPromptCommandName(path: string): string {
329-
const name = basename(path, PROMPT_FILE_EXTENSION);
330-
return name;
337+
function getCommandNameFromPromptPath(promptPath: IPromptPath): string {
338+
return promptPath.name ?? getCommandNameFromURI(promptPath.uri);
339+
}
340+
341+
function getCommandNameFromURI(uri: URI): string {
342+
return basename(uri.fsPath, PROMPT_FILE_EXTENSION);
331343
}
332344

333345
export class ChatModeUpdateTracker extends Disposable {

src/vs/workbench/contrib/chat/test/common/mockPromptsService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class MockPromptsService implements IPromptsService {
3838
asPromptSlashCommand(_command: string): any { return undefined; }
3939
resolvePromptSlashCommand(_data: any, _token: CancellationToken): Promise<any> { throw new Error('Not implemented'); }
4040
findPromptSlashCommands(): Promise<any[]> { throw new Error('Not implemented'); }
41+
getPromptCommandName(uri: URI): Promise<string> { throw new Error('Not implemented'); }
4142
parse(_uri: URI, _type: any, _token: CancellationToken): Promise<any> { throw new Error('Not implemented'); }
4243
parseNew(_uri: URI, _token: CancellationToken): Promise<any> { throw new Error('Not implemented'); }
4344
getPromptFileType(_resource: URI): any { return undefined; }

0 commit comments

Comments
 (0)