Skip to content

Commit e685838

Browse files
authored
fix: allow referring from inline to panel chat (microsoft#196614)
1 parent 2ca5d53 commit e685838

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import { MarkdownString } from 'vs/base/common/htmlContent';
4141
import { MovingAverage } from 'vs/base/common/numbers';
4242
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
4343
import { IModelDeltaDecoration } from 'vs/editor/common/model';
44+
import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
45+
import { chatAgentLeader, chatSubcommandLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes';
4446

4547
export const enum State {
4648
CREATE_SESSION = 'CREATE_SESSION',
@@ -135,7 +137,8 @@ export class InlineChatController implements IEditorContribution {
135137
@IContextKeyService contextKeyService: IContextKeyService,
136138
@IAccessibilityService private readonly _accessibilityService: IAccessibilityService,
137139
@IKeybindingService private readonly _keybindingService: IKeybindingService,
138-
@IChatAccessibilityService private readonly _chatAccessibilityService: IChatAccessibilityService
140+
@IChatAccessibilityService private readonly _chatAccessibilityService: IChatAccessibilityService,
141+
@IChatAgentService private readonly _chatAgentService: IChatAgentService,
139142
) {
140143
this._ctxHasActiveRequest = CTX_INLINE_CHAT_HAS_ACTIVE_REQUEST.bindTo(contextKeyService);
141144
this._ctxDidEdit = CTX_INLINE_CHAT_DID_EDIT.bindTo(contextKeyService);
@@ -531,7 +534,21 @@ export class InlineChatController implements IEditorContribution {
531534
if (refer) {
532535
this._log('[IE] seeing refer command, continuing outside editor', this._activeSession.provider.debugName);
533536
this._editor.setSelection(this._activeSession.wholeRange.value);
534-
this._instaService.invokeFunction(sendRequest, input);
537+
let massagedInput = input;
538+
if (input.startsWith(chatSubcommandLeader)) {
539+
const withoutSubCommandLeader = input.slice(1);
540+
const cts = new CancellationTokenSource();
541+
this._sessionStore.add(cts);
542+
for (const agent of this._chatAgentService.getAgents()) {
543+
const commands = await agent.provideSlashCommands(cts.token);
544+
if (commands.find((command) => withoutSubCommandLeader.startsWith(command.name))) {
545+
massagedInput = `${chatAgentLeader}${agent.id} ${input}`;
546+
break;
547+
}
548+
}
549+
}
550+
// if agent has a refer command, massage the input to include the agent name
551+
this._instaService.invokeFunction(sendRequest, massagedInput);
535552

536553
if (!this._activeSession.lastExchange) {
537554
// DONE when there wasn't any exchange yet. We used the inline chat only as trampoline

0 commit comments

Comments
 (0)