6
6
import { Emitter } from 'vs/base/common/event' ;
7
7
import { Disposable , DisposableMap } from 'vs/base/common/lifecycle' ;
8
8
import { URI , UriComponents } from 'vs/base/common/uri' ;
9
+ import { ILogService } from 'vs/platform/log/common/log' ;
9
10
import { ExtHostChatShape , ExtHostContext , MainContext , MainThreadChatShape } from 'vs/workbench/api/common/extHost.protocol' ;
10
11
import { IChatWidgetService } from 'vs/workbench/contrib/chat/browser/chat' ;
11
12
import { IChatContributionService } from 'vs/workbench/contrib/chat/common/chatContributionService' ;
@@ -24,25 +25,27 @@ export class MainThreadChat extends Disposable implements MainThreadChatShape {
24
25
extHostContext : IExtHostContext ,
25
26
@IChatService private readonly _chatService : IChatService ,
26
27
@IChatWidgetService private readonly _chatWidgetService : IChatWidgetService ,
27
- @IChatContributionService private readonly chatContribService : IChatContributionService ,
28
+ @IChatContributionService private readonly _chatContribService : IChatContributionService ,
29
+ @ILogService private readonly _logService : ILogService ,
28
30
) {
29
31
super ( ) ;
30
32
this . _proxy = extHostContext . getProxy ( ExtHostContext . ExtHostChat ) ;
31
33
}
32
34
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 ;
37
41
}
38
42
39
- const widget = this . _chatWidgetService . getWidgetBySessionId ( sessionIdStr ) ;
40
43
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 ) ) ;
42
45
}
43
46
44
47
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 ) ;
46
49
if ( ! registration ) {
47
50
throw new Error ( `Provider ${ id } must be declared in the package.json.` ) ;
48
51
}
0 commit comments