Skip to content

Commit

Permalink
Unify variable viewer data types (#15038)
Browse files Browse the repository at this point in the history
* Unify variable viewer data types

* fix test
  • Loading branch information
rebornix authored Jan 19, 2024
1 parent a5b0cc4 commit 14fc23d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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 &&
Expand All @@ -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(
Expand All @@ -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) {
Expand Down
22 changes: 9 additions & 13 deletions src/webviews/extension-side/variablesView/variableView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,14 @@ export class VariableView extends WebviewViewHost<IVariableViewPanelMapping> 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<QuickPickItem & { command: string }>();
quickPick.title = 'Select DataFrame Viewer';
Expand All @@ -169,20 +172,14 @@ export class VariableView extends WebviewViewHost<IVariableViewPanelMapping> 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);
Expand All @@ -207,7 +204,6 @@ export class VariableView extends WebviewViewHost<IVariableViewPanelMapping> 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) {
Expand Down

0 comments on commit 14fc23d

Please sign in to comment.