Skip to content

Commit

Permalink
fix: allow referring from inline to panel chat (microsoft#196614)
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceerhl committed Oct 25, 2023
1 parent 2ca5d53 commit e685838
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import { MarkdownString } from 'vs/base/common/htmlContent';
import { MovingAverage } from 'vs/base/common/numbers';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
import { IModelDeltaDecoration } from 'vs/editor/common/model';
import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
import { chatAgentLeader, chatSubcommandLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes';

export const enum State {
CREATE_SESSION = 'CREATE_SESSION',
Expand Down Expand Up @@ -135,7 +137,8 @@ export class InlineChatController implements IEditorContribution {
@IContextKeyService contextKeyService: IContextKeyService,
@IAccessibilityService private readonly _accessibilityService: IAccessibilityService,
@IKeybindingService private readonly _keybindingService: IKeybindingService,
@IChatAccessibilityService private readonly _chatAccessibilityService: IChatAccessibilityService
@IChatAccessibilityService private readonly _chatAccessibilityService: IChatAccessibilityService,
@IChatAgentService private readonly _chatAgentService: IChatAgentService,
) {
this._ctxHasActiveRequest = CTX_INLINE_CHAT_HAS_ACTIVE_REQUEST.bindTo(contextKeyService);
this._ctxDidEdit = CTX_INLINE_CHAT_DID_EDIT.bindTo(contextKeyService);
Expand Down Expand Up @@ -531,7 +534,21 @@ export class InlineChatController implements IEditorContribution {
if (refer) {
this._log('[IE] seeing refer command, continuing outside editor', this._activeSession.provider.debugName);
this._editor.setSelection(this._activeSession.wholeRange.value);
this._instaService.invokeFunction(sendRequest, input);
let massagedInput = input;
if (input.startsWith(chatSubcommandLeader)) {
const withoutSubCommandLeader = input.slice(1);
const cts = new CancellationTokenSource();
this._sessionStore.add(cts);
for (const agent of this._chatAgentService.getAgents()) {
const commands = await agent.provideSlashCommands(cts.token);
if (commands.find((command) => withoutSubCommandLeader.startsWith(command.name))) {
massagedInput = `${chatAgentLeader}${agent.id} ${input}`;
break;
}
}
}
// if agent has a refer command, massage the input to include the agent name
this._instaService.invokeFunction(sendRequest, massagedInput);

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

0 comments on commit e685838

Please sign in to comment.