Skip to content

Commit 709aafe

Browse files
authored
lockToCodingAgent earlier (microsoft#258706)
* lockToCodingAgent earlier * remove unneeded chatInputState
1 parent 20724f7 commit 709aafe

File tree

4 files changed

+21
-45
lines changed

4 files changed

+21
-45
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export interface IChatWidget {
227227
waitForReady(): Promise<void>;
228228
getViewState(): IChatViewState;
229229
togglePaused(): void;
230-
lockToCodingAgent(name: string): void;
230+
lockToCodingAgent(name: string, displayName: string): void;
231231

232232
delegateScrollFromMouseWheelEvent(event: IMouseWheelEvent): void;
233233
}

src/vs/workbench/contrib/chat/browser/chatEditor.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,32 +121,33 @@ export class ChatEditor extends EditorPane {
121121
override async setInput(input: ChatEditorInput, options: IChatEditorOptions | undefined, context: IEditorOpenContext, token: CancellationToken): Promise<void> {
122122
super.setInput(input, options, context, token);
123123

124-
const editorModel = await input.resolve();
125-
if (!editorModel) {
126-
throw new Error(`Failed to get model for chat editor. id: ${input.sessionId}`);
127-
}
128-
129124
if (!this.widget) {
130125
throw new Error('ChatEditor lifecycle issue: no editor widget');
131126
}
132127

133-
const viewState = options?.viewState ?? input.options.viewState;
134-
this.updateModel(editorModel.model, viewState);
135-
const isAlreadyLocked = !!(viewState as IChatViewState | undefined)?.inputState?.lockedToCodingAgent;
136-
137-
// Only apply specific locking for dedicated coding agent sessions if not already locked
138-
if (!isAlreadyLocked && input.resource.scheme === Schemas.vscodeChatSession) {
128+
if (input.resource.scheme === Schemas.vscodeChatSession) {
139129
const identifier = ChatSessionUri.parse(input.resource);
140130
if (identifier) {
141131
const contributions = this.chatSessionsService.getChatSessionContributions();
142132
const contribution = contributions.find(c => c.type === identifier.chatSessionType);
143133
if (contribution) {
144-
this.widget.lockToCodingAgent(contribution.name);
134+
this.widget.lockToCodingAgent(contribution.name, contribution.displayName);
135+
} else {
136+
this.widget.unlockFromCodingAgent();
145137
}
138+
} else {
139+
this.widget.unlockFromCodingAgent();
146140
}
147141
} else {
148142
this.widget.unlockFromCodingAgent();
149143
}
144+
145+
const editorModel = await input.resolve();
146+
if (!editorModel) {
147+
throw new Error(`Failed to get model for chat editor. id: ${input.sessionId}`);
148+
}
149+
const viewState = options?.viewState ?? input.options.viewState;
150+
this.updateModel(editorModel.model, viewState);
150151
}
151152

152153
private updateModel(model: IChatModel, viewState?: IChatViewState): void {

src/vs/workbench/contrib/chat/browser/chatWidget.ts

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,8 +1506,11 @@ export class ChatWidget extends Disposable implements IChatWidget {
15061506
this.container.setAttribute('data-session-id', model.sessionId);
15071507
this.viewModel = this.instantiationService.createInstance(ChatViewModel, model, this._codeBlockModelCollection);
15081508

1509-
// Apply any placeholder from the view model immediately
1510-
if (this.viewModel.inputPlaceholder) {
1509+
if (this._lockedToCodingAgent) {
1510+
const placeholder = localize('chat.input.placeholder.lockedToAgent', "Follow up with {0}", this._lockedToCodingAgent);
1511+
this.viewModel.setInputPlaceholder(placeholder);
1512+
this.inputEditor.updateOptions({ placeholder });
1513+
} else if (this.viewModel.inputPlaceholder) {
15111514
this.inputEditor.updateOptions({ placeholder: this.viewModel.inputPlaceholder });
15121515
}
15131516

@@ -1610,22 +1613,12 @@ export class ChatWidget extends Disposable implements IChatWidget {
16101613
}
16111614

16121615
// Coding agent locking methods
1613-
public lockToCodingAgent(name: string): void {
1614-
this._lockedToCodingAgent = name;
1616+
public lockToCodingAgent(name: string, displayName: string): void {
1617+
this._lockedToCodingAgent = displayName;
16151618
this._codingAgentPrefix = `@${name} `;
16161619
this._lockedToCodingAgentContextKey.set(true);
16171620
this.renderWelcomeViewContentIfNeeded();
16181621
this.input.setChatMode(ChatModeKind.Ask);
1619-
1620-
// Update the placeholder to show that we're locked to this agent
1621-
const localized = localize('chat.input.placeholder.lockedToAgent', "Chat with @{0}", name);
1622-
if (this.viewModel) {
1623-
this.viewModel.setInputPlaceholder(localized);
1624-
}
1625-
this.inputEditor.updateOptions({ placeholder: localized });
1626-
1627-
this.renderer.updateOptions({ restorable: false, editable: false });
1628-
this.tree.rerender();
16291622
}
16301623

16311624
public unlockFromCodingAgent(): void {
@@ -1641,8 +1634,6 @@ export class ChatWidget extends Disposable implements IChatWidget {
16411634
if (this.viewModel) {
16421635
this.viewModel.resetInputPlaceholder();
16431636
}
1644-
1645-
// Also clear the editor's placeholder immediately for immediate visual feedback
16461637
this.inputEditor.updateOptions({ placeholder: undefined });
16471638
this.renderer.updateOptions({ restorable: true, editable: true });
16481639
this.tree.rerender();
@@ -1687,11 +1678,6 @@ export class ChatWidget extends Disposable implements IChatWidget {
16871678
}
16881679
});
16891680

1690-
// Save the locked coding agent state
1691-
if (this._lockedToCodingAgent) {
1692-
inputState.lockedToCodingAgent = this._lockedToCodingAgent;
1693-
}
1694-
16951681
return inputState;
16961682
}
16971683

@@ -2100,12 +2086,6 @@ export class ChatWidget extends Disposable implements IChatWidget {
21002086
getViewState(): IChatViewState {
21012087
// Get the input state which includes our locked agent (if any)
21022088
const inputState = this.input.getViewState();
2103-
2104-
// Ensure the locked agent state is included
2105-
if (this._lockedToCodingAgent && inputState && !inputState.lockedToCodingAgent) {
2106-
inputState.lockedToCodingAgent = this._lockedToCodingAgent;
2107-
}
2108-
21092089
return {
21102090
inputValue: this.getInput(),
21112091
inputState: inputState

src/vs/workbench/contrib/chat/common/chatWidgetHistoryService.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ export interface IChatInputState {
2929
* { id: string } is the old IChatMode. This is deprecated but may still be in persisted data.
3030
*/
3131
chatMode?: ChatModeKind | string | { id: string };
32-
33-
/**
34-
* The name of the coding agent that the chat is locked to, if any.
35-
*/
36-
lockedToCodingAgent?: string;
3732
}
3833

3934
export const IChatWidgetHistoryService = createDecorator<IChatWidgetHistoryService>('IChatWidgetHistoryService');

0 commit comments

Comments
 (0)