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