@@ -10,7 +10,6 @@ import { CancellationTokenSource } from 'vs/base/common/cancellation';
1010import { toErrorMessage } from 'vs/base/common/errorMessage' ;
1111import { Emitter , Event } from 'vs/base/common/event' ;
1212import { DisposableStore , IDisposable , MutableDisposable , toDisposable } from 'vs/base/common/lifecycle' ;
13- import { isEqual } from 'vs/base/common/resources' ;
1413import { StopWatch } from 'vs/base/common/stopwatch' ;
1514import { assertType } from 'vs/base/common/types' ;
1615import { ICodeEditor } from 'vs/editor/browser/editorBrowser' ;
@@ -35,8 +34,6 @@ import { InlineChatZoneWidget } from 'vs/workbench/contrib/inlineChat/browser/in
3534import { CTX_INLINE_CHAT_HAS_ACTIVE_REQUEST , CTX_INLINE_CHAT_LAST_FEEDBACK , IInlineChatRequest , IInlineChatResponse , INLINE_CHAT_ID , EditMode , InlineChatResponseFeedbackKind , CTX_INLINE_CHAT_LAST_RESPONSE_TYPE , InlineChatResponseType , CTX_INLINE_CHAT_DID_EDIT , CTX_INLINE_CHAT_HAS_STASHED_SESSION , InlineChateResponseTypes , CTX_INLINE_CHAT_RESPONSE_TYPES } from 'vs/workbench/contrib/inlineChat/common/inlineChat' ;
3635import { IChatAccessibilityService , IChatWidgetService } from 'vs/workbench/contrib/chat/browser/chat' ;
3736import { IChatService } from 'vs/workbench/contrib/chat/common/chatService' ;
38- import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorService' ;
39- import { CellUri } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
4037import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
4138import { Lazy } from 'vs/base/common/lazy' ;
4239
@@ -111,7 +108,6 @@ export class InlineChatController implements IEditorContribution {
111108 @ILogService private readonly _logService : ILogService ,
112109 @IConfigurationService private readonly _configurationService : IConfigurationService ,
113110 @IModelService private readonly _modelService : IModelService ,
114- @INotebookEditorService private readonly _notebookEditorService : INotebookEditorService ,
115111 @IDialogService private readonly _dialogService : IDialogService ,
116112 @IContextKeyService contextKeyService : IContextKeyService ,
117113 @IAccessibilityService private readonly _accessibilityService : IAccessibilityService ,
@@ -144,7 +140,7 @@ export class InlineChatController implements IEditorContribution {
144140
145141 dispose ( ) : void {
146142 this . _stashedSession . clear ( ) ;
147- this . _finishExistingSession ( ) ;
143+ this . finishExistingSession ( ) ;
148144 this . _store . dispose ( ) ;
149145 this . _log ( 'controller disposed' ) ;
150146 }
@@ -177,25 +173,13 @@ export class InlineChatController implements IEditorContribution {
177173
178174 async run ( options : InlineChatRunOptions | undefined = { } ) : Promise < void > {
179175 this . _log ( 'session starting' ) ;
180- await this . _finishExistingSession ( ) ;
176+ await this . finishExistingSession ( ) ;
181177 this . _stashedSession . clear ( ) ;
182178
183179 await this . _nextState ( State . CREATE_SESSION , options ) ;
184180 this . _log ( 'session done or paused' ) ;
185181 }
186182
187- private async _finishExistingSession ( ) : Promise < void > {
188- if ( this . _activeSession ) {
189- if ( this . _activeSession . editMode === EditMode . Preview ) {
190- this . _log ( 'finishing existing session, using CANCEL' , this . _activeSession . editMode ) ;
191- this . cancelSession ( ) ;
192- } else {
193- this . _log ( 'finishing existing session, using APPLY' , this . _activeSession . editMode ) ;
194- this . acceptSession ( ) ;
195- }
196- }
197- }
198-
199183 // ---- state machine
200184
201185 private _showWidget ( initialRender : boolean = false ) {
@@ -296,8 +280,6 @@ export class InlineChatController implements IEditorContribution {
296280 // hide/cancel inline completions when invoking IE
297281 InlineCompletionsController . get ( this . _editor ) ?. hide ( ) ;
298282
299- this . _cancelNotebookSiblingEditors ( ) ;
300-
301283 this . _sessionStore . clear ( ) ;
302284
303285 const wholeRangeDecoration = this . _editor . createDecorationsCollection ( ) ;
@@ -348,7 +330,7 @@ export class InlineChatController implements IEditorContribution {
348330
349331 if ( editIsOutsideOfWholeRange ) {
350332 this . _log ( 'text changed outside of whole range, FINISH session' ) ;
351- this . _finishExistingSession ( ) ;
333+ this . finishExistingSession ( ) ;
352334 }
353335 } ) ) ;
354336
@@ -375,35 +357,6 @@ export class InlineChatController implements IEditorContribution {
375357 return result ;
376358 }
377359
378- private _cancelNotebookSiblingEditors ( ) : void {
379- if ( ! this . _editor . hasModel ( ) ) {
380- return ;
381- }
382- const candidate = CellUri . parse ( this . _editor . getModel ( ) . uri ) ;
383- if ( ! candidate ) {
384- return ;
385- }
386- for ( const editor of this . _notebookEditorService . listNotebookEditors ( ) ) {
387- if ( isEqual ( editor . textModel ?. uri , candidate . notebook ) ) {
388- let found = false ;
389- const editors : ICodeEditor [ ] = [ ] ;
390- for ( const [ , codeEditor ] of editor . codeEditors ) {
391- editors . push ( codeEditor ) ;
392- found = codeEditor === this . _editor || found ;
393- }
394- if ( found ) {
395- // found the this editor in the outer notebook editor -> make sure to
396- // cancel all sibling sessions
397- for ( const editor of editors ) {
398- if ( editor !== this . _editor ) {
399- InlineChatController . get ( editor ) ?. _finishExistingSession ( ) ;
400- }
401- }
402- break ;
403- }
404- }
405- }
406- }
407360
408361 private async [ State . WAIT_FOR_INPUT ] ( options : InlineChatRunOptions ) : Promise < State . ACCEPT | State . CANCEL | State . PAUSE | State . WAIT_FOR_INPUT | State . MAKE_REQUEST > {
409362 assertType ( this . _activeSession ) ;
@@ -818,6 +771,18 @@ export class InlineChatController implements IEditorContribution {
818771 return result ;
819772 }
820773
774+ async finishExistingSession ( ) : Promise < void > {
775+ if ( this . _activeSession ) {
776+ if ( this . _activeSession . editMode === EditMode . Preview ) {
777+ this . _log ( 'finishing existing session, using CANCEL' , this . _activeSession . editMode ) ;
778+ this . cancelSession ( ) ;
779+ } else {
780+ this . _log ( 'finishing existing session, using APPLY' , this . _activeSession . editMode ) ;
781+ this . acceptSession ( ) ;
782+ }
783+ }
784+ }
785+
821786 unstashLastSession ( ) : Session | undefined {
822787 return this . _stashedSession . value ?. unstash ( ) ;
823788 }
0 commit comments