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