55
66import { inject , injectable , multiInject , named , optional } from 'inversify' ;
77import { CodeLens , ConfigurationTarget , env , Range , Uri } from 'vscode' ;
8+ import { DebugProtocol } from 'vscode-debugprotocol' ;
89import { ICommandNameArgumentTypeMapping } from '../../common/application/commands' ;
910import { IApplicationShell , ICommandManager , IDebugService , IDocumentManager } from '../../common/application/types' ;
1011import { Commands as coreCommands } from '../../common/constants' ;
12+ import { traceError } from '../../common/logger' ;
1113
1214import { IStartPage } from '../../common/startPage/types' ;
1315import { IConfigurationService , IDisposable , IOutputChannel } from '../../common/types' ;
1416import { DataScience } from '../../common/utils/localize' ;
1517import { noop } from '../../common/utils/misc' ;
1618import { captureTelemetry , sendTelemetryEvent } from '../../telemetry' ;
1719import { Commands , JUPYTER_OUTPUT_CHANNEL , Telemetry } from '../constants' ;
20+ import { IDataViewerFactory } from '../data-viewing/types' ;
21+ import { DataViewerChecker } from '../interactive-common/dataViewerChecker' ;
22+ import { IShowDataViewerFromVariablePanel } from '../interactive-common/interactiveWindowTypes' ;
23+ import { convertDebugProtocolVariableToIJupyterVariable } from '../jupyter/debuggerVariables' ;
1824import {
1925 ICodeWatcher ,
2026 IDataScienceCodeLensProvider ,
2127 IDataScienceCommandListener ,
2228 IDataScienceFileSystem ,
29+ IJupyterVariableDataProviderFactory ,
2330 INotebookEditorProvider
2431} from '../types' ;
2532import { JupyterCommandLineSelectorCommand } from './commandLineSelector' ;
@@ -30,6 +37,7 @@ import { JupyterServerSelectorCommand } from './serverSelector';
3037@injectable ( )
3138export class CommandRegistry implements IDisposable {
3239 private readonly disposables : IDisposable [ ] = [ ] ;
40+ private dataViewerChecker : DataViewerChecker ;
3341 constructor (
3442 @inject ( IDocumentManager ) private documentManager : IDocumentManager ,
3543 @inject ( IDataScienceCodeLensProvider ) private dataScienceCodeLensProvider : IDataScienceCodeLensProvider ,
@@ -48,10 +56,14 @@ export class CommandRegistry implements IDisposable {
4856 @inject ( IOutputChannel ) @named ( JUPYTER_OUTPUT_CHANNEL ) private jupyterOutput : IOutputChannel ,
4957 @inject ( IStartPage ) private startPage : IStartPage ,
5058 @inject ( ExportCommands ) private readonly exportCommand : ExportCommands ,
59+ @inject ( IJupyterVariableDataProviderFactory )
60+ private readonly jupyterVariableDataProviderFactory : IJupyterVariableDataProviderFactory ,
61+ @inject ( IDataViewerFactory ) private readonly dataViewerFactory : IDataViewerFactory ,
5162 @inject ( IDataScienceFileSystem ) private readonly fs : IDataScienceFileSystem
5263 ) {
5364 this . disposables . push ( this . serverSelectedCommand ) ;
5465 this . disposables . push ( this . notebookCommands ) ;
66+ this . dataViewerChecker = new DataViewerChecker ( configService , appShell ) ;
5567 }
5668 public register ( ) {
5769 this . commandLineCommand . register ( ) ;
@@ -96,6 +108,7 @@ export class CommandRegistry implements IDisposable {
96108 this . registerCommand ( Commands . ViewJupyterOutput , this . viewJupyterOutput ) ;
97109 this . registerCommand ( Commands . GatherQuality , this . reportGatherQuality ) ;
98110 this . registerCommand ( Commands . LatestExtension , this . openPythonExtensionPage ) ;
111+ this . registerCommand ( Commands . ShowDataViewer , this . onVariablePanelShowDataViewerRequest ) ;
99112 this . registerCommand (
100113 Commands . EnableLoadingWidgetsFrom3rdPartySource ,
101114 this . enableLoadingWidgetScriptsFromThirdParty
@@ -466,4 +479,29 @@ export class CommandRegistry implements IDisposable {
466479 private openPythonExtensionPage ( ) {
467480 env . openExternal ( Uri . parse ( `https://marketplace.visualstudio.com/items?itemName=ms-python.python` ) ) ;
468481 }
482+
483+ private async onVariablePanelShowDataViewerRequest ( request : IShowDataViewerFromVariablePanel ) {
484+ sendTelemetryEvent ( Telemetry . OpenDataViewerFromVariableWindowRequest ) ;
485+ if ( this . debugService . activeDebugSession ) {
486+ const jupyterVariable = convertDebugProtocolVariableToIJupyterVariable (
487+ request . variable as DebugProtocol . Variable
488+ ) ;
489+ try {
490+ const jupyterVariableDataProvider = await this . jupyterVariableDataProviderFactory . create (
491+ jupyterVariable
492+ ) ;
493+ const dataFrameInfo = await jupyterVariableDataProvider . getDataFrameInfo ( ) ;
494+ const columnSize = dataFrameInfo ?. columns ?. length ;
495+ if ( columnSize && ( await this . dataViewerChecker . isRequestedColumnSizeAllowed ( columnSize ) ) ) {
496+ const title : string = `${ DataScience . dataExplorerTitle ( ) } - ${ jupyterVariable . name } ` ;
497+ await this . dataViewerFactory . create ( jupyterVariableDataProvider , title ) ;
498+ sendTelemetryEvent ( Telemetry . OpenDataViewerFromVariableWindowSuccess ) ;
499+ }
500+ } catch ( e ) {
501+ sendTelemetryEvent ( Telemetry . OpenDataViewerFromVariableWindowError ) ;
502+ traceError ( e ) ;
503+ this . appShell . showErrorMessage ( e . toString ( ) ) ;
504+ }
505+ }
506+ }
469507}
0 commit comments