5
5
6
6
import { CancellationToken } from 'vs/base/common/cancellation' ;
7
7
import { Emitter } from 'vs/base/common/event' ;
8
- import { Disposable } from 'vs/base/common/lifecycle' ;
8
+ import { Disposable , toDisposable } from 'vs/base/common/lifecycle' ;
9
9
import { Schemas } from 'vs/base/common/network' ;
10
10
import { URI } from 'vs/base/common/uri' ;
11
11
import * as nls from 'vs/nls' ;
@@ -18,9 +18,10 @@ import { IChatModel } from 'vs/workbench/contrib/chat/common/chatModel';
18
18
import { IChatService } from 'vs/workbench/contrib/chat/common/chatService' ;
19
19
20
20
export class ChatEditorInput extends EditorInput {
21
+ static readonly countsInUse = new Set < number > ( ) ;
22
+
21
23
static readonly TypeID : string = 'workbench.input.chatSession' ;
22
24
static readonly EditorID : string = 'workbench.editor.chatSession' ;
23
- static count = 0 ;
24
25
25
26
private readonly inputCount : number ;
26
27
public sessionId : string | undefined ;
@@ -33,6 +34,15 @@ export class ChatEditorInput extends EditorInput {
33
34
return ChatUri . generate ( handle ) ;
34
35
}
35
36
37
+ static getNextCount ( ) : number {
38
+ let count = 0 ;
39
+ while ( ChatEditorInput . countsInUse . has ( count ) ) {
40
+ count ++ ;
41
+ }
42
+
43
+ return count ;
44
+ }
45
+
36
46
constructor (
37
47
readonly resource : URI ,
38
48
readonly options : IChatEditorOptions ,
@@ -47,7 +57,9 @@ export class ChatEditorInput extends EditorInput {
47
57
48
58
this . sessionId = 'sessionId' in options . target ? options . target . sessionId : undefined ;
49
59
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 ) ) ) ;
51
63
}
52
64
53
65
override get editorId ( ) : string | undefined {
0 commit comments