From 41d723968d7a712e67fdaeb1b710f64a5c151e22 Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Fri, 17 Jun 2022 17:08:30 -0400 Subject: [PATCH 1/4] DataViewer in webviews serviceRegistry.web.ts --- .../data-viewing/dataViewer.unit.test.ts | 2 +- .../variableView/variableView.vscode.test.ts | 2 +- .../{dataViewer.node.ts => dataViewer.ts} | 24 +++++++++++-------- ...r.node.ts => dataViewerMessageListener.ts} | 0 .../plotting/plotViewer.node.ts | 2 +- .../extension-side/serviceRegistry.node.ts | 2 +- .../extension-side/serviceRegistry.web.ts | 3 +++ ...wPanelHost.node.ts => webviewPanelHost.ts} | 0 8 files changed, 21 insertions(+), 14 deletions(-) rename src/webviews/extension-side/dataviewer/{dataViewer.node.ts => dataViewer.ts} (96%) rename src/webviews/extension-side/dataviewer/{dataViewerMessageListener.node.ts => dataViewerMessageListener.ts} (100%) rename src/webviews/extension-side/{webviewPanelHost.node.ts => webviewPanelHost.ts} (100%) diff --git a/src/test/datascience/data-viewing/dataViewer.unit.test.ts b/src/test/datascience/data-viewing/dataViewer.unit.test.ts index 4a8ab92a39b..4012e9c1c0c 100644 --- a/src/test/datascience/data-viewing/dataViewer.unit.test.ts +++ b/src/test/datascience/data-viewing/dataViewer.unit.test.ts @@ -17,7 +17,7 @@ import { JupyterSettings } from '../../../platform/common/configSettings'; import { ConfigurationService } from '../../../platform/common/configuration/service.node'; import { IConfigurationService } from '../../../platform/common/types'; import { IDataScienceErrorHandler } from '../../../platform/errors/types'; -import { DataViewer } from '../../../webviews/extension-side/dataviewer/dataViewer.node'; +import { DataViewer } from '../../../webviews/extension-side/dataviewer/dataViewer'; import { JupyterVariableDataProvider } from '../../../webviews/extension-side/dataviewer/jupyterVariableDataProvider'; import { IDataViewer, IDataViewerDataProvider } from '../../../webviews/extension-side/dataviewer/types'; import { MockMemento } from '../../mocks/mementos'; diff --git a/src/test/datascience/variableView/variableView.vscode.test.ts b/src/test/datascience/variableView/variableView.vscode.test.ts index 04970f1dbb6..3d69f32c00d 100644 --- a/src/test/datascience/variableView/variableView.vscode.test.ts +++ b/src/test/datascience/variableView/variableView.vscode.test.ts @@ -24,7 +24,7 @@ import { traceInfo } from '../../../platform/logging'; import { PythonEnvironment } from '../../../platform/pythonEnvironments/info'; import { IInterpreterService } from '../../../platform/interpreter/contracts'; import { Commands } from '../../../platform/common/constants'; -import { DataViewer } from '../../../webviews/extension-side/dataviewer/dataViewer.node'; +import { DataViewer } from '../../../webviews/extension-side/dataviewer/dataViewer'; import { IVariableViewProvider } from '../../../webviews/extension-side/variablesView/types'; suite('DataScience - VariableView', function () { diff --git a/src/webviews/extension-side/dataviewer/dataViewer.node.ts b/src/webviews/extension-side/dataviewer/dataViewer.ts similarity index 96% rename from src/webviews/extension-side/dataviewer/dataViewer.node.ts rename to src/webviews/extension-side/dataviewer/dataViewer.ts index b113effbe00..df72c39e36b 100644 --- a/src/webviews/extension-side/dataviewer/dataViewer.node.ts +++ b/src/webviews/extension-side/dataviewer/dataViewer.ts @@ -8,7 +8,7 @@ import { EventEmitter, Memento, Uri, ViewColumn } from 'vscode'; import { sendTelemetryEvent } from '../../../telemetry'; import { JupyterDataRateLimitError } from '../../../platform/errors/jupyterDataRateLimitError'; -import { DataViewerMessageListener } from './dataViewerMessageListener.node'; +import { DataViewerMessageListener } from './dataViewerMessageListener'; import { DataViewerMessages, IDataFrameInfo, @@ -19,10 +19,7 @@ import { IGetSliceRequest, IJupyterVariableDataProvider } from './types'; -import { - isValidSliceExpression, - preselectedSliceExpression -} from '../../../webviews/webview-side/data-explorer/helpers'; +import { isValidSliceExpression, preselectedSliceExpression } from '../../webview-side/data-explorer/helpers'; import { CheckboxState } from '../../../telemetry/constants'; import { IKernel } from '../../../kernels/types'; import { @@ -32,19 +29,24 @@ import { } from '../../../platform/common/application/types'; import { HelpLinks } from '../../../platform/common/constants'; import { traceError, traceInfo } from '../../../platform/logging'; -import { IConfigurationService, IMemento, GLOBAL_MEMENTO, Resource, IDisposable } from '../../../platform/common/types'; +import { + IConfigurationService, + IMemento, + GLOBAL_MEMENTO, + Resource, + IDisposable, + IExtensionContext +} from '../../../platform/common/types'; import * as localize from '../../../platform/common/utils/localize'; import { StopWatch } from '../../../platform/common/utils/stopWatch'; -import { EXTENSION_ROOT_DIR } from '../../../platform/constants.node'; import { IDataScienceErrorHandler } from '../../../platform/errors/types'; import { Telemetry } from '../../webview-side/common/constants'; import { WebViewViewChangeEventArgs } from '../types'; -import { WebviewPanelHost } from '../webviewPanelHost.node'; +import { WebviewPanelHost } from '../webviewPanelHost'; import { noop } from '../../../platform/common/utils/misc'; import { joinPath } from '../../../platform/vscode-path/resources'; const PREFERRED_VIEWGROUP = 'JupyterDataViewerPreferredViewColumn'; -const dataExplorerDir = joinPath(Uri.file(EXTENSION_ROOT_DIR), 'out', 'webviews', 'webview-side', 'viewers'); @injectable() export class DataViewer extends WebviewPanelHost implements IDataViewer, IDisposable { private dataProvider: IDataViewerDataProvider | IJupyterVariableDataProvider | undefined; @@ -79,8 +81,10 @@ export class DataViewer extends WebviewPanelHost implements @inject(IWorkspaceService) workspaceService: IWorkspaceService, @inject(IApplicationShell) private applicationShell: IApplicationShell, @inject(IMemento) @named(GLOBAL_MEMENTO) readonly globalMemento: Memento, - @inject(IDataScienceErrorHandler) readonly errorHandler: IDataScienceErrorHandler + @inject(IDataScienceErrorHandler) readonly errorHandler: IDataScienceErrorHandler, + @inject(IExtensionContext) readonly context: IExtensionContext ) { + const dataExplorerDir = joinPath(context.extensionUri, 'out', 'webviews', 'webview-side', 'viewers'); super( configuration, provider, diff --git a/src/webviews/extension-side/dataviewer/dataViewerMessageListener.node.ts b/src/webviews/extension-side/dataviewer/dataViewerMessageListener.ts similarity index 100% rename from src/webviews/extension-side/dataviewer/dataViewerMessageListener.node.ts rename to src/webviews/extension-side/dataviewer/dataViewerMessageListener.ts diff --git a/src/webviews/extension-side/plotting/plotViewer.node.ts b/src/webviews/extension-side/plotting/plotViewer.node.ts index 15f1c4dbb90..57481833015 100644 --- a/src/webviews/extension-side/plotting/plotViewer.node.ts +++ b/src/webviews/extension-side/plotting/plotViewer.node.ts @@ -20,7 +20,7 @@ import { IConfigurationService, IDisposable } from '../../../platform/common/typ import { IFileSystemNode } from '../../../platform/common/platform/types.node'; import * as localize from '../../../platform/common/utils/localize'; import { EXTENSION_ROOT_DIR } from '../../../platform/constants.node'; -import { WebviewPanelHost } from '../webviewPanelHost.node'; +import { WebviewPanelHost } from '../webviewPanelHost'; import { joinPath } from '../../../platform/vscode-path/resources'; import { noop } from '../../../platform/common/utils/misc'; diff --git a/src/webviews/extension-side/serviceRegistry.node.ts b/src/webviews/extension-side/serviceRegistry.node.ts index 479664f7c0c..62503748549 100644 --- a/src/webviews/extension-side/serviceRegistry.node.ts +++ b/src/webviews/extension-side/serviceRegistry.node.ts @@ -28,7 +28,7 @@ import { RendererCommunication } from './plotView/rendererCommunication.node'; import { PlotSaveHandler } from './plotView/plotSaveHandler.node'; import { PlotViewHandler } from './plotView/plotViewHandler.node'; import { DataViewerCommandRegistry } from './dataviewer/dataViewerCommandRegistry'; -import { DataViewer } from './dataviewer/dataViewer.node'; +import { DataViewer } from './dataviewer/dataViewer'; import { IPlotViewer, IPlotViewerProvider } from './plotting/types'; import { PlotViewer } from './plotting/plotViewer.node'; import { DataViewerDependencyService } from './dataviewer/dataViewerDependencyService.node'; diff --git a/src/webviews/extension-side/serviceRegistry.web.ts b/src/webviews/extension-side/serviceRegistry.web.ts index 3af7a6602c9..78725f390d3 100644 --- a/src/webviews/extension-side/serviceRegistry.web.ts +++ b/src/webviews/extension-side/serviceRegistry.web.ts @@ -13,6 +13,7 @@ import { VariableViewProvider } from './variablesView/variableViewProvider'; import { JupyterVariableDataProvider } from './dataviewer/jupyterVariableDataProvider'; import { JupyterVariableDataProviderFactory } from './dataviewer/jupyterVariableDataProviderFactory'; import { + IDataViewer, IDataViewerFactory, IJupyterVariableDataProvider, IJupyterVariableDataProviderFactory @@ -24,6 +25,7 @@ import { DataViewerFactory } from './dataviewer/dataViewerFactory'; import { ExtensionSideRenderer, IExtensionSideRenderer } from './renderer'; import { ActiveEditorContextService } from './activeEditorContext'; import { GlobalActivation } from './globalActivation'; +import { DataViewer } from './dataviewer/dataViewer'; export function registerTypes(serviceManager: IServiceManager, _isDevMode: boolean) { serviceManager.addSingleton(IExtensionSingleActivationService, GlobalActivation); @@ -36,6 +38,7 @@ export function registerTypes(serviceManager: IServiceManager, _isDevMode: boole serviceManager.add(IWebviewPanelProvider, WebviewPanelProvider); // Data viewer + serviceManager.add(IDataViewer, DataViewer); serviceManager.addSingleton(IDataViewerFactory, DataViewerFactory); serviceManager.addSingleton( IExtensionSingleActivationService, diff --git a/src/webviews/extension-side/webviewPanelHost.node.ts b/src/webviews/extension-side/webviewPanelHost.ts similarity index 100% rename from src/webviews/extension-side/webviewPanelHost.node.ts rename to src/webviews/extension-side/webviewPanelHost.ts From 3447a746d33cf85a9f69922a31e697e4d383a263 Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Fri, 17 Jun 2022 18:12:20 -0400 Subject: [PATCH 2/4] Sending the new number of parameters to the DataViewer in the tests --- src/test/datascience/data-viewing/dataViewer.unit.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/datascience/data-viewing/dataViewer.unit.test.ts b/src/test/datascience/data-viewing/dataViewer.unit.test.ts index 4012e9c1c0c..3e3c8a26317 100644 --- a/src/test/datascience/data-viewing/dataViewer.unit.test.ts +++ b/src/test/datascience/data-viewing/dataViewer.unit.test.ts @@ -15,7 +15,7 @@ import { WebviewPanelProvider } from '../../../webviews/extension-side/webviewPa import { WorkspaceService } from '../../../platform/common/application/workspace.node'; import { JupyterSettings } from '../../../platform/common/configSettings'; import { ConfigurationService } from '../../../platform/common/configuration/service.node'; -import { IConfigurationService } from '../../../platform/common/types'; +import { IConfigurationService, IExtensionContext } from '../../../platform/common/types'; import { IDataScienceErrorHandler } from '../../../platform/errors/types'; import { DataViewer } from '../../../webviews/extension-side/dataviewer/dataViewer'; import { JupyterVariableDataProvider } from '../../../webviews/extension-side/dataviewer/jupyterVariableDataProvider'; @@ -54,7 +54,8 @@ suite('DataScience - DataViewer', () => { instance(workspaceService), instance(applicationShell), new MockMemento(), - instance(mock()) + instance(mock()), + instance(mock()) ); }); test('Data viewer showData calls gets dataFrame info from data provider', async () => { From ed73fa3f6a055cc0245ca8e1bf93a989485c8e35 Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Fri, 17 Jun 2022 18:23:24 -0400 Subject: [PATCH 3/4] strictPropertyInitialization fixes non-fatal typescript errors that were specially visible in the editor --- tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tsconfig.json b/tsconfig.json index 39da68d83b5..163dd577ed6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,6 +23,7 @@ "resolveJsonModule": true, "removeComments": true, "useUnknownInCatchVariables": false, + "strictPropertyInitialization": false, "types": ["@types/vscode-notebook-renderer/preload", "webpack-env"] }, "exclude": [ From 4fbfc65af294add439446b43a3dbc40dbeaa21a5 Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Fri, 17 Jun 2022 19:19:46 -0400 Subject: [PATCH 4/4] test fix --- src/test/datascience/data-viewing/dataViewer.unit.test.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/test/datascience/data-viewing/dataViewer.unit.test.ts b/src/test/datascience/data-viewing/dataViewer.unit.test.ts index 3e3c8a26317..c046eb44a1a 100644 --- a/src/test/datascience/data-viewing/dataViewer.unit.test.ts +++ b/src/test/datascience/data-viewing/dataViewer.unit.test.ts @@ -4,7 +4,7 @@ 'use strict'; import { anything, instance, mock, verify, when } from 'ts-mockito'; -import { ConfigurationChangeEvent, EventEmitter } from 'vscode'; +import { ConfigurationChangeEvent, EventEmitter, Uri } from 'vscode'; import { ApplicationShell } from '../../../platform/common/application/applicationShell'; import { IApplicationShell, @@ -39,14 +39,16 @@ suite('DataScience - DataViewer', () => { dataProvider = mock(JupyterVariableDataProvider); const settings = mock(JupyterSettings); const settingsChangedEvent = new EventEmitter(); + const context: IExtensionContext = mock(); when(settings.onDidChange).thenReturn(settingsChangedEvent.event); when(configService.getSettings(anything())).thenReturn(instance(settings)); const configChangeEvent = new EventEmitter(); - when(workspaceService.onDidChangeConfiguration).thenReturn(configChangeEvent.event); + when(workspaceService.onDidChangeConfiguration).thenReturn(configChangeEvent.event); when(dataProvider.getDataFrameInfo(anything(), anything())).thenResolve({}); + when(context.extensionUri).thenReturn(Uri.parse('/')); dataViewer = new DataViewer( instance(webPanelProvider), @@ -55,7 +57,7 @@ suite('DataScience - DataViewer', () => { instance(applicationShell), new MockMemento(), instance(mock()), - instance(mock()) + instance(context) ); }); test('Data viewer showData calls gets dataFrame info from data provider', async () => {