From 14fc23d695bbabc4bf851815537c31e031ab3304 Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Thu, 18 Jan 2024 23:53:47 -0800 Subject: [PATCH] Unify variable viewer data types (#15038) * Unify variable viewer data types * fix test --- src/commands.ts | 4 ++-- ...DataViewerPythonInterpreter.vscode.test.ts | 15 +++++-------- .../dataviewer/dataViewerCommandRegistry.ts | 11 +++++----- .../variablesView/variableView.ts | 22 ++++++++----------- 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index ec1132a0e51..1c5a9975a91 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -11,10 +11,10 @@ import { Uri, ViewColumn } from 'vscode'; -import { IShowDataViewerFromVariablePanel } from './messageTypes'; import { Commands as DSCommands, CommandSource } from './platform/common/constants'; import { PythonEnvironment } from './platform/pythonEnvironments/info'; import { Channel } from './platform/common/application/types'; +import { IJupyterVariable } from './kernels/variables/types'; export type CommandIds = keyof ICommandNameArgumentTypeMapping; @@ -178,7 +178,7 @@ export interface ICommandNameArgumentTypeMapping { [DSCommands.EnableLoadingWidgetsFrom3rdPartySource]: []; [DSCommands.NotebookEditorExpandAllCells]: []; [DSCommands.NotebookEditorCollapseAllCells]: []; - [DSCommands.ShowDataViewer]: [IShowDataViewerFromVariablePanel]; + [DSCommands.ShowDataViewer]: [IJupyterVariable]; [DSCommands.RefreshDataViewer]: []; [DSCommands.ClearSavedJupyterUris]: []; [DSCommands.RunByLine]: [NotebookCell]; diff --git a/src/test/datascience/data-viewing/showInDataViewerPythonInterpreter.vscode.test.ts b/src/test/datascience/data-viewing/showInDataViewerPythonInterpreter.vscode.test.ts index eecbbf4c2d3..714fc44b4d1 100644 --- a/src/test/datascience/data-viewing/showInDataViewerPythonInterpreter.vscode.test.ts +++ b/src/test/datascience/data-viewing/showInDataViewerPythonInterpreter.vscode.test.ts @@ -14,7 +14,6 @@ import { waitForCondition } from '../../common.node'; import { defaultNotebookTestTimeout } from '../notebook/helper'; import { createDeferred } from '../../../platform/common/utils/async'; import { dispose } from '../../../platform/common/utils/lifecycle'; -import { IShowDataViewerFromVariablePanel } from '../../../messageTypes'; /* eslint-disable @typescript-eslint/no-explicit-any, no-invalid-this */ suite('DataViewer @webview', function () { @@ -106,14 +105,12 @@ suite('DataViewer @webview', function () { await stoppedDef.promise; // Properties that we want to show the data viewer with - const props: IShowDataViewerFromVariablePanel = { - container: {}, - variable: { - evaluateName: 'my_list', - name: 'my_list', - value: '[1, 2, 3]', - variablesReference - } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const props: any = { + evaluateName: 'my_list', + name: 'my_list', + value: '[1, 2, 3]', + variablesReference }; // Run our command to actually open the variable view diff --git a/src/webviews/extension-side/dataviewer/dataViewerCommandRegistry.ts b/src/webviews/extension-side/dataviewer/dataViewerCommandRegistry.ts index 1d3759c60e9..a5521796704 100644 --- a/src/webviews/extension-side/dataviewer/dataViewerCommandRegistry.ts +++ b/src/webviews/extension-side/dataviewer/dataViewerCommandRegistry.ts @@ -5,7 +5,7 @@ import { inject, injectable, named, optional } from 'inversify'; import { DebugConfiguration, Uri, commands, window, workspace } from 'vscode'; import { DebugProtocol } from 'vscode-debugprotocol'; import { convertDebugProtocolVariableToIJupyterVariable } from '../../../kernels/variables/helpers'; -import { IJupyterVariables } from '../../../kernels/variables/types'; +import { IJupyterVariable, IJupyterVariables } from '../../../kernels/variables/types'; import { IExtensionSyncActivationService } from '../../../platform/activation/types'; import { ICommandNameArgumentTypeMapping } from '../../../commands'; import { IDebugService } from '../../../platform/common/application/types'; @@ -17,7 +17,6 @@ import { noop } from '../../../platform/common/utils/misc'; import { untildify } from '../../../platform/common/utils/platform'; import { IInterpreterService } from '../../../platform/interpreter/contracts'; import { traceError, traceInfo } from '../../../platform/logging'; -import { IShowDataViewerFromVariablePanel } from '../../../messageTypes'; import { sendTelemetryEvent } from '../../../telemetry'; import { EventName } from '../../../platform/telemetry/constants'; import { IDataScienceErrorHandler } from '../../../kernels/errors/types'; @@ -73,7 +72,7 @@ export class DataViewerCommandRegistry implements IExtensionSyncActivationServic const disposable = commands.registerCommand(command, callback, this); this.disposables.push(disposable); } - private async onVariablePanelShowDataViewerRequest(request: IShowDataViewerFromVariablePanel) { + private async onVariablePanelShowDataViewerRequest(request: IJupyterVariable) { sendTelemetryEvent(EventName.OPEN_DATAVIEWER_FROM_VARIABLE_WINDOW_REQUEST); if ( this.debugService?.activeDebugSession && @@ -97,7 +96,7 @@ export class DataViewerCommandRegistry implements IExtensionSyncActivationServic } const variable = convertDebugProtocolVariableToIJupyterVariable( - request.variable as DebugProtocol.Variable + request as unknown as DebugProtocol.Variable ); const jupyterVariable = await this.variableProvider.getFullVariable(variable); const jupyterVariableDataProvider = await this.jupyterVariableDataProviderFactory.create( @@ -123,11 +122,11 @@ export class DataViewerCommandRegistry implements IExtensionSyncActivationServic if (activeKernel && this.jupyterVariableDataProviderFactory && this.dataViewerFactory) { // Create a variable data provider and pass it to the data viewer factory to create the data viewer const jupyterVariableDataProvider = await this.jupyterVariableDataProviderFactory.create( - request.variable, + request, activeKernel ); - const title: string = `${DataScience.dataExplorerTitle} - ${request.variable.name}`; + const title: string = `${DataScience.dataExplorerTitle} - ${request.name}`; return await this.dataViewerFactory.create(jupyterVariableDataProvider, title); } } catch (e) { diff --git a/src/webviews/extension-side/variablesView/variableView.ts b/src/webviews/extension-side/variablesView/variableView.ts index 4a927c72648..36d5d86c46d 100644 --- a/src/webviews/extension-side/variablesView/variableView.ts +++ b/src/webviews/extension-side/variablesView/variableView.ts @@ -148,11 +148,14 @@ export class VariableView extends WebviewViewHost imp } else if (variableViewers.length === 1) { const command = variableViewers[0].jupyterVariableViewers.command; // eslint-disable-next-line @typescript-eslint/no-explicit-any - return commands.executeCommand(command as any, { - container: {}, - variable: request.variable - }); + return commands.executeCommand(command as any, request.variable); } else { + const thirdPartyViewers = variableViewers.filter((d) => d.extension.id !== JVSC_EXTENSION_ID); + if (thirdPartyViewers.length === 1) { + const command = thirdPartyViewers[0].jupyterVariableViewers.command; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return commands.executeCommand(command as any, request.variable); + } // show quick pick const quickPick = window.createQuickPick(); quickPick.title = 'Select DataFrame Viewer'; @@ -169,20 +172,14 @@ export class VariableView extends WebviewViewHost imp quickPick.hide(); commands // eslint-disable-next-line @typescript-eslint/no-explicit-any - .executeCommand(item.command as any, { - container: {}, - variable: request.variable - }) + .executeCommand(item.command as any, request.variable) .then(noop, noop); } }); quickPick.show(); } } else { - return commands.executeCommand(Commands.ShowDataViewer, { - container: {}, - variable: request.variable - }); + return commands.executeCommand(Commands.ShowDataViewer, request.variable); } } catch (e) { traceError(e); @@ -207,7 +204,6 @@ export class VariableView extends WebviewViewHost imp e.packageJSON?.contributes?.jupyterVariableViewers && e.packageJSON?.contributes?.jupyterVariableViewers.length ) - .filter((e) => e.id !== JVSC_EXTENSION_ID) .map((e) => { const contributes = e.packageJSON?.contributes; if (contributes?.jupyterVariableViewers) {