Skip to content

Commit 27af80e

Browse files
authored
Set icon for chat editor, and add editor title (microsoft#183008)
1 parent d052d31 commit 27af80e

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import 'vs/css!./media/chatEditor';
67
import * as dom from 'vs/base/browser/dom';
78
import { CancellationToken } from 'vs/base/common/cancellation';
89
import { IContextKeyService, IScopedContextKeyService } from 'vs/platform/contextkey/common/contextkey';

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export class ChatEditorInput extends EditorInput {
2626
public sessionId: string | undefined;
2727
public providerId: string | undefined;
2828

29+
private model: IChatModel | undefined;
30+
2931
static getNewEditorUri(): URI {
3032
const handle = Math.floor(Math.random() * 1e9);
3133
return ChatUri.generate(handle);
@@ -65,26 +67,31 @@ export class ChatEditorInput extends EditorInput {
6567
}
6668

6769
override getName(): string {
68-
return nls.localize('chatEditorName', "Chat") + (this.inputCount > 0 ? ` ${this.inputCount + 1}` : '');
70+
return this.model?.title || nls.localize('chatEditorName', "Chat") + (this.inputCount > 0 ? ` ${this.inputCount + 1}` : '');
71+
}
72+
73+
override getLabelExtraClasses(): string[] {
74+
return ['chat-editor-label'];
6975
}
7076

7177
override async resolve(): Promise<ChatEditorModel | null> {
72-
let model: IChatModel | undefined;
7378
if (typeof this.sessionId === 'string') {
74-
model = this.chatService.getOrRestoreSession(this.sessionId);
79+
this.model = this.chatService.getOrRestoreSession(this.sessionId);
7580
} else if (typeof this.providerId === 'string') {
76-
model = this.chatService.startSession(this.providerId, CancellationToken.None);
81+
this.model = this.chatService.startSession(this.providerId, CancellationToken.None);
7782
} else if ('data' in this.options.target) {
78-
model = this.chatService.loadSessionFromContent(this.options.target.data);
83+
this.model = this.chatService.loadSessionFromContent(this.options.target.data);
7984
}
8085

81-
if (!model) {
86+
if (!this.model) {
8287
return null;
8388
}
8489

85-
this.sessionId = model.sessionId;
86-
await model.waitForInitialization();
87-
return this._register(new ChatEditorModel(model));
90+
this.sessionId = this.model.sessionId;
91+
await this.model.waitForInitialization();
92+
this._register(this.model.onDidChange(() => this._onDidChangeLabel.fire()));
93+
94+
return this._register(new ChatEditorModel(this.model));
8895
}
8996

9097
override dispose(): void {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
.show-file-icons .chat-editor-label.file-icon::before {
7+
content: '\EAC7';
8+
font-family: 'codicon';
9+
font-size: 16px;
10+
}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Disposable } from 'vs/base/common/lifecycle';
1010
import { URI, UriComponents } from 'vs/base/common/uri';
1111
import { generateUuid } from 'vs/base/common/uuid';
1212
import { ILogService } from 'vs/platform/log/common/log';
13-
import { IChatProgress, IChatResponse, IChatResponseErrorDetails, IChat, IChatFollowup, IChatReplyFollowup, InteractiveSessionVoteDirection } from 'vs/workbench/contrib/chat/common/chatService';
13+
import { IChat, IChatFollowup, IChatProgress, IChatReplyFollowup, IChatResponse, IChatResponseErrorDetails, InteractiveSessionVoteDirection } from 'vs/workbench/contrib/chat/common/chatService';
1414

1515
export interface IChatRequestModel {
1616
readonly id: string;
@@ -174,7 +174,7 @@ export interface IChatModel {
174174
readonly sessionId: string;
175175
readonly providerId: string;
176176
readonly isInitialized: boolean;
177-
// readonly title: string;
177+
readonly title: string;
178178
readonly welcomeMessage: IChatWelcomeMessageModel | undefined;
179179
readonly requestInProgress: boolean;
180180
readonly inputPlaceholder?: string;
@@ -319,6 +319,17 @@ export class ChatModel extends Disposable implements IChatModel {
319319
return this._isImported;
320320
}
321321

322+
get title(): string {
323+
const firstRequestMessage = this._requests[0]?.message;
324+
if (typeof firstRequestMessage === 'string') {
325+
return firstRequestMessage;
326+
} else if (firstRequestMessage) {
327+
return firstRequestMessage.message;
328+
} else {
329+
return '';
330+
}
331+
}
332+
322333
constructor(
323334
public readonly providerId: string,
324335
private readonly initialData: ISerializableChatData | IExportableChatData | undefined,

0 commit comments

Comments
 (0)