Return NotebookEditor
from interactive.open
command (#129084)
* Return NotebookEditor from `interactive.open` command This allows extensions to obtain a reference to the embedded NotebookEditor at creation. Otherwise extensions must look through window.visibleNotebookEditors to obtain a reference to the NotebookEditor and call revealRange for scrolling, and window.visibleNotebookEditors may change in future. Co-authored-by: rebornix <penn.lv@gmail.com> * process argument label Co-authored-by: rebornix <penn.lv@gmail.com>
This commit is contained in:
parent
79e91942bc
commit
a1423e3998
|
@ -174,7 +174,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
|||
const extHostWebviewViews = rpcProtocol.set(ExtHostContext.ExtHostWebviewViews, new ExtHostWebviewViews(rpcProtocol, extHostWebviews));
|
||||
const extHostTesting = rpcProtocol.set(ExtHostContext.ExtHostTesting, new ExtHostTesting(rpcProtocol, extHostCommands));
|
||||
const extHostUriOpeners = rpcProtocol.set(ExtHostContext.ExtHostUriOpeners, new ExtHostUriOpeners(rpcProtocol));
|
||||
rpcProtocol.set(ExtHostContext.ExtHostInteractive, new ExtHostInteractive(rpcProtocol, extHostNotebook, extHostDocumentsAndEditors));
|
||||
rpcProtocol.set(ExtHostContext.ExtHostInteractive, new ExtHostInteractive(rpcProtocol, extHostNotebook, extHostDocumentsAndEditors, extHostCommands));
|
||||
|
||||
// Check that no named customers are missing
|
||||
const expected: ProxyIdentifier<any>[] = values(ExtHostContext);
|
||||
|
|
|
@ -5,15 +5,37 @@
|
|||
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
import { ExtHostInteractiveShape, IMainContext } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { ApiCommand, ApiCommandArgument, ApiCommandResult, ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
|
||||
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
|
||||
import { ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook';
|
||||
import { NotebookEditor } from 'vscode';
|
||||
|
||||
export class ExtHostInteractive implements ExtHostInteractiveShape {
|
||||
constructor(
|
||||
mainContext: IMainContext,
|
||||
private _extHostNotebooks: ExtHostNotebookController,
|
||||
private _textDocumentsAndEditors: ExtHostDocumentsAndEditors,
|
||||
private _commands: ExtHostCommands
|
||||
) {
|
||||
const apiCommand = new ApiCommand(
|
||||
'interactive.open',
|
||||
'_interactive.open',
|
||||
'Open interactive window and return notebook editor and input URI',
|
||||
[
|
||||
new ApiCommandArgument('showOptions', 'Show Options', v => true, v => v),
|
||||
new ApiCommandArgument('resource', 'Interactive resource Uri', v => true, v => v),
|
||||
new ApiCommandArgument('controllerId', 'Notebook controller Id', v => true, v => v),
|
||||
new ApiCommandArgument('title', 'Interactive editor title', v => true, v => v)
|
||||
],
|
||||
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 }) => {
|
||||
if (v.notebookEditorId !== undefined) {
|
||||
const editor = this._extHostNotebooks.getEditorById(v.notebookEditorId);
|
||||
return { notebookUri: URI.revive(v.notebookUri), inputUri: URI.revive(v.inputUri), notebookEditor: editor.apiEditor };
|
||||
}
|
||||
return { notebookUri: URI.revive(v.notebookUri), inputUri: URI.revive(v.inputUri) };
|
||||
})
|
||||
);
|
||||
this._commands.registerApiCommand(apiCommand);
|
||||
}
|
||||
|
||||
$willAddInteractiveDocument(uri: UriComponents, eol: string, modeId: string, notebookUri: UriComponents) {
|
||||
|
|
|
@ -259,7 +259,7 @@ registerSingleton(IInteractiveDocumentService, InteractiveDocumentService);
|
|||
registerAction2(class extends Action2 {
|
||||
constructor() {
|
||||
super({
|
||||
id: 'interactive.open',
|
||||
id: '_interactive.open',
|
||||
title: { value: localize('interactive.open', "Open Interactive Window"), original: 'Open Interactive Window' },
|
||||
f1: false,
|
||||
category: 'Interactive',
|
||||
|
@ -304,7 +304,7 @@ registerAction2(class extends Action2 {
|
|||
});
|
||||
}
|
||||
|
||||
async run(accessor: ServicesAccessor, showOptions?: number | { viewColumn?: number, preserveFocus?: boolean }, resource?: URI, id?: string, title?: string): Promise<{ notebookUri: URI, inputUri: URI; }> {
|
||||
async run(accessor: ServicesAccessor, showOptions?: number | { viewColumn?: number, preserveFocus?: boolean }, resource?: URI, id?: string, title?: string): Promise<{ notebookUri: URI, inputUri: URI; notebookEditorId?: string }> {
|
||||
const editorService = accessor.get(IEditorService);
|
||||
const editorGroupService = accessor.get(IEditorGroupsService);
|
||||
const historyService = accessor.get(IInteractiveHistoryService);
|
||||
|
@ -321,10 +321,13 @@ registerAction2(class extends Action2 {
|
|||
if (editors.length) {
|
||||
const editorInput = editors[0].editor as InteractiveEditorInput;
|
||||
const currentGroup = editors[0].groupId;
|
||||
await editorService.openEditor(editorInput, editorOptions, currentGroup);
|
||||
const editor = await editorService.openEditor(editorInput, editorOptions, currentGroup);
|
||||
const editorControl = editor?.getControl() as { notebookEditor: NotebookEditorWidget | undefined, codeEditor: CodeEditorWidget; } | undefined;
|
||||
|
||||
return {
|
||||
notebookUri: editorInput.resource!,
|
||||
inputUri: editorInput.inputResource
|
||||
inputUri: editorInput.inputResource,
|
||||
notebookEditorId: editorControl?.notebookEditor?.getId()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -356,9 +359,10 @@ registerAction2(class extends Action2 {
|
|||
|
||||
const editorInput = InteractiveEditorInput.create(accessor.get(IInstantiationService), notebookUri, inputUri, title);
|
||||
historyService.clearHistory(notebookUri);
|
||||
await editorService.openEditor(editorInput, { ...editorOptions, pinned: true }, group);
|
||||
const editorPane = await editorService.openEditor(editorInput, editorOptions, group);
|
||||
const editorControl = editorPane?.getControl() as { notebookEditor: NotebookEditorWidget | undefined, codeEditor: CodeEditorWidget; } | undefined;
|
||||
// Extensions must retain references to these URIs to manipulate the interactive editor
|
||||
return { notebookUri, inputUri };
|
||||
return { notebookUri, inputUri, notebookEditorId: editorControl?.notebookEditor?.getId() };
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue