add notebook to the text document of the input box in iw.

This commit is contained in:
rebornix
2021-06-25 15:17:51 -07:00
parent 95ac778330
commit b17fa9dcf5
9 changed files with 129 additions and 4 deletions

View File

@@ -66,6 +66,7 @@ import './mainThreadNotebook';
import './mainThreadNotebookKernels';
import './mainThreadNotebookDocumentsAndEditors';
import './mainThreadNotebookRenderers';
import './mainThreadInteractive';
import './mainThreadTask';
import './mainThreadLabelService';
import './mainThreadTunnelService';

View File

@@ -0,0 +1,32 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { DisposableStore } from 'vs/base/common/lifecycle';
import { ExtHostContext, ExtHostInteractiveShape, IExtHostContext, MainContext, MainThreadInteractiveShape } from 'vs/workbench/api/common/extHost.protocol';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { IInteractiveDocumentService } from 'vs/workbench/contrib/interactive/browser/interactiveDocumentService';
@extHostNamedCustomer(MainContext.MainThreadInteractive)
export class MainThreadInteractive implements MainThreadInteractiveShape {
private readonly _proxy: ExtHostInteractiveShape;
private readonly _disposables = new DisposableStore();
constructor(
extHostContext: IExtHostContext,
@IInteractiveDocumentService interactiveDocumentService: IInteractiveDocumentService
) {
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostInteractive);
this._disposables.add(interactiveDocumentService.onWillAddInteractiveDocument((e) => {
this._proxy.$acceptInputDocument(e.inputUri, '\n', 'plaintext', e.notebookUri);
}));
}
dispose(): void {
this._disposables.dispose();
}
}

View File

@@ -90,6 +90,7 @@ import { Schemas } from 'vs/base/common/network';
import { matchesScheme } from 'vs/platform/opener/common/opener';
import { ExtHostNotebookEditors } from 'vs/workbench/api/common/extHostNotebookEditors';
import { ExtHostNotebookDocuments } from 'vs/workbench/api/common/extHostNotebookDocuments';
import { ExtHostInteractive } from 'vs/workbench/api/common/extHostInteractive';
export interface IExtensionApiFactory {
(extension: IExtensionDescription, registry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): typeof vscode;
@@ -173,6 +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));
// Check that no named customers are missing
const expected: ProxyIdentifier<any>[] = values(ExtHostContext);

View File

@@ -44,6 +44,7 @@ import { ThemeColor, ThemeIcon } from 'vs/platform/theme/common/themeService';
import { IExtensionIdWithVersion } from 'vs/platform/userDataSync/common/extensionsStorageSync';
import { WorkspaceTrustRequestOptions } from 'vs/platform/workspace/common/workspaceTrust';
import { ExtensionActivationReason } from 'vs/workbench/api/common/extHostExtensionActivator';
import { ExtHostInteractive } from 'vs/workbench/api/common/extHostInteractive';
import { TunnelDto } from 'vs/workbench/api/common/extHostTunnelService';
import { DebugConfigurationProviderTriggerKind, TestResultState } from 'vs/workbench/api/common/extHostTypes';
import * as tasks from 'vs/workbench/api/common/shared/tasks';
@@ -929,6 +930,9 @@ export interface MainThreadNotebookRenderersShape extends IDisposable {
$postMessage(editorId: string, rendererId: string, message: unknown): void;
}
export interface MainThreadInteractiveShape extends IDisposable {
}
export interface MainThreadUrlsShape extends IDisposable {
$registerUriHandler(handle: number, extensionId: ExtensionIdentifier): Promise<void>;
$unregisterUriHandler(handle: number): Promise<void>;
@@ -2033,6 +2037,10 @@ export interface ExtHostNotebookKernelsShape {
$acceptKernelMessageFromRenderer(handle: number, editorId: string, message: any): void;
}
export interface ExtHostInteractiveShape {
$acceptInputDocument(uri: UriComponents, eol: string, modeId: string, notebookUri: UriComponents): void;
}
export interface ExtHostStorageShape {
$acceptValue(shared: boolean, key: string, value: object | undefined): void;
}
@@ -2173,6 +2181,7 @@ export const MainContext = {
MainThreadNotebookEditors: createMainId<MainThreadNotebookEditorsShape>('MainThreadNotebookEditorsShape'),
MainThreadNotebookKernels: createMainId<MainThreadNotebookKernelsShape>('MainThreadNotebookKernels'),
MainThreadNotebookRenderers: createMainId<MainThreadNotebookRenderersShape>('MainThreadNotebookRenderers'),
MainThreadInteractive: createMainId<MainThreadInteractiveShape>('MainThreadInteractive'),
MainThreadTheming: createMainId<MainThreadThemingShape>('MainThreadTheming'),
MainThreadTunnelService: createMainId<MainThreadTunnelServiceShape>('MainThreadTunnelService'),
MainThreadTimeline: createMainId<MainThreadTimelineShape>('MainThreadTimeline'),
@@ -2223,6 +2232,7 @@ export const ExtHostContext = {
ExtHostNotebookEditors: createMainId<ExtHostNotebookEditorsShape>('ExtHostNotebookEditors'),
ExtHostNotebookKernels: createMainId<ExtHostNotebookKernelsShape>('ExtHostNotebookKernels'),
ExtHostNotebookRenderers: createMainId<ExtHostNotebookRenderersShape>('ExtHostNotebookRenderers'),
ExtHostInteractive: createMainId<ExtHostInteractive>('ExtHostInteractive'),
ExtHostTheming: createMainId<ExtHostThemingShape>('ExtHostTheming'),
ExtHostTunnelService: createMainId<ExtHostTunnelServiceShape>('ExtHostTunnelService'),
ExtHostAuthentication: createMainId<ExtHostAuthenticationShape>('ExtHostAuthentication'),

View File

@@ -92,7 +92,7 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha
// double check -> only notebook cell documents should be
// referenced/opened more than once...
if (ref) {
if (resource.scheme !== Schemas.vscodeNotebookCell) {
if (resource.scheme !== Schemas.vscodeNotebookCell && resource.scheme !== Schemas.vscodeInteractiveInput) {
throw new Error(`document '${resource} already exists!'`);
}
}

View File

@@ -0,0 +1,32 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { URI, UriComponents } from 'vs/base/common/uri';
import { ExtHostInteractiveShape, IMainContext } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
import { ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook';
export class ExtHostInteractive implements ExtHostInteractiveShape {
constructor(
mainContext: IMainContext,
private _extHostNotebooks: ExtHostNotebookController,
private _textDocumentsAndEditors: ExtHostDocumentsAndEditors,
) {
}
$acceptInputDocument(uri: UriComponents, eol: string, modeId: string, notebookUri: UriComponents) {
this._textDocumentsAndEditors.acceptDocumentsAndEditorsDelta({
addedDocuments: [{
EOL: eol,
lines: [''],
modeId: modeId,
uri: uri,
isDirty: false,
versionId: 1,
notebook: this._extHostNotebooks.getNotebookDocument(URI.revive(notebookUri))?.apiNotebook
}]
});
}
}