Path: blob/main/src/vs/workbench/api/common/extHostInteractive.ts
3296 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 { URI, UriComponents } from '../../../base/common/uri.js';6import { ILogService } from '../../../platform/log/common/log.js';7import { ExtHostInteractiveShape, IMainContext } from './extHost.protocol.js';8import { ApiCommand, ApiCommandArgument, ApiCommandResult, ExtHostCommands } from './extHostCommands.js';9import { ExtHostDocumentsAndEditors } from './extHostDocumentsAndEditors.js';10import { ExtHostNotebookController } from './extHostNotebook.js';11import { NotebookEditor } from 'vscode';1213export class ExtHostInteractive implements ExtHostInteractiveShape {14constructor(15mainContext: IMainContext,16private _extHostNotebooks: ExtHostNotebookController,17private _textDocumentsAndEditors: ExtHostDocumentsAndEditors,18private _commands: ExtHostCommands,19_logService: ILogService20) {21const openApiCommand = new ApiCommand(22'interactive.open',23'_interactive.open',24'Open interactive window and return notebook editor and input URI',25[26new ApiCommandArgument('showOptions', 'Show Options', v => true, v => v),27new ApiCommandArgument('resource', 'Interactive resource Uri', v => true, v => v),28new ApiCommandArgument('controllerId', 'Notebook controller Id', v => true, v => v),29new ApiCommandArgument('title', 'Interactive editor title', v => true, v => v)30],31new ApiCommandResult<{ notebookUri: UriComponents; inputUri: UriComponents; notebookEditorId?: string }, { notebookUri: URI; inputUri: URI; notebookEditor?: NotebookEditor }>('Notebook and input URI', (v: { notebookUri: UriComponents; inputUri: UriComponents; notebookEditorId?: string }) => {32_logService.debug('[ExtHostInteractive] open iw with notebook editor id', v.notebookEditorId);33if (v.notebookEditorId !== undefined) {34const editor = this._extHostNotebooks.getEditorById(v.notebookEditorId);35_logService.debug('[ExtHostInteractive] notebook editor found', editor.id);36return { notebookUri: URI.revive(v.notebookUri), inputUri: URI.revive(v.inputUri), notebookEditor: editor.apiEditor };37}38_logService.debug('[ExtHostInteractive] notebook editor not found, uris for the interactive document', v.notebookUri, v.inputUri);39return { notebookUri: URI.revive(v.notebookUri), inputUri: URI.revive(v.inputUri) };40})41);42this._commands.registerApiCommand(openApiCommand);43}4445$willAddInteractiveDocument(uri: UriComponents, eol: string, languageId: string, notebookUri: UriComponents) {46this._textDocumentsAndEditors.acceptDocumentsAndEditorsDelta({47addedDocuments: [{48EOL: eol,49lines: [''],50languageId: languageId,51uri: uri,52isDirty: false,53versionId: 1,54encoding: 'utf8'55}]56});57}5859$willRemoveInteractiveDocument(uri: UriComponents, notebookUri: UriComponents) {60this._textDocumentsAndEditors.acceptDocumentsAndEditorsDelta({61removedDocuments: [uri]62});63}64}656667