Skip to content

Commit 09990db

Browse files
committed
use InlineChatWidget feedback logic instead of custom commands
1 parent 30ced27 commit 09990db

File tree

3 files changed

+28
-56
lines changed

3 files changed

+28
-56
lines changed

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import { EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions';
5555
import { ICodeEditorWidgetOptions } from 'vs/editor/browser/widget/codeEditor/codeEditorWidget';
5656
import { SnippetController2 } from 'vs/editor/contrib/snippet/browser/snippetController2';
5757
import { SuggestController } from 'vs/editor/contrib/suggest/browser/suggestController';
58+
import { IChatService } from 'vs/workbench/contrib/chat/common/chatService';
5859

5960

6061
export interface InlineChatWidgetViewState {
@@ -145,8 +146,6 @@ export class InlineChatWidget {
145146
private _isLayouting: boolean = false;
146147

147148
private _followUpDisposables = this._store.add(new DisposableStore());
148-
149-
150149
constructor(
151150
location: ChatAgentLocation,
152151
options: IInlineChatWidgetConstructionOptions,
@@ -157,6 +156,7 @@ export class InlineChatWidget {
157156
@IConfigurationService private readonly _configurationService: IConfigurationService,
158157
@IAccessibleViewService private readonly _accessibleViewService: IAccessibleViewService,
159158
@ITextModelService protected readonly _textModelResolverService: ITextModelService,
159+
@IChatService private readonly _chatService: IChatService,
160160
) {
161161
// Share hover delegates between toolbars to support instant hover between both
162162
// TODO@jrieken move into chat widget
@@ -165,6 +165,9 @@ export class InlineChatWidget {
165165
this._store.add(this._configurationService.onDidChangeConfiguration(e => {
166166
if (e.affectsConfiguration(AccessibilityVerbositySettingId.InlineChat)) {
167167
this._updateAriaLabel();
168+
// TODO@jrieken FIX THIS
169+
// this._chatWidget.ariaLabel = this._accessibleViewService.getOpenAriaHint(AccessibilityVerbositySettingId.InlineChat);
170+
this._elements.followUps.ariaLabel = this._accessibleViewService.getOpenAriaHint(AccessibilityVerbositySettingId.InlineChat);
168171
}
169172
}));
170173

@@ -285,11 +288,9 @@ export class InlineChatWidget {
285288

286289
this._elements.statusLabel.tabIndex = 0;
287290

288-
this._store.add(this._configurationService.onDidChangeConfiguration(e => {
289-
if (e.affectsConfiguration(AccessibilityVerbositySettingId.InlineChat)) {
290-
// TODO@jrieken FIX THIS
291-
// this._chatWidget.ariaLabel = this._accessibleViewService.getOpenAriaHint(AccessibilityVerbositySettingId.InlineChat);
292-
this._elements.followUps.ariaLabel = this._accessibleViewService.getOpenAriaHint(AccessibilityVerbositySettingId.InlineChat);
291+
this._store.add(this._chatService.onDidPerformUserAction(e => {
292+
if (e.sessionId === this._chatWidget.viewModel?.model.sessionId && e.action.kind === 'vote') {
293+
this.updateStatus('Thank you for your feedback!', { resetAfter: 1250 });
293294
}
294295
}));
295296

@@ -432,6 +433,10 @@ export class InlineChatWidget {
432433
return tail(requests).response?.response.asString();
433434
}
434435

436+
getChatModel(): IChatModel {
437+
return this._chatWidget.viewModel?.model ?? this._defaultChatModel;
438+
}
439+
435440
setChatModel(chatModel: IChatModel) {
436441
this._chatWidget.setModel(chatModel, { inputValue: undefined });
437442
}
@@ -605,8 +610,9 @@ export class EditorBasedInlineChatWidget extends InlineChatWidget {
605610
@IConfigurationService configurationService: IConfigurationService,
606611
@IAccessibleViewService accessibleViewService: IAccessibleViewService,
607612
@ITextModelService textModelResolverService: ITextModelService,
613+
@IChatService chatService: IChatService,
608614
) {
609-
super(ChatAgentLocation.Editor, options, instantiationService, contextKeyService, keybindingService, accessibilityService, configurationService, accessibleViewService, textModelResolverService);
615+
super(ChatAgentLocation.Editor, options, instantiationService, contextKeyService, keybindingService, accessibilityService, configurationService, accessibleViewService, textModelResolverService, chatService);
610616

611617
// preview editors
612618
this._previewDiffEditor = new Lazy(() => this._store.add(instantiationService.createInstance(EmbeddedDiffEditorWidget, this._elements.previewDiff, {

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

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -294,54 +294,6 @@ registerActiveXtermAction({
294294
}
295295
});
296296

297-
registerActiveXtermAction({
298-
id: TerminalChatCommandId.FeedbackHelpful,
299-
title: localize2('feedbackHelpful', 'Helpful'),
300-
precondition: ContextKeyExpr.and(
301-
ContextKeyExpr.has(`config.${TerminalSettingId.ExperimentalInlineChat}`),
302-
TerminalChatContextKeys.responseContainsCodeBlock.notEqualsTo(undefined)
303-
),
304-
icon: Codicon.thumbsup,
305-
toggled: TerminalChatContextKeys.sessionResponseVote.isEqualTo('up'),
306-
menu: {
307-
id: MENU_TERMINAL_CHAT_WIDGET_FEEDBACK,
308-
group: 'inline',
309-
order: 1,
310-
when: TerminalChatContextKeys.responseContainsCodeBlock.notEqualsTo(undefined),
311-
},
312-
run: (_xterm, _accessor, activeInstance) => {
313-
if (isDetachedTerminalInstance(activeInstance)) {
314-
return;
315-
}
316-
const contr = TerminalChatController.activeChatWidget || TerminalChatController.get(activeInstance);
317-
contr?.acceptFeedback(true);
318-
}
319-
});
320-
321-
registerActiveXtermAction({
322-
id: TerminalChatCommandId.FeedbackUnhelpful,
323-
title: localize2('feedbackUnhelpful', 'Unhelpful'),
324-
precondition: ContextKeyExpr.and(
325-
ContextKeyExpr.has(`config.${TerminalSettingId.ExperimentalInlineChat}`),
326-
TerminalChatContextKeys.responseContainsCodeBlock.notEqualsTo(undefined),
327-
),
328-
toggled: TerminalChatContextKeys.sessionResponseVote.isEqualTo('down'),
329-
icon: Codicon.thumbsdown,
330-
menu: {
331-
id: MENU_TERMINAL_CHAT_WIDGET_FEEDBACK,
332-
group: 'inline',
333-
order: 2,
334-
when: TerminalChatContextKeys.responseContainsCodeBlock.notEqualsTo(undefined),
335-
},
336-
run: (_xterm, _accessor, activeInstance) => {
337-
if (isDetachedTerminalInstance(activeInstance)) {
338-
return;
339-
}
340-
const contr = TerminalChatController.activeChatWidget || TerminalChatController.get(activeInstance);
341-
contr?.acceptFeedback(false);
342-
}
343-
});
344-
345297
registerActiveXtermAction({
346298
id: TerminalChatCommandId.FeedbackReportIssue,
347299
title: localize2('reportIssue', 'Report Issue'),

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ export class TerminalChatController extends Disposable implements ITerminalContr
130130
};
131131
}
132132
}, 'terminal'));
133+
134+
// TODO
135+
// This is glue/debt that's needed while ChatModel isn't yet adopted. The chat model uses
136+
// a default chat model (unless configured) and feedback is reported against that one. This
137+
// code forwards the feedback to an actual registered provider
138+
this._chatService.onDidPerformUserAction(e => {
139+
if (e.providerId === this._chatWidget?.rawValue?.inlineChatWidget.getChatModel().providerId) {
140+
if (e.action.kind === 'bug') {
141+
this.acceptFeedback(undefined);
142+
} else if (e.action.kind === 'vote') {
143+
this.acceptFeedback(e.action.direction === InteractiveSessionVoteDirection.Up);
144+
}
145+
}
146+
});
133147
}
134148

135149
private initTerminalAgent(): boolean {

0 commit comments

Comments
 (0)