Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/inlineChat/browser/inlineChatNotebook.ts
5231 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { DisposableStore } from '../../../../base/common/lifecycle.js';
7
import { isEqual } from '../../../../base/common/resources.js';
8
import { ICodeEditor } from '../../../../editor/browser/editorBrowser.js';
9
import { InlineChatController } from './inlineChatController.js';
10
import { IInlineChatSessionService } from './inlineChatSessionService.js';
11
import { INotebookEditorService } from '../../notebook/browser/services/notebookEditorService.js';
12
import { CellUri } from '../../notebook/common/notebookCommon.js';
13
import { IEditorService } from '../../../services/editor/common/editorService.js';
14
15
export class InlineChatNotebookContribution {
16
17
private readonly _store = new DisposableStore();
18
19
constructor(
20
@IInlineChatSessionService sessionService: IInlineChatSessionService,
21
@IEditorService editorService: IEditorService,
22
@INotebookEditorService notebookEditorService: INotebookEditorService,
23
) {
24
25
this._store.add(sessionService.onWillStartSession(newSessionEditor => {
26
const candidate = CellUri.parse(newSessionEditor.getModel().uri);
27
if (!candidate) {
28
return;
29
}
30
for (const notebookEditor of notebookEditorService.listNotebookEditors()) {
31
if (isEqual(notebookEditor.textModel?.uri, candidate.notebook)) {
32
let found = false;
33
const editors: ICodeEditor[] = [];
34
for (const [, codeEditor] of notebookEditor.codeEditors) {
35
editors.push(codeEditor);
36
found = codeEditor === newSessionEditor || found;
37
}
38
if (found) {
39
// found the this editor in the outer notebook editor -> make sure to
40
// cancel all sibling sessions
41
for (const editor of editors) {
42
if (editor !== newSessionEditor) {
43
InlineChatController.get(editor)?.acceptSession();
44
}
45
}
46
break;
47
}
48
}
49
}
50
}));
51
}
52
53
dispose(): void {
54
this._store.dispose();
55
}
56
}
57
58