55
66import { CancellationToken } from 'vs/base/common/cancellation' ;
77import { Emitter } from 'vs/base/common/event' ;
8- import { Disposable } from 'vs/base/common/lifecycle' ;
8+ import { Disposable , toDisposable } from 'vs/base/common/lifecycle' ;
99import { Schemas } from 'vs/base/common/network' ;
1010import { URI } from 'vs/base/common/uri' ;
1111import * as nls from 'vs/nls' ;
@@ -18,9 +18,10 @@ import { IChatModel } from 'vs/workbench/contrib/chat/common/chatModel';
1818import { IChatService } from 'vs/workbench/contrib/chat/common/chatService' ;
1919
2020export class ChatEditorInput extends EditorInput {
21+ static readonly countsInUse = new Set < number > ( ) ;
22+
2123 static readonly TypeID : string = 'workbench.input.chatSession' ;
2224 static readonly EditorID : string = 'workbench.editor.chatSession' ;
23- static count = 0 ;
2425
2526 private readonly inputCount : number ;
2627 public sessionId : string | undefined ;
@@ -33,6 +34,15 @@ export class ChatEditorInput extends EditorInput {
3334 return ChatUri . generate ( handle ) ;
3435 }
3536
37+ static getNextCount ( ) : number {
38+ let count = 0 ;
39+ while ( ChatEditorInput . countsInUse . has ( count ) ) {
40+ count ++ ;
41+ }
42+
43+ return count ;
44+ }
45+
3646 constructor (
3747 readonly resource : URI ,
3848 readonly options : IChatEditorOptions ,
@@ -47,7 +57,9 @@ export class ChatEditorInput extends EditorInput {
4757
4858 this . sessionId = 'sessionId' in options . target ? options . target . sessionId : undefined ;
4959 this . providerId = 'providerId' in options . target ? options . target . providerId : undefined ;
50- this . inputCount = ChatEditorInput . count ++ ;
60+ this . inputCount = ChatEditorInput . getNextCount ( ) ;
61+ ChatEditorInput . countsInUse . add ( this . inputCount ) ;
62+ this . _register ( toDisposable ( ( ) => ChatEditorInput . countsInUse . delete ( this . inputCount ) ) ) ;
5163 }
5264
5365 override get editorId ( ) : string | undefined {
0 commit comments