ensure terminal agent is registered

This commit is contained in:
meganrogge
2024-02-13 12:24:10 -06:00
parent a9cfba2875
commit 1617ebe843
3 changed files with 18 additions and 1 deletions
@@ -43,6 +43,7 @@ export const enum TerminalContextKeyStrings {
ChatVisible = 'terminalChatVisible',
ChatActiveRequest = 'terminalChatActiveRequest',
ChatInputHasText = 'terminalChatInputHasText',
ChatAgentRegistered = 'terminalChatAgentRegistered',
}
export namespace TerminalContextKeys {
@@ -175,4 +176,7 @@ export namespace TerminalContextKeys {
/** Whether the chat input has text */
export const chatInputHasText = new RawContextKey<boolean>(TerminalContextKeyStrings.ChatInputHasText, false, localize('chatInputHasTextContextKey', "Whether the chat input has text."));
/** Whether the terminal chat agent has been registered */
export const chatAgentRegistered = new RawContextKey<boolean>(TerminalContextKeyStrings.ChatAgentRegistered, false, localize('chatAgentRegisteredContextKey', "Whether the terminal chat agent has been registered."));
}
@@ -72,7 +72,8 @@ registerActiveXtermAction({
precondition: ContextKeyExpr.and(
ContextKeyExpr.has(`config.${TerminalSettingId.ExperimentalInlineChat}`),
ContextKeyExpr.or(TerminalContextKeys.processSupported, TerminalContextKeys.terminalHasBeenCreated),
TerminalContextKeys.chatRequestActive.negate()
TerminalContextKeys.chatRequestActive.negate(),
TerminalContextKeys.chatAgentRegistered
),
icon: Codicon.send,
keybinding: {
@@ -103,6 +104,7 @@ registerActiveXtermAction({
precondition: ContextKeyExpr.and(
ContextKeyExpr.has(`config.${TerminalSettingId.ExperimentalInlineChat}`),
TerminalContextKeys.chatRequestActive,
TerminalContextKeys.chatAgentRegistered
),
icon: Codicon.debugStop,
menu: {
@@ -41,6 +41,7 @@ export class TerminalChatController extends Disposable implements ITerminalContr
get chatWidget(): TerminalChatWidget | undefined { return this._chatWidget?.value; }
private readonly _ctxHasActiveRequest!: IContextKey<boolean>;
private readonly _ctxHasTerminalAgent!: IContextKey<boolean>;
private _cancellationTokenSource!: CancellationTokenSource;
@@ -60,6 +61,16 @@ export class TerminalChatController extends Disposable implements ITerminalContr
return;
}
this._ctxHasActiveRequest = TerminalContextKeys.chatRequestActive.bindTo(this._contextKeyService);
this._ctxHasTerminalAgent = TerminalContextKeys.chatAgentRegistered.bindTo(this._contextKeyService);
if (!this._chatAgentService.hasAgent('terminal')) {
this._register(this._chatAgentService.onDidChangeAgents(() => {
if (this._chatAgentService.getAgent('terminal')) {
this._ctxHasTerminalAgent.set(true);
}
}));
} else {
this._ctxHasTerminalAgent.set(true);
}
this._cancellationTokenSource = new CancellationTokenSource();
}