Skip to content

Commit 6b66c59

Browse files
authored
Reuse chat editor count in name (microsoft#186799)
Fix microsoft/vscode-copilot#149
1 parent 5556ac2 commit 6b66c59

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/vs/workbench/contrib/chat/browser/chatEditorInput.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { CancellationToken } from 'vs/base/common/cancellation';
77
import { Emitter } from 'vs/base/common/event';
8-
import { Disposable } from 'vs/base/common/lifecycle';
8+
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
99
import { Schemas } from 'vs/base/common/network';
1010
import { URI } from 'vs/base/common/uri';
1111
import * as nls from 'vs/nls';
@@ -18,9 +18,10 @@ import { IChatModel } from 'vs/workbench/contrib/chat/common/chatModel';
1818
import { IChatService } from 'vs/workbench/contrib/chat/common/chatService';
1919

2020
export 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

Comments
 (0)