Skip to content

Commit ace2b1b

Browse files
authored
use provideSampleQuestions to show initial input of inline chat session (microsoft#209947)
* use `provideSampleQuestions` to show initial input of inline chat session * fix test
1 parent 2cc237d commit ace2b1b

File tree

6 files changed

+40
-18
lines changed

6 files changed

+40
-18
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export interface IChatListItemRendererOptions {
9999

100100
export interface IChatWidgetViewOptions {
101101
renderInputOnTop?: boolean;
102+
renderFollowups?: boolean;
102103
renderStyle?: 'default' | 'compact';
103104
supportsFileReferences?: boolean;
104105
filter?: (item: ChatTreeItem) => boolean;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,16 @@ export class ChatWidget extends Disposable implements IChatWidget {
259259
const viewId = 'viewId' in this.viewContext ? this.viewContext.viewId : undefined;
260260
this.editorOptions = this._register(this.instantiationService.createInstance(ChatEditorOptions, viewId, this.styles.listForeground, this.styles.inputEditorBackground, this.styles.resultEditorBackground));
261261
const renderInputOnTop = this.viewOptions.renderInputOnTop ?? false;
262+
const renderFollowups = this.viewOptions.renderFollowups ?? !renderInputOnTop;
262263
const renderStyle = this.viewOptions.renderStyle;
263264

264265
this.container = dom.append(parent, $('.interactive-session'));
265266
if (renderInputOnTop) {
266-
this.createInput(this.container, { renderFollowups: false, renderStyle });
267+
this.createInput(this.container, { renderFollowups, renderStyle });
267268
this.listContainer = dom.append(this.container, $(`.interactive-list`));
268269
} else {
269270
this.listContainer = dom.append(this.container, $(`.interactive-list`));
270-
this.createInput(this.container, { renderFollowups: true, renderStyle });
271+
this.createInput(this.container, { renderFollowups, renderStyle });
271272
}
272273

273274
this.createList(this.listContainer, { ...this.viewOptions.rendererOptions, renderStyle });

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export class InlineChatContentWidget implements IContentWidget {
6868
editorOverflowWidgetsDomNode: _editor.getOverflowWidgetsDomNode(),
6969
renderStyle: 'compact',
7070
renderInputOnTop: true,
71+
renderFollowups: true,
7172
supportsFileReferences: false,
7273
menus: {
7374
telemetrySource: 'inlineChat-content'

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,6 @@ export class InlineChatController implements IEditorContribution {
343343
break;
344344
}
345345

346-
if (session.session.input) {
347-
options.message = session.session.input;
348-
}
349346
this._session = session;
350347
return State.INIT_UI;
351348
}

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

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,29 @@ class BridgeAgent implements IChatAgentImplementation {
186186
coalesceInPlace(chatFollowups);
187187
return chatFollowups;
188188
}
189+
190+
provideWelcomeMessage(token: CancellationToken): string[] {
191+
// without this provideSampleQuestions is not called
192+
return [];
193+
}
194+
195+
async provideSampleQuestions(location: ChatAgentLocation, token: CancellationToken): Promise<IChatFollowup[]> {
196+
// TODO@jrieken DEBT
197+
// (hack) this function is called while creating the session. We need the timeout to make sure this._sessions is populated.
198+
// (hack) we have no context/session id and therefore use the first session with an active editor
199+
await new Promise(resolve => setTimeout(resolve, 10));
200+
201+
for (const [, data] of this._sessions) {
202+
if (data.session.session.input && data.editor.hasWidgetFocus()) {
203+
return [{
204+
kind: 'reply',
205+
agentId: _bridgeAgentId,
206+
message: data.session.session.input,
207+
}];
208+
}
209+
}
210+
return [];
211+
}
189212
}
190213

191214
type SessionData = {
@@ -342,19 +365,6 @@ export class InlineChatSessionServiceImpl implements IInlineChatSessionService {
342365
return undefined;
343366
}
344367

345-
const chatModel = this._chatService.startSession(ChatAgentLocation.Editor, token);
346-
if (!chatModel) {
347-
this._logService.trace('[IE] NO chatModel found');
348-
return undefined;
349-
}
350-
351-
const store = new DisposableStore();
352-
353-
store.add(toDisposable(() => {
354-
this._chatService.clearSession(chatModel.sessionId);
355-
chatModel.dispose();
356-
}));
357-
358368
this._onWillStartSession.fire(editor);
359369

360370
const textModel = editor.getModel();
@@ -375,8 +385,19 @@ export class InlineChatSessionServiceImpl implements IInlineChatSessionService {
375385
return undefined;
376386
}
377387

388+
const store = new DisposableStore();
378389
this._logService.trace(`[IE] creating NEW session for ${editor.getId()}, ${provider.extensionId}`);
379390

391+
const chatModel = this._chatService.startSession(ChatAgentLocation.Editor, token);
392+
if (!chatModel) {
393+
this._logService.trace('[IE] NO chatModel found');
394+
return undefined;
395+
}
396+
397+
store.add(toDisposable(() => {
398+
this._chatService.clearSession(chatModel.sessionId);
399+
chatModel.dispose();
400+
}));
380401

381402
const lastResponseListener = store.add(new MutableDisposable());
382403
store.add(chatModel.onDidChange(e => {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export class InlineChatWidget {
173173
defaultElementHeight: 32,
174174
renderStyle: 'compact',
175175
renderInputOnTop: true,
176+
renderFollowups: true,
176177
supportsFileReferences: true,
177178
editorOverflowWidgetsDomNode: options.editorOverflowWidgetsDomNode,
178179
rendererOptions: options.rendererOptions,

0 commit comments

Comments
 (0)