Skip to content

Commit 5bb0f37

Browse files
authored
Remove 'session' from transfer API (microsoft#209204)
1 parent 904d030 commit 5bb0f37

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { Emitter } from 'vs/base/common/event';
77
import { Disposable, DisposableMap } from 'vs/base/common/lifecycle';
88
import { URI, UriComponents } from 'vs/base/common/uri';
9+
import { ILogService } from 'vs/platform/log/common/log';
910
import { ExtHostChatShape, ExtHostContext, MainContext, MainThreadChatShape } from 'vs/workbench/api/common/extHost.protocol';
1011
import { IChatWidgetService } from 'vs/workbench/contrib/chat/browser/chat';
1112
import { IChatContributionService } from 'vs/workbench/contrib/chat/common/chatContributionService';
@@ -24,25 +25,27 @@ export class MainThreadChat extends Disposable implements MainThreadChatShape {
2425
extHostContext: IExtHostContext,
2526
@IChatService private readonly _chatService: IChatService,
2627
@IChatWidgetService private readonly _chatWidgetService: IChatWidgetService,
27-
@IChatContributionService private readonly chatContribService: IChatContributionService,
28+
@IChatContributionService private readonly _chatContribService: IChatContributionService,
29+
@ILogService private readonly _logService: ILogService,
2830
) {
2931
super();
3032
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostChat);
3133
}
3234

33-
$transferChatSession(sessionId: number, toWorkspace: UriComponents): void {
34-
const sessionIdStr = this._chatService.getSessionId(sessionId);
35-
if (!sessionIdStr) {
36-
throw new Error(`Failed to transfer session. Unknown session provider ID: ${sessionId}`);
35+
$transferActiveChatSession(toWorkspace: UriComponents): void {
36+
const widget = this._chatWidgetService.lastFocusedWidget;
37+
const sessionId = widget?.viewModel?.model.sessionId;
38+
if (!sessionId) {
39+
this._logService.error(`MainThreadChat#$transferActiveChatSession: No active chat session found`);
40+
return;
3741
}
3842

39-
const widget = this._chatWidgetService.getWidgetBySessionId(sessionIdStr);
4043
const inputValue = widget?.inputEditor.getValue() ?? '';
41-
this._chatService.transferChatSession({ sessionId: sessionIdStr, inputValue: inputValue }, URI.revive(toWorkspace));
44+
this._chatService.transferChatSession({ sessionId, inputValue }, URI.revive(toWorkspace));
4245
}
4346

4447
async $registerChatProvider(handle: number, id: string): Promise<void> {
45-
const registration = this.chatContribService.registeredProviders.find(staticProvider => staticProvider.id === id);
48+
const registration = this._chatContribService.registeredProviders.find(staticProvider => staticProvider.id === id);
4649
if (!registration) {
4750
throw new Error(`Provider ${id} must be declared in the package.json.`);
4851
}

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,9 +1405,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
14051405
checkProposedApiEnabled(extension, 'interactive');
14061406
return extHostChat.registerChatProvider(extension, id, provider);
14071407
},
1408-
transferChatSession(session: vscode.InteractiveSession, toWorkspace: vscode.Uri) {
1408+
transferActiveChat(toWorkspace: vscode.Uri) {
14091409
checkProposedApiEnabled(extension, 'interactive');
1410-
return extHostChat.transferChatSession(session, toWorkspace);
1410+
return extHostChat.transferActiveChat(toWorkspace);
14111411
}
14121412
};
14131413

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ export interface MainThreadChatShape extends IDisposable {
13221322
$registerChatProvider(handle: number, id: string): Promise<void>;
13231323
$acceptChatState(sessionId: number, state: any): Promise<void>;
13241324
$unregisterChatProvider(handle: number): Promise<void>;
1325-
$transferChatSession(sessionId: number, toWorkspace: UriComponents): void;
1325+
$transferActiveChatSession(toWorkspace: UriComponents): void;
13261326
}
13271327

13281328
export interface ExtHostChatShape {

src/vs/workbench/api/common/extHostChat.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { CancellationToken } from 'vs/base/common/cancellation';
7-
import { Iterable } from 'vs/base/common/iterator';
87
import { toDisposable } from 'vs/base/common/lifecycle';
98
import { IRelaxedExtensionDescription } from 'vs/platform/extensions/common/extensions';
109
import { ExtHostChatShape, IChatDto, IMainContext, MainContext, MainThreadChatShape } from 'vs/workbench/api/common/extHost.protocol';
@@ -49,13 +48,8 @@ export class ExtHostChat implements ExtHostChatShape {
4948
});
5049
}
5150

52-
transferChatSession(session: vscode.InteractiveSession, newWorkspace: vscode.Uri): void {
53-
const sessionId = Iterable.find(this._chatSessions.keys(), key => this._chatSessions.get(key) === session) ?? 0;
54-
if (typeof sessionId !== 'number') {
55-
return;
56-
}
57-
58-
this._proxy.$transferChatSession(sessionId, newWorkspace);
51+
transferActiveChat(newWorkspace: vscode.Uri): void {
52+
this._proxy.$transferActiveChatSession(newWorkspace);
5953
}
6054

6155
async $prepareChat(handle: number, token: CancellationToken): Promise<IChatDto | undefined> {

src/vscode-dts/vscode.proposed.interactive.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,6 @@ declare module 'vscode' {
132132

133133
export function registerInteractiveEditorSessionProvider(provider: InteractiveEditorSessionProvider, metadata?: InteractiveEditorSessionProviderMetadata): Disposable;
134134

135-
export function transferChatSession(session: InteractiveSession, toWorkspace: Uri): void;
135+
export function transferActiveChat(toWorkspace: Uri): void;
136136
}
137137
}

0 commit comments

Comments
 (0)