Skip to content

Commit 2132fb8

Browse files
committed
Start reducing use of chatSessionType
We should be able to use the resource for this instead
1 parent d8864b2 commit 2132fb8

5 files changed

Lines changed: 38 additions & 36 deletions

File tree

src/vs/workbench/api/browser/mainThreadChatSessions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ export class MainThreadChatSessions extends Disposable implements MainThreadChat
336336

337337
this._proxy = this._extHostContext.getProxy(ExtHostContext.ExtHostChatSessions);
338338

339-
this._chatSessionsService.setOptionsChangeCallback(async (chatSessionType: string, sessionResource: URI, updates: ReadonlyArray<{ optionId: string; value: string }>) => {
340-
const handle = this._getHandleForSessionType(chatSessionType);
339+
this._chatSessionsService.setOptionsChangeCallback(async (sessionResource: URI, updates: ReadonlyArray<{ optionId: string; value: string }>) => {
340+
const handle = this._getHandleForSessionType(sessionResource.scheme);
341341
if (handle !== undefined) {
342342
await this.notifyOptionsChange(handle, sessionResource, updates);
343343
}
@@ -484,10 +484,10 @@ export class MainThreadChatSessions extends Disposable implements MainThreadChat
484484
try {
485485
await session.initialize(token);
486486
if (session.options) {
487-
for (const [chatSessionType, handle] of this._sessionTypeToHandle) {
487+
for (const [_, handle] of this._sessionTypeToHandle) {
488488
if (handle === providerHandle) {
489489
for (const [optionId, value] of Object.entries(session.options)) {
490-
this._chatSessionsService.setSessionOption(chatSessionType, sessionResource, optionId, value);
490+
this._chatSessionsService.setSessionOption(sessionResource, optionId, value);
491491
}
492492
break;
493493
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
663663
if (!ctx) {
664664
continue;
665665
}
666-
if (!this.chatSessionsService.getSessionOption(ctx.chatSessionType, ctx.chatSessionResource, optionGroup.id)) {
666+
if (!this.chatSessionsService.getSessionOption(ctx.chatSessionResource, optionGroup.id)) {
667667
// This session does not have a value to contribute for this option group
668668
continue;
669669
}
@@ -682,7 +682,6 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
682682
}
683683
this.getOrCreateOptionEmitter(optionGroup.id).fire(option);
684684
this.chatSessionsService.notifySessionOptionsChange(
685-
ctx.chatSessionType,
686685
ctx.chatSessionResource,
687686
[{ optionId: optionGroup.id, value: option.id }]
688687
).catch(err => this.logService.error(`Failed to notify extension of ${optionGroup.id} change:`, err));
@@ -1173,7 +1172,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
11731172
}
11741173

11751174
for (const [optionGroupId] of this.chatSessionPickerWidgets.entries()) {
1176-
const currentOption = this.chatSessionsService.getSessionOption(ctx.chatSessionType, ctx.chatSessionResource, optionGroupId);
1175+
const currentOption = this.chatSessionsService.getSessionOption(ctx.chatSessionResource, optionGroupId);
11771176
if (currentOption) {
11781177
const optionGroup = optionGroups.find(g => g.id === optionGroupId);
11791178
if (optionGroup) {
@@ -1218,7 +1217,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
12181217
return;
12191218
}
12201219

1221-
const currentOptionId = this.chatSessionsService.getSessionOption(ctx.chatSessionType, ctx.chatSessionResource, optionGroupId);
1220+
const currentOptionId = this.chatSessionsService.getSessionOption(ctx.chatSessionResource, optionGroupId);
12221221
return optionGroup.items.find(m => m.id === currentOptionId);
12231222
}
12241223

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { ExtensionsRegistry } from '../../../services/extensions/common/extensio
2828
import { ChatEditorInput } from '../browser/chatEditorInput.js';
2929
import { IChatAgentAttachmentCapabilities, IChatAgentData, IChatAgentRequest, IChatAgentService } from '../common/chatAgents.js';
3030
import { ChatContextKeys } from '../common/chatContextKeys.js';
31-
import { ChatSession, ChatSessionStatus, IChatSessionContentProvider, IChatSessionItem, IChatSessionItemProvider, IChatSessionProviderOptionGroup, IChatSessionsExtensionPoint, IChatSessionsService } from '../common/chatSessionsService.js';
31+
import { ChatSession, ChatSessionStatus, IChatSessionContentProvider, IChatSessionItem, IChatSessionItemProvider, IChatSessionProviderOptionGroup, IChatSessionsExtensionPoint, IChatSessionsService, SessionOptionsChangedCallback } from '../common/chatSessionsService.js';
3232
import { AGENT_SESSIONS_VIEWLET_ID, ChatAgentLocation, ChatModeKind } from '../common/constants.js';
3333
import { CHAT_CATEGORY } from './actions/chatActions.js';
3434
import { IChatEditorOptions } from './chatEditor.js';
@@ -822,18 +822,18 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ
822822
this._sessions.delete(sessionResource);
823823
}
824824

825-
public hasAnySessionOptions(resource: URI): boolean {
826-
const session = this._sessions.get(resource);
825+
public hasAnySessionOptions(sessionResource: URI): boolean {
826+
const session = this._sessions.get(sessionResource);
827827
return !!session && !!session.options && Object.keys(session.options).length > 0;
828828
}
829829

830-
public getSessionOption(chatSessionType: string, resource: URI, optionId: string): string | undefined {
831-
const session = this._sessions.get(resource);
830+
public getSessionOption(sessionResource: URI, optionId: string): string | undefined {
831+
const session = this._sessions.get(sessionResource);
832832
return session?.getOption(optionId);
833833
}
834834

835-
public setSessionOption(chatSessionType: string, resource: URI, optionId: string, value: string): boolean {
836-
const session = this._sessions.get(resource);
835+
public setSessionOption(sessionResource: URI, optionId: string, value: string): boolean {
836+
const session = this._sessions.get(sessionResource);
837837
return !!session?.setOption(optionId, value);
838838
}
839839

@@ -878,27 +878,27 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ
878878
return this._sessionTypeOptions.get(chatSessionType);
879879
}
880880

881-
private _optionsChangeCallback?: (chatSessionType: string, sessionResource: URI, updates: ReadonlyArray<{ optionId: string; value: string }>) => Promise<void>;
881+
private _optionsChangeCallback?: SessionOptionsChangedCallback;
882882

883883
/**
884884
* Set the callback for notifying extensions about option changes
885885
*/
886-
public setOptionsChangeCallback(callback: (chatSessionType: string, sessionResource: URI, updates: ReadonlyArray<{ optionId: string; value: string }>) => Promise<void>): void {
886+
public setOptionsChangeCallback(callback: SessionOptionsChangedCallback): void {
887887
this._optionsChangeCallback = callback;
888888
}
889889

890890
/**
891891
* Notify extension about option changes for a session
892892
*/
893-
public async notifySessionOptionsChange(chatSessionType: string, sessionResource: URI, updates: ReadonlyArray<{ optionId: string; value: string }>): Promise<void> {
893+
public async notifySessionOptionsChange(sessionResource: URI, updates: ReadonlyArray<{ optionId: string; value: string }>): Promise<void> {
894894
if (!updates.length) {
895895
return;
896896
}
897897
if (this._optionsChangeCallback) {
898-
await this._optionsChangeCallback(chatSessionType, sessionResource, updates);
898+
await this._optionsChangeCallback(sessionResource, updates);
899899
}
900900
for (const u of updates) {
901-
this.setSessionOption(chatSessionType, sessionResource, u.optionId, u.value);
901+
this.setSessionOption(sessionResource, u.optionId, u.value);
902902
}
903903
}
904904

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ export interface IChatSessionContentProvider {
126126
provideChatSessionContent(sessionResource: URI, token: CancellationToken): Promise<ChatSession>;
127127
}
128128

129+
export type SessionOptionsChangedCallback = (sessionResource: URI, updates: ReadonlyArray<{
130+
optionId: string;
131+
value: string;
132+
}>) => Promise<void>;
133+
129134
export interface IChatSessionsService {
130135
readonly _serviceBrand: undefined;
131136

@@ -165,10 +170,10 @@ export interface IChatSessionsService {
165170
setOptionGroupsForSessionType(chatSessionType: string, handle: number, optionGroups?: IChatSessionProviderOptionGroup[]): void;
166171

167172
// Set callback for notifying extensions about option changes
168-
setOptionsChangeCallback(callback: (chatSessionType: string, sessionResource: URI, updates: ReadonlyArray<{ optionId: string; value: string }>) => Promise<void>): void;
173+
setOptionsChangeCallback(callback: SessionOptionsChangedCallback): void;
169174

170175
// Notify extension about option changes
171-
notifySessionOptionsChange(chatSessionType: string, sessionResource: URI, updates: ReadonlyArray<{ optionId: string; value: string }>): Promise<void>;
176+
notifySessionOptionsChange(sessionResource: URI, updates: ReadonlyArray<{ optionId: string; value: string }>): Promise<void>;
172177

173178
// Editable session support
174179
setEditableSession(sessionResource: URI, data: IEditableData | null): Promise<void>;
@@ -185,13 +190,13 @@ export interface IChatSessionsService {
185190

186191
getContentProviderSchemes(): string[];
187192

188-
registerChatSessionContentProvider(chatSessionType: string, provider: IChatSessionContentProvider): IDisposable;
189-
canResolveChatSession(chatSessionResource: URI): Promise<boolean>;
193+
registerChatSessionContentProvider(scheme: string, provider: IChatSessionContentProvider): IDisposable;
194+
canResolveChatSession(sessionResource: URI): Promise<boolean>;
190195
provideChatSessionContent(sessionResource: URI, token: CancellationToken): Promise<ChatSession>;
191196

192-
hasAnySessionOptions(resource: URI): boolean;
193-
getSessionOption(chatSessionType: string, sessionResource: URI, optionId: string): string | undefined;
194-
setSessionOption(chatSessionType: string, sessionResource: URI, optionId: string, value: string): boolean;
197+
hasAnySessionOptions(sessionResource: URI): boolean;
198+
getSessionOption(sessionResource: URI, optionId: string): string | undefined;
199+
setSessionOption(sessionResource: URI, optionId: string, value: string): boolean;
195200

196201
/**
197202
* Get the capabilities for a specific session type

src/vs/workbench/contrib/chat/test/common/mockChatSessionsService.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ThemeIcon } from '../../../../../base/common/themables.js';
1111
import { URI } from '../../../../../base/common/uri.js';
1212
import { IEditableData } from '../../../../common/views.js';
1313
import { IChatAgentAttachmentCapabilities, IChatAgentRequest } from '../../common/chatAgents.js';
14-
import { ChatSession, IChatSessionContentProvider, IChatSessionItem, IChatSessionItemProvider, IChatSessionProviderOptionGroup, IChatSessionsExtensionPoint, IChatSessionsService } from '../../common/chatSessionsService.js';
14+
import { ChatSession, IChatSessionContentProvider, IChatSessionItem, IChatSessionItemProvider, IChatSessionProviderOptionGroup, IChatSessionsExtensionPoint, IChatSessionsService, SessionOptionsChangedCallback } from '../../common/chatSessionsService.js';
1515

1616
export class MockChatSessionsService implements IChatSessionsService {
1717
_serviceBrand: undefined;
@@ -165,16 +165,14 @@ export class MockChatSessionsService implements IChatSessionsService {
165165
}
166166
}
167167

168-
private optionsChangeCallback?: (chatSessionType: string, sessionResource: URI, updates: ReadonlyArray<{ optionId: string; value: string }>) => Promise<void>;
168+
private optionsChangeCallback?: SessionOptionsChangedCallback;
169169

170-
setOptionsChangeCallback(callback: (chatSessionType: string, sessionResource: URI, updates: ReadonlyArray<{ optionId: string; value: string }>) => Promise<void>): void {
170+
setOptionsChangeCallback(callback: SessionOptionsChangedCallback): void {
171171
this.optionsChangeCallback = callback;
172172
}
173173

174-
async notifySessionOptionsChange(chatSessionType: string, sessionResource: URI, updates: ReadonlyArray<{ optionId: string; value: string }>): Promise<void> {
175-
if (this.optionsChangeCallback) {
176-
await this.optionsChangeCallback(chatSessionType, sessionResource, updates);
177-
}
174+
async notifySessionOptionsChange(sessionResource: URI, updates: ReadonlyArray<{ optionId: string; value: string }>): Promise<void> {
175+
await this.optionsChangeCallback?.(sessionResource, updates);
178176
}
179177

180178
async setEditableSession(sessionResource: URI, data: IEditableData | null): Promise<void> {
@@ -197,11 +195,11 @@ export class MockChatSessionsService implements IChatSessionsService {
197195
this._onDidChangeSessionItems.fire(chatSessionType);
198196
}
199197

200-
getSessionOption(chatSessionType: string, sessionResource: URI, optionId: string): string | undefined {
198+
getSessionOption(sessionResource: URI, optionId: string): string | undefined {
201199
return this.sessionOptions.get(sessionResource)?.get(optionId);
202200
}
203201

204-
setSessionOption(chatSessionType: string, sessionResource: URI, optionId: string, value: string): boolean {
202+
setSessionOption(sessionResource: URI, optionId: string, value: string): boolean {
205203
if (!this.sessionOptions.has(sessionResource)) {
206204
this.sessionOptions.set(sessionResource, new Map());
207205
}

0 commit comments

Comments
 (0)