Skip to content

Commit

Permalink
debt - remove InlineChatWidget#updateChatMessage because it is effe…
Browse files Browse the repository at this point in the history
…ctively unused (microsoft#230213)

fyi @meganrogge @Tyriar this update the terminal chat controller. It use of `updateChatMessage` would be a noop since terminal chat uses a real chat model
  • Loading branch information
jrieken authored Oct 1, 2024
1 parent 4aeed99 commit 7e50bfa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 62 deletions.
63 changes: 4 additions & 59 deletions src/vs/workbench/contrib/inlineChat/browser/inlineChatWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { renderLabelWithIcons } from '../../../../base/browser/ui/iconLabel/icon
import { IAction } from '../../../../base/common/actions.js';
import { isNonEmptyArray, tail } from '../../../../base/common/arrays.js';
import { Emitter, Event } from '../../../../base/common/event.js';
import { IMarkdownString, MarkdownString } from '../../../../base/common/htmlContent.js';
import { IMarkdownString } from '../../../../base/common/htmlContent.js';
import { DisposableStore, MutableDisposable, toDisposable } from '../../../../base/common/lifecycle.js';
import { constObservable, derived, ISettableObservable, observableValue } from '../../../../base/common/observable.js';
import './media/inlineChat.css';
Expand Down Expand Up @@ -45,10 +45,9 @@ import { MarkUnhelpfulActionId } from '../../chat/browser/actions/chatTitleActio
import { IChatWidgetViewOptions } from '../../chat/browser/chat.js';
import { ChatVoteDownButton } from '../../chat/browser/chatListRenderer.js';
import { ChatWidget, IChatWidgetLocationOptions } from '../../chat/browser/chatWidget.js';
import { ChatAgentLocation } from '../../chat/common/chatAgents.js';
import { chatRequestBackground } from '../../chat/common/chatColors.js';
import { CONTEXT_CHAT_RESPONSE_SUPPORT_ISSUE_REPORTING, CONTEXT_RESPONSE, CONTEXT_RESPONSE_ERROR, CONTEXT_RESPONSE_FILTERED, CONTEXT_RESPONSE_VOTE } from '../../chat/common/chatContextKeys.js';
import { ChatModel, IChatModel } from '../../chat/common/chatModel.js';
import { IChatModel } from '../../chat/common/chatModel.js';
import { ChatAgentVoteDirection, IChatService } from '../../chat/common/chatService.js';
import { isResponseVM } from '../../chat/common/chatViewModel.js';
import { HunkInformation, Session } from './inlineChatSession.js';
Expand Down Expand Up @@ -107,7 +106,6 @@ export class InlineChatWidget {

protected readonly _store = new DisposableStore();

private readonly _defaultChatModel: ChatModel;
private readonly _ctxInputEditorFocused: IContextKey<boolean>;
private readonly _ctxResponseFocused: IContextKey<boolean>;

Expand Down Expand Up @@ -287,13 +285,6 @@ export class InlineChatWidget {
this.updateStatus('Thank you for your feedback!', { resetAfter: 1250 });
}
}));

// LEGACY - default chat model
// this is only here for as long as we offer updateChatMessage
this._defaultChatModel = this._store.add(this._instantiationService.createInstance(ChatModel, undefined, ChatAgentLocation.Editor));
this._defaultChatModel.startInitialize();
this._defaultChatModel.initialize(undefined);
this.setChatModel(this._defaultChatModel);
}

private _updateAriaLabel(): void {
Expand Down Expand Up @@ -452,57 +443,14 @@ export class InlineChatWidget {
}


getChatModel(): IChatModel {
return this._chatWidget.viewModel?.model ?? this._defaultChatModel;
getChatModel(): IChatModel | undefined {
return this._chatWidget.viewModel?.model;
}

setChatModel(chatModel: IChatModel) {
this._chatWidget.setModel(chatModel, { inputValue: undefined });
}

/**
* @deprecated use `setChatModel` instead
*/
updateChatMessage(message: IInlineChatMessage, isIncomplete: true): IInlineChatMessageAppender;
updateChatMessage(message: IInlineChatMessage | undefined): void;
updateChatMessage(message: IInlineChatMessage | undefined, isIncomplete?: boolean, isCodeBlockEditable?: boolean): IInlineChatMessageAppender | undefined;
updateChatMessage(message: IInlineChatMessage | undefined, isIncomplete?: boolean, isCodeBlockEditable?: boolean): IInlineChatMessageAppender | undefined {

if (!this._chatWidget.viewModel || this._chatWidget.viewModel.model !== this._defaultChatModel) {
// this can only be used with the default chat model
return;
}

const model = this._defaultChatModel;
if (!message?.message.value) {
for (const request of model.getRequests()) {
model.removeRequest(request.id);
}
return;
}

const chatRequest = model.addRequest({ parts: [], text: '' }, { variables: [] }, 0);
model.acceptResponseProgress(chatRequest, {
kind: 'markdownContent',
content: message.message
});

if (!isIncomplete) {
model.completeResponse(chatRequest);
return;
}
return {
cancel: () => model.cancelRequest(chatRequest),
complete: () => model.completeResponse(chatRequest),
appendContent: (fragment: string) => {
model.acceptResponseProgress(chatRequest, {
kind: 'markdownContent',
content: new MarkdownString(fragment)
});
}
};
}

updateInfo(message: string): void {
this._elements.infoLabel.classList.toggle('hidden', !message);
const renderedMessage = renderLabelWithIcons(message);
Expand Down Expand Up @@ -541,16 +489,13 @@ export class InlineChatWidget {
reset() {
this._chatWidget.setContext(true);
this._chatWidget.saveState();
this.updateChatMessage(undefined);

reset(this._elements.statusLabel);
this._elements.statusLabel.classList.toggle('hidden', true);
this._elements.toolbar1.classList.add('hidden');
this._elements.toolbar2.classList.add('hidden');
this.updateInfo('');

this.chatWidget.setModel(this._defaultChatModel, {});

this._elements.accessibleViewer.classList.toggle('hidden', true);
this._onDidChangeHeight.fire();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { TerminalWidgetManager } from '../../../terminal/browser/widgets/widgetM
import { ITerminalProcessManager } from '../../../terminal/common/terminal.js';
import { TerminalChatWidget } from './terminalChatWidget.js';

import { MarkdownString } from '../../../../../base/common/htmlContent.js';
import { ChatModel, IChatResponseModel } from '../../../chat/common/chatModel.js';
import { TerminalChatContextKeys } from './terminalChat.js';
import { IViewsService } from '../../../../services/views/common/viewsService.js';
Expand Down Expand Up @@ -244,8 +243,6 @@ export class TerminalChatController extends Disposable implements ITerminalContr
if (response.isComplete) {
this._requestActiveContextKey.set(false);
this._requestActiveContextKey.set(false);
const containsCode = responseContent.includes('```');
this._terminalChatWidget!.value.inlineChatWidget.updateChatMessage({ message: new MarkdownString(responseContent), requestId: response!.requestId }, false, containsCode);
const firstCodeBlock = await this.terminalChatWidget?.inlineChatWidget.getCodeBlockInfo(0);
const secondCodeBlock = await this.terminalChatWidget?.inlineChatWidget.getCodeBlockInfo(1);
this._responseContainsCodeBlockContextKey.set(!!firstCodeBlock);
Expand Down

0 comments on commit 7e50bfa

Please sign in to comment.