@@ -1272,7 +1272,7 @@ export class InlineChatController2 implements IEditorContribution {
12721272 private readonly _editor : ICodeEditor ,
12731273 @IInstantiationService private readonly _instaService : IInstantiationService ,
12741274 @INotebookEditorService private readonly _notebookEditorService : INotebookEditorService ,
1275- @IInlineChatSessionService private readonly _inlineChatSessions : IInlineChatSessionService ,
1275+ @IInlineChatSessionService private readonly _inlineChatSessionService : IInlineChatSessionService ,
12761276 @ICodeEditorService codeEditorService : ICodeEditorService ,
12771277 @IContextKeyService contextKeyService : IContextKeyService ,
12781278 @ISharedWebContentExtractorService private readonly _webContentExtractorService : ISharedWebContentExtractorService ,
@@ -1360,22 +1360,35 @@ export class InlineChatController2 implements IEditorContribution {
13601360
13611361 const editorObs = observableCodeEditor ( _editor ) ;
13621362
1363- const sessionsSignal = observableSignalFromEvent ( this , _inlineChatSessions . onDidChangeSessions ) ;
1363+ const sessionsSignal = observableSignalFromEvent ( this , _inlineChatSessionService . onDidChangeSessions ) ;
13641364
13651365 this . _currentSession = derived ( r => {
13661366 sessionsSignal . read ( r ) ;
13671367 const model = editorObs . model . read ( r ) ;
1368- const value = model && _inlineChatSessions . getSession2 ( model . uri ) ;
1369- return value ?? undefined ;
1368+ const session = model && _inlineChatSessionService . getSession2 ( model . uri ) ;
1369+ return session ?? undefined ;
13701370 } ) ;
13711371
13721372
1373+ let lastSession : IInlineChatSession2 | undefined = undefined ;
1374+
13731375 this . _store . add ( autorun ( r => {
13741376 const session = this . _currentSession . read ( r ) ;
13751377 if ( ! session ) {
13761378 this . _isActiveController . set ( false , undefined ) ;
1379+
1380+ if ( lastSession && ! lastSession . chatModel . hasRequests ) {
1381+ const state = lastSession . chatModel . inputModel . state . read ( undefined ) ;
1382+ if ( ! state || ( ! state . inputText && state . attachments . length === 0 ) ) {
1383+ lastSession . dispose ( ) ;
1384+ lastSession = undefined ;
1385+ }
1386+ }
13771387 return ;
13781388 }
1389+
1390+ lastSession = session ;
1391+
13791392 let foundOne = false ;
13801393 for ( const editor of codeEditorService . listCodeEditors ( ) ) {
13811394 if ( Boolean ( InlineChatController2 . get ( editor ) ?. _isActiveController . read ( undefined ) ) ) {
@@ -1409,11 +1422,12 @@ export class InlineChatController2 implements IEditorContribution {
14091422 const session = visibleSessionObs . read ( r ) ;
14101423 if ( ! session ) {
14111424 this . _zone . rawValue ?. hide ( ) ;
1425+ this . _zone . value . widget . chatWidget . setModel ( undefined ) ;
14121426 _editor . focus ( ) ;
14131427 ctxInlineChatVisible . reset ( ) ;
14141428 } else {
14151429 ctxInlineChatVisible . set ( true ) ;
1416- this . _zone . value . widget . setChatModel ( session . chatModel ) ;
1430+ this . _zone . value . widget . chatWidget . setModel ( session . chatModel ) ;
14171431 if ( ! this . _zone . value . position ) {
14181432 this . _zone . value . widget . chatWidget . input . renderAttachedContext ( ) ; // TODO - fights layout bug
14191433 this . _zone . value . show ( session . initialPosition ) ;
@@ -1537,15 +1551,15 @@ export class InlineChatController2 implements IEditorContribution {
15371551
15381552 const uri = this . _editor . getModel ( ) . uri ;
15391553
1540- const existingSession = this . _inlineChatSessions . getSession2 ( uri ) ;
1554+ const existingSession = this . _inlineChatSessionService . getSession2 ( uri ) ;
15411555 if ( existingSession ) {
15421556 await existingSession . editingSession . accept ( ) ;
15431557 existingSession . dispose ( ) ;
15441558 }
15451559
15461560 this . _isActiveController . set ( true , undefined ) ;
15471561
1548- const session = await this . _inlineChatSessions . createSession2 ( this . _editor , uri , CancellationToken . None ) ;
1562+ const session = await this . _inlineChatSessionService . createSession2 ( this . _editor , uri , CancellationToken . None ) ;
15491563
15501564 // ADD diagnostics
15511565 const entries : IChatRequestVariableEntry [ ] = [ ] ;
0 commit comments