From d6037cb1ee0312be56befec69954266d8aa2cb23 Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Thu, 26 May 2022 15:25:58 -0400 Subject: [PATCH 1/6] will it work? --- src/kernels/serviceRegistry.node.ts | 2 +- src/kernels/serviceRegistry.web.ts | 28 +++++++++++++++ src/platform/common/application/types.ts | 2 +- .../data-viewing/dataViewer.unit.test.ts | 2 +- .../variableViewTestInterfaces.ts | 2 +- ... => jupyterVariableDataProviderFactory.ts} | 0 .../extension-side/serviceRegistry.node.ts | 6 ++-- .../extension-side/serviceRegistry.web.ts | 22 ++++++++++++ .../{variableView.node.ts => variableView.ts} | 15 +++++--- ...ovider.node.ts => variableViewProvider.ts} | 6 ++-- .../{webviewPanel.node.ts => webviewPanel.ts} | 11 +++--- ...ovider.node.ts => webviewPanelProvider.ts} | 8 ++--- .../{webviewView.node.ts => webviewView.ts} | 13 +++---- ...rovider.node.ts => webviewViewProvider.ts} | 11 +++--- .../webviews/{webview.node.ts => webview.ts} | 35 +++++++++---------- 15 files changed, 110 insertions(+), 53 deletions(-) rename src/webviews/extension-side/dataviewer/{jupyterVariableDataProviderFactory.node.ts => jupyterVariableDataProviderFactory.ts} (100%) create mode 100644 src/webviews/extension-side/serviceRegistry.web.ts rename src/webviews/extension-side/variablesView/{variableView.node.ts => variableView.ts} (97%) rename src/webviews/extension-side/variablesView/{variableViewProvider.node.ts => variableViewProvider.ts} (93%) rename src/webviews/extension-side/webviewPanels/{webviewPanel.node.ts => webviewPanel.ts} (90%) rename src/webviews/extension-side/webviewPanels/{webviewPanelProvider.node.ts => webviewPanelProvider.ts} (85%) rename src/webviews/extension-side/webviewViews/{webviewView.node.ts => webviewView.ts} (82%) rename src/webviews/extension-side/webviewViews/{webviewViewProvider.node.ts => webviewViewProvider.ts} (65%) rename src/webviews/extension-side/webviews/{webview.node.ts => webview.ts} (88%) diff --git a/src/kernels/serviceRegistry.node.ts b/src/kernels/serviceRegistry.node.ts index e3c4b90faf0..1db93901638 100644 --- a/src/kernels/serviceRegistry.node.ts +++ b/src/kernels/serviceRegistry.node.ts @@ -36,7 +36,7 @@ import { PythonVariablesRequester } from './variables/pythonVariableRequester'; import { IInteractiveWindowDebugger } from '../interactive-window/types'; import { MultiplexingDebugService } from './debugger/multiplexingDebugService'; import { JupyterVariableDataProvider } from '../webviews/extension-side/dataviewer/jupyterVariableDataProvider'; -import { JupyterVariableDataProviderFactory } from '../webviews/extension-side/dataviewer/jupyterVariableDataProviderFactory.node'; +import { JupyterVariableDataProviderFactory } from '../webviews/extension-side/dataviewer/jupyterVariableDataProviderFactory'; import { IJupyterVariableDataProvider, IJupyterVariableDataProviderFactory diff --git a/src/kernels/serviceRegistry.web.ts b/src/kernels/serviceRegistry.web.ts index b940b31a14c..988f93c8b44 100644 --- a/src/kernels/serviceRegistry.web.ts +++ b/src/kernels/serviceRegistry.web.ts @@ -22,6 +22,17 @@ import { IDataScienceCommandListener } from '../platform/common/types'; import { KernelCommandListener } from './kernelCommandListener'; import { MultiplexingDebugService } from './debugger/multiplexingDebugService'; import { IJupyterDebugService } from './debugger/types'; +import { JupyterVariableDataProviderFactory } from '../webviews/extension-side/dataviewer/jupyterVariableDataProviderFactory'; +import { + IJupyterVariableDataProvider, + IJupyterVariableDataProviderFactory +} from '../webviews/extension-side/dataviewer/types'; +import { JupyterVariableDataProvider } from '../webviews/extension-side/dataviewer/jupyterVariableDataProvider'; +import { DebuggerVariables } from './variables/debuggerVariables'; +import { IJupyterVariables, IKernelVariableRequester } from './variables/types'; +import { KernelVariables } from './variables/kernelVariables'; +import { JupyterVariables } from './variables/jupyterVariables'; +import { PythonVariablesRequester } from './variables/pythonVariableRequester'; @injectable() class RawNotebookSupportedService implements IRawNotebookSupportedService { @@ -51,11 +62,28 @@ export function registerTypes(serviceManager: IServiceManager, isDevMode: boolea const rawService = serviceManager.get(IRawNotebookSupportedService); setSharedProperty('rawKernelSupported', rawService.isSupported ? 'true' : 'false'); + serviceManager.addSingleton( + IKernelVariableRequester, + PythonVariablesRequester, + Identifiers.PYTHON_VARIABLES_REQUESTER + ); serviceManager.addSingleton( IJupyterDebugService, MultiplexingDebugService, Identifiers.MULTIPLEXING_DEBUGSERVICE ); + serviceManager.addSingleton(IJupyterVariables, JupyterVariables, Identifiers.ALL_VARIABLES); + serviceManager.addSingleton(IJupyterVariables, KernelVariables, Identifiers.KERNEL_VARIABLES); + serviceManager.addSingleton( + IJupyterVariables, + DebuggerVariables, + Identifiers.DEBUGGER_VARIABLES + ); + serviceManager.add(IJupyterVariableDataProvider, JupyterVariableDataProvider); + serviceManager.addSingleton( + IJupyterVariableDataProviderFactory, + JupyterVariableDataProviderFactory + ); serviceManager.addSingleton(IExtensionSyncActivationService, KernelCrashMonitor); serviceManager.addSingleton(IKernelProvider, KernelProvider); diff --git a/src/platform/common/application/types.ts b/src/platform/common/application/types.ts index 0d319dcebfb..179fb39fbf0 100644 --- a/src/platform/common/application/types.ts +++ b/src/platform/common/application/types.ts @@ -1096,7 +1096,7 @@ export interface IWebview { // Wraps the VS Code webview view export const IWebviewView = Symbol('IWebviewView'); export interface IWebviewView extends IWebview { - readonly onDidChangeVisiblity: Event; + readonly onDidChangeVisibility: Event; readonly visible: boolean; } diff --git a/src/test/datascience/data-viewing/dataViewer.unit.test.ts b/src/test/datascience/data-viewing/dataViewer.unit.test.ts index 69a102bf70f..4a8ab92a39b 100644 --- a/src/test/datascience/data-viewing/dataViewer.unit.test.ts +++ b/src/test/datascience/data-viewing/dataViewer.unit.test.ts @@ -11,7 +11,7 @@ import { IWebviewPanelProvider, IWorkspaceService } from '../../../platform/common/application/types'; -import { WebviewPanelProvider } from '../../../webviews/extension-side/webviewPanels/webviewPanelProvider.node'; +import { WebviewPanelProvider } from '../../../webviews/extension-side/webviewPanels/webviewPanelProvider'; import { WorkspaceService } from '../../../platform/common/application/workspace.node'; import { JupyterSettings } from '../../../platform/common/configSettings'; import { ConfigurationService } from '../../../platform/common/configuration/service.node'; diff --git a/src/test/datascience/variableView/variableViewTestInterfaces.ts b/src/test/datascience/variableView/variableViewTestInterfaces.ts index e7f7dca7c24..63516b161d3 100644 --- a/src/test/datascience/variableView/variableViewTestInterfaces.ts +++ b/src/test/datascience/variableView/variableViewTestInterfaces.ts @@ -3,7 +3,7 @@ 'use strict'; import { IVariableViewProvider } from '../../../webviews/extension-side/variablesView/types'; -import { VariableView } from '../../../webviews/extension-side/variablesView/variableView.node'; +import { VariableView } from '../../../webviews/extension-side/variablesView/variableView'; export interface ITestVariableViewProvider extends IVariableViewProvider { readonly activeVariableView: Promise; diff --git a/src/webviews/extension-side/dataviewer/jupyterVariableDataProviderFactory.node.ts b/src/webviews/extension-side/dataviewer/jupyterVariableDataProviderFactory.ts similarity index 100% rename from src/webviews/extension-side/dataviewer/jupyterVariableDataProviderFactory.node.ts rename to src/webviews/extension-side/dataviewer/jupyterVariableDataProviderFactory.ts diff --git a/src/webviews/extension-side/serviceRegistry.node.ts b/src/webviews/extension-side/serviceRegistry.node.ts index a1a279597a5..5782d6c983a 100644 --- a/src/webviews/extension-side/serviceRegistry.node.ts +++ b/src/webviews/extension-side/serviceRegistry.node.ts @@ -7,9 +7,9 @@ import { IWebviewViewProvider, IWebviewPanelProvider } from '../../platform/comm import { IServiceManager } from '../../platform/ioc/types'; import { IVariableViewProvider } from './variablesView/types'; import { VariableViewActivationService } from './variablesView/variableViewActivationService'; -import { VariableViewProvider } from './variablesView/variableViewProvider.node'; -import { WebviewPanelProvider } from './webviewPanels/webviewPanelProvider.node'; -import { WebviewViewProvider } from './webviewViews/webviewViewProvider.node'; +import { VariableViewProvider } from './variablesView/variableViewProvider'; +import { WebviewPanelProvider } from './webviewPanels/webviewPanelProvider'; +import { WebviewViewProvider } from './webviewViews/webviewViewProvider'; export function registerTypes(serviceManager: IServiceManager, _isDevMode: boolean) { serviceManager.add(IWebviewViewProvider, WebviewViewProvider); diff --git a/src/webviews/extension-side/serviceRegistry.web.ts b/src/webviews/extension-side/serviceRegistry.web.ts new file mode 100644 index 00000000000..2bb7651760b --- /dev/null +++ b/src/webviews/extension-side/serviceRegistry.web.ts @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +'use strict'; + +import { IWebviewViewProvider, IWebviewPanelProvider } from '../../platform/common/application/types'; +import { IServiceManager } from '../../platform/ioc/types'; +import { WebviewViewProvider } from './webviewViews/webviewViewProvider'; +import { WebviewPanelProvider } from './webviewPanels/webviewPanelProvider'; +import { IExtensionSingleActivationService } from '../../platform/activation/types'; +import { VariableViewActivationService } from './variablesView/variableViewActivationService'; +import { IVariableViewProvider } from './variablesView/types'; +import { VariableViewProvider } from './variablesView/variableViewProvider'; + +export function registerTypes(serviceManager: IServiceManager, _isDevMode: boolean) { + serviceManager.add(IWebviewViewProvider, WebviewViewProvider); + serviceManager.add(IWebviewPanelProvider, WebviewPanelProvider); + serviceManager.addSingleton( + IExtensionSingleActivationService, + VariableViewActivationService + ); + serviceManager.addSingleton(IVariableViewProvider, VariableViewProvider); +} diff --git a/src/webviews/extension-side/variablesView/variableView.node.ts b/src/webviews/extension-side/variablesView/variableView.ts similarity index 97% rename from src/webviews/extension-side/variablesView/variableView.node.ts rename to src/webviews/extension-side/variablesView/variableView.ts index 96f029a5fa6..be76e00cd48 100644 --- a/src/webviews/extension-side/variablesView/variableView.node.ts +++ b/src/webviews/extension-side/variablesView/variableView.ts @@ -24,17 +24,20 @@ import { } from '../../../platform/common/application/types'; import { ContextKey } from '../../../platform/common/contextKey'; import { traceError } from '../../../platform/logging'; -import { Resource, IConfigurationService, IDisposableRegistry, IDisposable } from '../../../platform/common/types'; +import { + Resource, + IConfigurationService, + IDisposableRegistry, + IDisposable, + IExtensionContext +} from '../../../platform/common/types'; import * as localize from '../../../platform/common/utils/localize'; -import { EXTENSION_ROOT_DIR } from '../../../platform/constants.node'; import { Telemetry } from '../../webview-side/common/constants'; import { DataViewerChecker } from '../dataviewer/dataViewerChecker'; import { IJupyterVariableDataProviderFactory, IDataViewerFactory, IDataViewer } from '../dataviewer/types'; import { WebviewViewHost } from '../webviewViewHost'; import { joinPath } from '../../../platform/vscode-path/resources'; -const variableViewDir = joinPath(Uri.file(EXTENSION_ROOT_DIR), 'out', 'webviews', 'webview-side', 'viewers'); - // This is the client side host for the native notebook variable view webview // It handles passing messages to and from the react view as well as the connection // to execution and changing of the active notebook @@ -47,6 +50,7 @@ export class VariableView extends WebviewViewHost imp configuration: IConfigurationService, workspaceService: IWorkspaceService, provider: IWebviewViewProvider, + context: IExtensionContext, private readonly variables: IJupyterVariables, private readonly disposables: IDisposableRegistry, private readonly appShell: IApplicationShell, @@ -56,6 +60,7 @@ export class VariableView extends WebviewViewHost imp private readonly commandManager: ICommandManager, private readonly documentManager: IDocumentManager ) { + const variableViewDir = joinPath(context.extensionUri, 'out', 'webviews', 'webview-side', 'viewers'); super( configuration, workspaceService, @@ -84,7 +89,7 @@ export class VariableView extends WebviewViewHost imp // After loading, hook up our visibility watch and check the initial visibility if (this.webviewView) { this.disposables.push( - this.webviewView.onDidChangeVisiblity(() => { + this.webviewView.onDidChangeVisibility(() => { this.handleVisibilityChanged(); }) ); diff --git a/src/webviews/extension-side/variablesView/variableViewProvider.node.ts b/src/webviews/extension-side/variablesView/variableViewProvider.ts similarity index 93% rename from src/webviews/extension-side/variablesView/variableViewProvider.node.ts rename to src/webviews/extension-side/variablesView/variableViewProvider.ts index 0a08ab48631..168ae7a3b95 100644 --- a/src/webviews/extension-side/variablesView/variableViewProvider.node.ts +++ b/src/webviews/extension-side/variablesView/variableViewProvider.ts @@ -13,12 +13,12 @@ import { IDocumentManager } from '../../../platform/common/application/types'; import { isTestExecution } from '../../../platform/common/constants'; -import { IConfigurationService, IDisposableRegistry } from '../../../platform/common/types'; +import { IConfigurationService, IDisposableRegistry, IExtensionContext } from '../../../platform/common/types'; import { createDeferred, Deferred } from '../../../platform/common/utils/async'; import { Identifiers } from '../../webview-side/common/constants'; import { IJupyterVariableDataProviderFactory, IDataViewerFactory } from '../dataviewer/types'; import { INotebookWatcher, IVariableViewProvider } from './types'; -import { VariableView } from './variableView.node'; +import { VariableView } from './variableView'; // This class creates our UI for our variable view and links it to the vs code webview view @injectable() @@ -48,6 +48,7 @@ export class VariableViewProvider implements IVariableViewProvider { @inject(IConfigurationService) private readonly configuration: IConfigurationService, @inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService, @inject(IWebviewViewProvider) private readonly webviewViewProvider: IWebviewViewProvider, + @inject(IExtensionContext) private readonly context: IExtensionContext, @inject(IJupyterVariables) @named(Identifiers.ALL_VARIABLES) private variables: IJupyterVariables, @inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry, @inject(IApplicationShell) private readonly appShell: IApplicationShell, @@ -71,6 +72,7 @@ export class VariableViewProvider implements IVariableViewProvider { this.configuration, this.workspaceService, this.webviewViewProvider, + this.context, this.variables, this.disposables, this.appShell, diff --git a/src/webviews/extension-side/webviewPanels/webviewPanel.node.ts b/src/webviews/extension-side/webviewPanels/webviewPanel.ts similarity index 90% rename from src/webviews/extension-side/webviewPanels/webviewPanel.node.ts rename to src/webviews/extension-side/webviewPanels/webviewPanel.ts index ad56691f4ef..607d6a5bc7e 100644 --- a/src/webviews/extension-side/webviewPanels/webviewPanel.node.ts +++ b/src/webviews/extension-side/webviewPanels/webviewPanel.ts @@ -4,10 +4,10 @@ import '../../../platform/common/extensions'; import { Uri, ViewColumn, WebviewOptions, WebviewPanel as vscodeWebviewPanel, window } from 'vscode'; -import { IFileSystemNode } from '../../../platform/common/platform/types.node'; -import { IDisposableRegistry } from '../../../platform/common/types'; +import { IFileSystem } from '../../../platform/common/platform/types'; +import { IDisposableRegistry, IExtensionContext } from '../../../platform/common/types'; import { IWebviewPanel, IWebviewPanelOptions } from '../../../platform/common/application/types'; -import { Webview } from '../webviews/webview.node'; +import { Webview } from '../webviews/webview'; export class WebviewPanel extends Webview implements IWebviewPanel { private get panel(): vscodeWebviewPanel | undefined { @@ -19,12 +19,13 @@ export class WebviewPanel extends Webview implements IWebviewPanel { } constructor( - fs: IFileSystemNode, + fs: IFileSystem, disposableRegistry: IDisposableRegistry, + context: IExtensionContext, panelOptions: IWebviewPanelOptions, additionalRootPaths: Uri[] = [] ) { - super(fs, disposableRegistry, panelOptions, additionalRootPaths); + super(fs, disposableRegistry, context, panelOptions, additionalRootPaths); } public async show(preserveFocus: boolean) { diff --git a/src/webviews/extension-side/webviewPanels/webviewPanelProvider.node.ts b/src/webviews/extension-side/webviewPanels/webviewPanelProvider.ts similarity index 85% rename from src/webviews/extension-side/webviewPanels/webviewPanelProvider.node.ts rename to src/webviews/extension-side/webviewPanels/webviewPanelProvider.ts index b65dc49a72d..3f619c6dc2d 100644 --- a/src/webviews/extension-side/webviewPanels/webviewPanelProvider.node.ts +++ b/src/webviews/extension-side/webviewPanels/webviewPanelProvider.ts @@ -4,16 +4,16 @@ import { inject, injectable } from 'inversify'; import * as path from '../../../platform/vscode-path/path'; import { Uri } from 'vscode'; -import { IFileSystemNode } from '../../../platform/common/platform/types.node'; +import { IFileSystem } from '../../../platform/common/platform/types'; import { IDisposableRegistry, IExtensionContext } from '../../../platform/common/types'; import { IWebviewPanel, IWebviewPanelOptions, IWebviewPanelProvider } from '../../../platform/common/application/types'; -import { WebviewPanel } from './webviewPanel.node'; +import { WebviewPanel } from './webviewPanel'; @injectable() export class WebviewPanelProvider implements IWebviewPanelProvider { constructor( @inject(IDisposableRegistry) private readonly disposableRegistry: IDisposableRegistry, - @inject(IFileSystemNode) private readonly fs: IFileSystemNode, + @inject(IFileSystem) private readonly fs: IFileSystem, @inject(IExtensionContext) private readonly context: IExtensionContext ) {} @@ -25,6 +25,6 @@ export class WebviewPanelProvider implements IWebviewPanelProvider { if (Array.isArray(options.additionalPaths)) { additionalRootPaths.push(...options.additionalPaths); } - return new WebviewPanel(this.fs, this.disposableRegistry, options, additionalRootPaths); + return new WebviewPanel(this.fs, this.disposableRegistry, this.context, options, additionalRootPaths); } } diff --git a/src/webviews/extension-side/webviewViews/webviewView.node.ts b/src/webviews/extension-side/webviewViews/webviewView.ts similarity index 82% rename from src/webviews/extension-side/webviewViews/webviewView.node.ts rename to src/webviews/extension-side/webviewViews/webviewView.ts index 8efda93930c..f39dab7e612 100644 --- a/src/webviews/extension-side/webviewViews/webviewView.node.ts +++ b/src/webviews/extension-side/webviewViews/webviewView.ts @@ -4,9 +4,9 @@ import { Event, EventEmitter, Uri, WebviewOptions, WebviewView as vscodeWebviewView } from 'vscode'; import { IWebviewView, IWebviewViewOptions } from '../../../platform/common/application/types'; -import { IFileSystemNode } from '../../../platform/common/platform/types.node'; -import { IDisposableRegistry } from '../../../platform/common/types'; -import { Webview } from '../webviews/webview.node'; +import { IFileSystem } from '../../../platform/common/platform/types'; +import { IDisposableRegistry, IExtensionContext } from '../../../platform/common/types'; +import { Webview } from '../webviews/webview'; export class WebviewView extends Webview implements IWebviewView { public get visible(): boolean { @@ -16,17 +16,18 @@ export class WebviewView extends Webview implements IWebviewView { return this.webviewHost.visible; } } - public get onDidChangeVisiblity(): Event { + public get onDidChangeVisibility(): Event { return this._onDidChangeVisibility.event; } private readonly _onDidChangeVisibility = new EventEmitter(); constructor( - fs: IFileSystemNode, + fs: IFileSystem, disposableRegistry: IDisposableRegistry, + context: IExtensionContext, private panelOptions: IWebviewViewOptions, additionalRootPaths: Uri[] = [] ) { - super(fs, disposableRegistry, panelOptions, additionalRootPaths); + super(fs, disposableRegistry, context, panelOptions, additionalRootPaths); } protected createWebview(_webviewOptions: WebviewOptions): vscodeWebviewView { diff --git a/src/webviews/extension-side/webviewViews/webviewViewProvider.node.ts b/src/webviews/extension-side/webviewViews/webviewViewProvider.ts similarity index 65% rename from src/webviews/extension-side/webviewViews/webviewViewProvider.node.ts rename to src/webviews/extension-side/webviewViews/webviewViewProvider.ts index 52518c32d29..eb179be6245 100644 --- a/src/webviews/extension-side/webviewViews/webviewViewProvider.node.ts +++ b/src/webviews/extension-side/webviewViews/webviewViewProvider.ts @@ -3,19 +3,20 @@ 'use strict'; import { inject, injectable } from 'inversify'; import { IWebviewViewProvider, IWebviewViewOptions, IWebviewView } from '../../../platform/common/application/types'; -import { IFileSystemNode } from '../../../platform/common/platform/types.node'; -import { IDisposableRegistry } from '../../../platform/common/types'; -import { WebviewView } from './webviewView.node'; +import { IFileSystem } from '../../../platform/common/platform/types'; +import { IDisposableRegistry, IExtensionContext } from '../../../platform/common/types'; +import { WebviewView } from './webviewView'; @injectable() export class WebviewViewProvider implements IWebviewViewProvider { constructor( @inject(IDisposableRegistry) private readonly disposableRegistry: IDisposableRegistry, - @inject(IFileSystemNode) private readonly fs: IFileSystemNode + @inject(IFileSystem) private readonly fs: IFileSystem, + @inject(IExtensionContext) private readonly context: IExtensionContext ) {} // eslint-disable-next-line @typescript-eslint/no-explicit-any public async create(options: IWebviewViewOptions): Promise { - return new WebviewView(this.fs, this.disposableRegistry, options); + return new WebviewView(this.fs, this.disposableRegistry, this.context, options); } } diff --git a/src/webviews/extension-side/webviews/webview.node.ts b/src/webviews/extension-side/webviews/webview.ts similarity index 88% rename from src/webviews/extension-side/webviews/webview.node.ts rename to src/webviews/extension-side/webviews/webview.ts index 7deb05b8aa9..2280052f25d 100644 --- a/src/webviews/extension-side/webviews/webview.node.ts +++ b/src/webviews/extension-side/webviews/webview.ts @@ -3,7 +3,7 @@ 'use strict'; import '../../../platform/common/extensions'; -import * as path from '../../../platform/vscode-path/path'; +import * as uriPath from '../../../platform/vscode-path/resources'; import { Event, EventEmitter, @@ -14,11 +14,11 @@ import { } from 'vscode'; import { IWebview, IWebviewOptions, WebviewMessage } from '../../../platform/common/application/types'; import { traceError } from '../../../platform/logging'; -import { IFileSystemNode } from '../../../platform/common/platform/types.node'; -import { IDisposableRegistry } from '../../../platform/common/types'; +import { IFileSystem } from '../../../platform/common/platform/types'; +import { IDisposableRegistry, IExtensionContext } from '../../../platform/common/types'; import * as localize from '../../../platform/common/utils/localize'; -import { EXTENSION_ROOT_DIR } from '../../../platform/constants.node'; import { Identifiers } from '../../webview-side/common/constants'; +import { joinPath } from '../../../platform/vscode-path/resources'; // Wrapper over a vscode webview. To be used with either WebviewPanel or WebviewView export abstract class Webview implements IWebview { @@ -30,8 +30,9 @@ export abstract class Webview implements IWebview { protected loadPromise: Promise; constructor( - protected fs: IFileSystemNode, + protected fs: IFileSystem, protected disposableRegistry: IDisposableRegistry, + private readonly context: IExtensionContext, protected options: IWebviewOptions, additionalRootPaths: Uri[] = [] ) { @@ -82,22 +83,20 @@ export abstract class Webview implements IWebview { // This method must be called so VSC is aware of files that can be pulled. // Allow js and js.map files to be loaded by webpack in the webview. testFiles - .filter((f) => f.fsPath.toLowerCase().endsWith('.js') || f.fsPath.toLowerCase().endsWith('.js.map')) + .filter((f) => f.fsPath.toLowerCase().endsWith('.js') || uriPath.extname(f).toLowerCase() === '.js.map') .forEach((f) => this.webviewHost?.webview!.asWebviewUri(f)); const rootPath = this.webviewHost.webview.asWebviewUri(this.options.rootPath).toString(); const fontAwesomePath = this.webviewHost.webview .asWebviewUri( - Uri.file( - path.join( - EXTENSION_ROOT_DIR, - 'out', - 'fontAwesome', - 'node_modules', - 'font-awesome', - 'css', - 'font-awesome.min.css' - ) + joinPath( + this.context.extensionUri, + 'out', + 'fontAwesome', + 'node_modules', + 'font-awesome', + 'css', + 'font-awesome.min.css' ) ) .toString(); @@ -145,9 +144,7 @@ export abstract class Webview implements IWebview { private async load() { try { if (this.webviewHost?.webview) { - const localFilesExist = await Promise.all( - this.options.scripts.map((s) => this.fs.localFileExists(s.fsPath)) - ); + const localFilesExist = await Promise.all(this.options.scripts.map((s) => this.fs.exists(s))); if (localFilesExist.every((exists) => exists === true)) { // Call our special function that sticks this script inside of an html page // and translates all of the paths to vscode-resource URIs From 090daefad8c35180496e10cd7a216546256c1ea3 Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Thu, 26 May 2022 15:43:59 -0400 Subject: [PATCH 2/6] lint fixes --- .../extension-side/variablesView/variableView.ts | 4 +--- src/webviews/extension-side/webviews/webview.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/webviews/extension-side/variablesView/variableView.ts b/src/webviews/extension-side/variablesView/variableView.ts index be76e00cd48..e88b11f1ec9 100644 --- a/src/webviews/extension-side/variablesView/variableView.ts +++ b/src/webviews/extension-side/variablesView/variableView.ts @@ -3,7 +3,6 @@ 'use strict'; import '../../../platform/common/extensions'; -import * as path from '../../../platform/vscode-path/path'; import { Uri, WebviewView as vscodeWebviewView } from 'vscode'; import { captureTelemetry, sendTelemetryEvent } from '../../../telemetry'; @@ -78,8 +77,7 @@ export class VariableView extends WebviewViewHost imp this.documentManager.onDidChangeActiveTextEditor(this.activeTextEditorChanged, this, this.disposables); this.dataViewerChecker = new DataViewerChecker(configuration, appShell); - console.log(`Dirname up one is ${path.join(__dirname, '..')}`); - console.log(`Done initing variables`); + console.log(`Done initializing variables`); } @captureTelemetry(Telemetry.NativeVariableViewLoaded) diff --git a/src/webviews/extension-side/webviews/webview.ts b/src/webviews/extension-side/webviews/webview.ts index 2280052f25d..d21807b9aaa 100644 --- a/src/webviews/extension-side/webviews/webview.ts +++ b/src/webviews/extension-side/webviews/webview.ts @@ -83,7 +83,10 @@ export abstract class Webview implements IWebview { // This method must be called so VSC is aware of files that can be pulled. // Allow js and js.map files to be loaded by webpack in the webview. testFiles - .filter((f) => f.fsPath.toLowerCase().endsWith('.js') || uriPath.extname(f).toLowerCase() === '.js.map') + .filter((f) => { + const ext = uriPath.extname(f).toLowerCase(); + return ext === '.js' || ext === '.js.map'; + }) .forEach((f) => this.webviewHost?.webview!.asWebviewUri(f)); const rootPath = this.webviewHost.webview.asWebviewUri(this.options.rootPath).toString(); @@ -101,8 +104,8 @@ export abstract class Webview implements IWebview { ) .toString(); - // Check to see if we should force on Test middleware for our react code - const forceTestMiddleware = process.env.VSC_JUPYTER_WEBVIEW_TEST_MIDDLEWARE || 'false'; + // Change to `true` to force on Test middleware for our react code + const forceTestMiddleware = 'false'; return ` From 7b15848332220840d3a886375e1f87a714542c1f Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Thu, 26 May 2022 15:55:22 -0400 Subject: [PATCH 3/6] added to extension.web.ts --- src/extension.web.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/extension.web.ts b/src/extension.web.ts index 0881d7ffc3b..8f63a60f879 100644 --- a/src/extension.web.ts +++ b/src/extension.web.ts @@ -70,6 +70,7 @@ import { registerTypes as registerNotebookTypes } from './notebooks/serviceRegis import { registerTypes as registerInteractiveTypes } from './interactive-window/serviceRegistry.web'; import { registerTypes as registerIntellisenseTypes } from './intellisense/serviceRegistry.web'; import { registerTypes as registerTerminalTypes } from './platform/terminals/serviceRegistry.web'; +import { registerTypes as registerWebviewTypes } from './webviews/extension-side/serviceRegistry.web'; import { IExtensionActivationManager } from './platform/activation/types'; import { isCI, isTestExecution, STANDARD_OUTPUT_CHANNEL } from './platform/common/constants'; import { getJupyterOutputChannel } from './platform/devTools/jupyterOutputChannel'; @@ -289,6 +290,7 @@ async function activateLegacy( registerInteractiveTypes(serviceManager); registerIntellisenseTypes(serviceManager, isDevMode); registerTerminalTypes(serviceManager); + registerWebviewTypes(serviceManager, isDevMode); // Load the two data science experiments that we need to register types // Await here to keep the register method sync From 52e568771f906f55cfee2b0656bda3793b01f4f3 Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Thu, 26 May 2022 19:31:21 -0400 Subject: [PATCH 4/6] it works, but I need to clean things up --- src/platform/common/net/httpClient.ts | 7 +++++-- src/platform/common/platform/fileSystem.ts | 2 ++ .../extension-side/variablesView/variableView.ts | 5 ++--- src/webviews/extension-side/webviews/webview.ts | 15 ++++++++++++++- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/platform/common/net/httpClient.ts b/src/platform/common/net/httpClient.ts index a35a206b46d..bca967cdd37 100644 --- a/src/platform/common/net/httpClient.ts +++ b/src/platform/common/net/httpClient.ts @@ -11,9 +11,12 @@ import * as fetch from 'cross-fetch'; @injectable() export class HttpClient implements IHttpClient { - public readonly requestOptions: RequestInit; + public readonly requestOptions: RequestInit = {}; constructor(@inject(IWorkspaceService) workspaceService: IWorkspaceService) { - this.requestOptions = { headers: { proxy: workspaceService.getConfiguration('http').get('proxy', '') } }; + const proxy = workspaceService.getConfiguration('http').get('proxy', ''); + if (proxy) { + this.requestOptions = { headers: { proxy: workspaceService.getConfiguration('http').get('proxy', '') } }; + } } public async downloadFile(uri: string): Promise { diff --git a/src/platform/common/platform/fileSystem.ts b/src/platform/common/platform/fileSystem.ts index d3aaff3c43b..8cfcd11e7a6 100644 --- a/src/platform/common/platform/fileSystem.ts +++ b/src/platform/common/platform/fileSystem.ts @@ -34,7 +34,9 @@ export class FileSystem implements IFileSystem { } async getFiles(dir: vscode.Uri): Promise { + console.log('getFiles', { dir }); const files = await this.vscfs.readDirectory(dir); + console.log({ files }); return files.filter((f) => f[1] === vscode.FileType.File).map((f) => vscode.Uri.file(f[0])); } diff --git a/src/webviews/extension-side/variablesView/variableView.ts b/src/webviews/extension-side/variablesView/variableView.ts index e88b11f1ec9..a004801f5fe 100644 --- a/src/webviews/extension-side/variablesView/variableView.ts +++ b/src/webviews/extension-side/variablesView/variableView.ts @@ -35,7 +35,6 @@ import { Telemetry } from '../../webview-side/common/constants'; import { DataViewerChecker } from '../dataviewer/dataViewerChecker'; import { IJupyterVariableDataProviderFactory, IDataViewerFactory, IDataViewer } from '../dataviewer/types'; import { WebviewViewHost } from '../webviewViewHost'; -import { joinPath } from '../../../platform/vscode-path/resources'; // This is the client side host for the native notebook variable view webview // It handles passing messages to and from the react view as well as the connection @@ -59,14 +58,14 @@ export class VariableView extends WebviewViewHost imp private readonly commandManager: ICommandManager, private readonly documentManager: IDocumentManager ) { - const variableViewDir = joinPath(context.extensionUri, 'out', 'webviews', 'webview-side', 'viewers'); + const variableViewDir = Uri.joinPath(context.extensionUri, 'out', 'webviews', 'webview-side', 'viewers'); super( configuration, workspaceService, (c, d) => new VariableViewMessageListener(c, d), provider, variableViewDir, - [joinPath(variableViewDir, 'variableView.js')] + [Uri.joinPath(variableViewDir, 'variableView.js')] ); // Sign up if the active variable view notebook is changed, restarted or updated diff --git a/src/webviews/extension-side/webviews/webview.ts b/src/webviews/extension-side/webviews/webview.ts index d21807b9aaa..915d26b1db4 100644 --- a/src/webviews/extension-side/webviews/webview.ts +++ b/src/webviews/extension-side/webviews/webview.ts @@ -72,13 +72,24 @@ export abstract class Webview implements IWebview { // eslint-disable-next-line @typescript-eslint/no-explicit-any protected async generateLocalReactHtml() { + console.log('AAAAAA'); if (!this.webviewHost?.webview) { throw new Error('WebView not initialized, too early to get a Uri'); } + console.log('BBBBBB'); const uriBase = this.webviewHost?.webview.asWebviewUri(this.options.cwd).toString(); + console.log({ uriBase }); const uris = this.options.scripts.map((script) => this.webviewHost!.webview!.asWebviewUri(script)); - const testFiles = await this.fs.getFiles(this.options.rootPath); + console.log({ uris }); + let testFiles: Uri[] = []; + try { + testFiles = await this.fs.getFiles(this.options.rootPath); + } catch (e) { + console.log(e); + } + + console.log({ testFiles }); // This method must be called so VSC is aware of files that can be pulled. // Allow js and js.map files to be loaded by webpack in the webview. @@ -103,6 +114,7 @@ export abstract class Webview implements IWebview { ) ) .toString(); + console.log({ rootPath, fontAwesomePath }); // Change to `true` to force on Test middleware for our react code const forceTestMiddleware = 'false'; @@ -148,6 +160,7 @@ export abstract class Webview implements IWebview { try { if (this.webviewHost?.webview) { const localFilesExist = await Promise.all(this.options.scripts.map((s) => this.fs.exists(s))); + console.log({ scripts: this.options.scripts, localFilesExist }); if (localFilesExist.every((exists) => exists === true)) { // Call our special function that sticks this script inside of an html page // and translates all of the paths to vscode-resource URIs From bb3729312979f8d2b44bd0d1ef54081b88672872 Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Thu, 26 May 2022 19:44:32 -0400 Subject: [PATCH 5/6] it works! --- src/platform/common/platform/fileSystem.ts | 2 -- .../variablesView/variableView.ts | 7 +++--- .../extension-side/webviews/webview.ts | 23 ------------------- 3 files changed, 3 insertions(+), 29 deletions(-) diff --git a/src/platform/common/platform/fileSystem.ts b/src/platform/common/platform/fileSystem.ts index 8cfcd11e7a6..d3aaff3c43b 100644 --- a/src/platform/common/platform/fileSystem.ts +++ b/src/platform/common/platform/fileSystem.ts @@ -34,9 +34,7 @@ export class FileSystem implements IFileSystem { } async getFiles(dir: vscode.Uri): Promise { - console.log('getFiles', { dir }); const files = await this.vscfs.readDirectory(dir); - console.log({ files }); return files.filter((f) => f[1] === vscode.FileType.File).map((f) => vscode.Uri.file(f[0])); } diff --git a/src/webviews/extension-side/variablesView/variableView.ts b/src/webviews/extension-side/variablesView/variableView.ts index a004801f5fe..067509eebdd 100644 --- a/src/webviews/extension-side/variablesView/variableView.ts +++ b/src/webviews/extension-side/variablesView/variableView.ts @@ -2,9 +2,8 @@ // Licensed under the MIT License. 'use strict'; import '../../../platform/common/extensions'; - import { Uri, WebviewView as vscodeWebviewView } from 'vscode'; - +import { joinPath } from '../../../platform/vscode-path/resources'; import { captureTelemetry, sendTelemetryEvent } from '../../../telemetry'; import { INotebookWatcher, IVariableViewPanelMapping } from './types'; import { VariableViewMessageListener } from './variableViewMessageListener'; @@ -58,14 +57,14 @@ export class VariableView extends WebviewViewHost imp private readonly commandManager: ICommandManager, private readonly documentManager: IDocumentManager ) { - const variableViewDir = Uri.joinPath(context.extensionUri, 'out', 'webviews', 'webview-side', 'viewers'); + const variableViewDir = joinPath(context.extensionUri, 'out', 'webviews', 'webview-side', 'viewers'); super( configuration, workspaceService, (c, d) => new VariableViewMessageListener(c, d), provider, variableViewDir, - [Uri.joinPath(variableViewDir, 'variableView.js')] + [joinPath(variableViewDir, 'variableView.js')] ); // Sign up if the active variable view notebook is changed, restarted or updated diff --git a/src/webviews/extension-side/webviews/webview.ts b/src/webviews/extension-side/webviews/webview.ts index 915d26b1db4..ceea1c06ee3 100644 --- a/src/webviews/extension-side/webviews/webview.ts +++ b/src/webviews/extension-side/webviews/webview.ts @@ -72,33 +72,12 @@ export abstract class Webview implements IWebview { // eslint-disable-next-line @typescript-eslint/no-explicit-any protected async generateLocalReactHtml() { - console.log('AAAAAA'); if (!this.webviewHost?.webview) { throw new Error('WebView not initialized, too early to get a Uri'); } - console.log('BBBBBB'); const uriBase = this.webviewHost?.webview.asWebviewUri(this.options.cwd).toString(); - console.log({ uriBase }); const uris = this.options.scripts.map((script) => this.webviewHost!.webview!.asWebviewUri(script)); - console.log({ uris }); - let testFiles: Uri[] = []; - try { - testFiles = await this.fs.getFiles(this.options.rootPath); - } catch (e) { - console.log(e); - } - - console.log({ testFiles }); - - // This method must be called so VSC is aware of files that can be pulled. - // Allow js and js.map files to be loaded by webpack in the webview. - testFiles - .filter((f) => { - const ext = uriPath.extname(f).toLowerCase(); - return ext === '.js' || ext === '.js.map'; - }) - .forEach((f) => this.webviewHost?.webview!.asWebviewUri(f)); const rootPath = this.webviewHost.webview.asWebviewUri(this.options.rootPath).toString(); const fontAwesomePath = this.webviewHost.webview @@ -114,7 +93,6 @@ export abstract class Webview implements IWebview { ) ) .toString(); - console.log({ rootPath, fontAwesomePath }); // Change to `true` to force on Test middleware for our react code const forceTestMiddleware = 'false'; @@ -160,7 +138,6 @@ export abstract class Webview implements IWebview { try { if (this.webviewHost?.webview) { const localFilesExist = await Promise.all(this.options.scripts.map((s) => this.fs.exists(s))); - console.log({ scripts: this.options.scripts, localFilesExist }); if (localFilesExist.every((exists) => exists === true)) { // Call our special function that sticks this script inside of an html page // and translates all of the paths to vscode-resource URIs From 1ab0e53a9bd80a26748883fba54aba6d70697d71 Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Thu, 26 May 2022 19:56:46 -0400 Subject: [PATCH 6/6] lint fix and re-using the proxy variable --- src/platform/common/net/httpClient.ts | 2 +- src/webviews/extension-side/webviews/webview.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/platform/common/net/httpClient.ts b/src/platform/common/net/httpClient.ts index bca967cdd37..396cff69abf 100644 --- a/src/platform/common/net/httpClient.ts +++ b/src/platform/common/net/httpClient.ts @@ -15,7 +15,7 @@ export class HttpClient implements IHttpClient { constructor(@inject(IWorkspaceService) workspaceService: IWorkspaceService) { const proxy = workspaceService.getConfiguration('http').get('proxy', ''); if (proxy) { - this.requestOptions = { headers: { proxy: workspaceService.getConfiguration('http').get('proxy', '') } }; + this.requestOptions = { headers: { proxy } }; } } diff --git a/src/webviews/extension-side/webviews/webview.ts b/src/webviews/extension-side/webviews/webview.ts index ceea1c06ee3..8922354e67f 100644 --- a/src/webviews/extension-side/webviews/webview.ts +++ b/src/webviews/extension-side/webviews/webview.ts @@ -3,7 +3,6 @@ 'use strict'; import '../../../platform/common/extensions'; -import * as uriPath from '../../../platform/vscode-path/resources'; import { Event, EventEmitter,