Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,11 @@
"title": "DataScience.latestExtension",
"category": "Python"
},
{
"command": "python.datascience.showDataViewer",
"title": "%python.command.python.datascience.showDataViewer.title%",
"category": "Python"
},
{
"command": "python.analysis.restartLanguageServer",
"title": "%python.command.python.analysis.restartLanguageServer.title%",
Expand Down Expand Up @@ -1655,6 +1660,13 @@
"when": "view == python_tests && viewItem == suite && !busyTests",
"group": "inline@0"
}
],
"debug/variables/context": [
{
"command": "python.datascience.showDataViewer",
"group": "1_view",
"when": "debugProtocolVariableMenuContext == 'viewableInDataViewer'"
}
]
},
"breakpoints": [
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"Datascience.currentlySelectedJupyterInterpreterForPlaceholder": "current: {0}",
"python.command.python.analysis.clearCache.title": "Clear Module Analysis Cache",
"python.command.python.analysis.restartLanguageServer.title": "Restart Language Server",
"python.command.python.datascience.showDataViewer.title": "View Value in Data Viewer",
"python.snippet.launch.standard.label": "Python: Current File",
"python.snippet.launch.module.label": "Python: Module",
"python.snippet.launch.module.default": "enter-your-module-name",
Expand Down
2 changes: 2 additions & 0 deletions src/client/common/application/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { CancellationToken, Position, TextDocument, Uri } from 'vscode';
import { Commands as LSCommands } from '../../activation/commands';
import { Commands as DSCommands } from '../../datascience/constants';
import { IShowDataViewerFromVariablePanel } from '../../datascience/interactive-common/interactiveWindowTypes';
import { KernelConnectionMetadata } from '../../datascience/jupyter/kernels/types';
import { INotebookModel, ISwitchKernelOptions } from '../../datascience/types';
import { CommandSource } from '../../testing/common/constants';
Expand Down Expand Up @@ -204,4 +205,5 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu
[DSCommands.TrustNotebook]: [undefined | never | Uri];
[DSCommands.NotebookEditorExpandAllCells]: [];
[DSCommands.NotebookEditorCollapseAllCells]: [];
[DSCommands.ShowDataViewer]: [IShowDataViewerFromVariablePanel];
}
30 changes: 30 additions & 0 deletions src/client/datascience/commands/commandRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { inject, injectable, multiInject, named, optional } from 'inversify';
import { CodeLens, ConfigurationTarget, env, Range, Uri } from 'vscode';
import { DebugProtocol } from 'vscode-debugprotocol';
import { ICommandNameArgumentTypeMapping } from '../../common/application/commands';
import { IApplicationShell, ICommandManager, IDebugService, IDocumentManager } from '../../common/application/types';
import { Commands as coreCommands } from '../../common/constants';
Expand All @@ -15,11 +16,15 @@ import { DataScience } from '../../common/utils/localize';
import { noop } from '../../common/utils/misc';
import { captureTelemetry, sendTelemetryEvent } from '../../telemetry';
import { Commands, JUPYTER_OUTPUT_CHANNEL, Telemetry } from '../constants';
import { ColumnWarningSize, IDataViewerFactory } from '../data-viewing/types';
import { IShowDataViewerFromVariablePanel } from '../interactive-common/interactiveWindowTypes';
import { convertDebugProtocolVariableToIJupyterVariable } from '../jupyter/debuggerVariables';
import {
ICodeWatcher,
IDataScienceCodeLensProvider,
IDataScienceCommandListener,
IDataScienceFileSystem,
IJupyterVariableDataProviderFactory,
INotebookEditorProvider
} from '../types';
import { JupyterCommandLineSelectorCommand } from './commandLineSelector';
Expand Down Expand Up @@ -48,6 +53,9 @@ export class CommandRegistry implements IDisposable {
@inject(IOutputChannel) @named(JUPYTER_OUTPUT_CHANNEL) private jupyterOutput: IOutputChannel,
@inject(IStartPage) private startPage: IStartPage,
@inject(ExportCommands) private readonly exportCommand: ExportCommands,
@inject(IJupyterVariableDataProviderFactory)
private readonly jupyterVariableDataProviderFactory: IJupyterVariableDataProviderFactory,
@inject(IDataViewerFactory) private readonly dataViewerFactory: IDataViewerFactory,
@inject(IDataScienceFileSystem) private readonly fs: IDataScienceFileSystem
) {
this.disposables.push(this.serverSelectedCommand);
Expand Down Expand Up @@ -96,6 +104,7 @@ export class CommandRegistry implements IDisposable {
this.registerCommand(Commands.ViewJupyterOutput, this.viewJupyterOutput);
this.registerCommand(Commands.GatherQuality, this.reportGatherQuality);
this.registerCommand(Commands.LatestExtension, this.openPythonExtensionPage);
this.registerCommand(Commands.ShowDataViewer, this.onVariablePanelShowDataViewerRequest);
this.registerCommand(
Commands.EnableLoadingWidgetsFrom3rdPartySource,
this.enableLoadingWidgetScriptsFromThirdParty
Expand Down Expand Up @@ -466,4 +475,25 @@ export class CommandRegistry implements IDisposable {
private openPythonExtensionPage() {
env.openExternal(Uri.parse(`https://marketplace.visualstudio.com/items?itemName=ms-python.python`));
}

private async onVariablePanelShowDataViewerRequest(request: IShowDataViewerFromVariablePanel) {
if (this.debugService.activeDebugSession) {
const jupyterVariable = convertDebugProtocolVariableToIJupyterVariable(
request.variable as DebugProtocol.Variable
);
try {
const jupyterVariableDataProvider = await this.jupyterVariableDataProviderFactory.create(
jupyterVariable
);
const dataFrameInfo = await jupyterVariableDataProvider.getDataFrameInfo();
const columnSize = dataFrameInfo?.columns?.length;
if (columnSize && columnSize <= ColumnWarningSize) {
const title: string = `${DataScience.dataExplorerTitle()} - ${jupyterVariable.name}`;
await this.dataViewerFactory.create(jupyterVariableDataProvider, title);
}
} catch (e) {
this.appShell.showErrorMessage(e.toString());
}
}
}
}
1 change: 1 addition & 0 deletions src/client/datascience/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export namespace Commands {
'python.datascience.enableLoadingWidgetScriptsFromThirdPartySource';
export const NotebookEditorExpandAllCells = 'python.datascience.notebookeditor.expandallcells';
export const NotebookEditorCollapseAllCells = 'python.datascience.notebookeditor.collapseallcells';
export const ShowDataViewer = 'python.datascience.showDataViewer';
}

export namespace CodeLensCommands {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ export class JupyterVariableDataProvider implements IJupyterVariableDataProvider
return;
}

public setDependencies(variable: IJupyterVariable, notebook: INotebook): void {
public setDependencies(variable: IJupyterVariable, notebook?: INotebook): void {
this.notebook = notebook;
this.variable = variable;
}

public async getDataFrameInfo(): Promise<IDataFrameInfo> {
let dataFrameInfo: IDataFrameInfo = {};
await this.ensureInitialized();
if (this.variable && this.notebook) {
if (this.variable) {
dataFrameInfo = {
columns: this.variable.columns
? JupyterVariableDataProvider.getNormalizedColumns(this.variable.columns)
Expand All @@ -80,12 +80,12 @@ export class JupyterVariableDataProvider implements IJupyterVariableDataProvider
public async getAllRows() {
let allRows: IRowsResponse = [];
await this.ensureInitialized();
if (this.variable && this.variable.rowCount && this.notebook) {
if (this.variable && this.variable.rowCount) {
const dataFrameRows = await this.variableManager.getDataFrameRows(
this.variable,
this.notebook,
0,
this.variable.rowCount
this.variable.rowCount,
this.notebook
);
allRows = dataFrameRows && dataFrameRows.data ? (dataFrameRows.data as IRowsResponse) : [];
}
Expand All @@ -95,18 +95,18 @@ export class JupyterVariableDataProvider implements IJupyterVariableDataProvider
public async getRows(start: number, end: number) {
let rows: IRowsResponse = [];
await this.ensureInitialized();
if (this.variable && this.variable.rowCount && this.notebook) {
const dataFrameRows = await this.variableManager.getDataFrameRows(this.variable, this.notebook, start, end);
if (this.variable && this.variable.rowCount) {
const dataFrameRows = await this.variableManager.getDataFrameRows(this.variable, start, end, this.notebook);
rows = dataFrameRows && dataFrameRows.data ? (dataFrameRows.data as IRowsResponse) : [];
}
return rows;
}

private async ensureInitialized(): Promise<void> {
// Postpone pre-req and variable initialization until data is requested.
if (!this.initialized && this.variable && this.notebook) {
if (!this.initialized && this.variable) {
this.initialized = true;
await this.dependencyService.checkAndInstallMissingDependencies(this.notebook.getMatchingInterpreter());
await this.dependencyService.checkAndInstallMissingDependencies(this.notebook?.getMatchingInterpreter());
this.variable = await this.variableManager.getDataFrameInfo(this.variable, this.notebook);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {

@injectable()
export class JupyterVariableDataProviderFactory implements IJupyterVariableDataProviderFactory {
constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer) {}
constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer) { }

public async create(variable: IJupyterVariable, notebook: INotebook): Promise<IJupyterVariableDataProvider> {
public async create(variable: IJupyterVariable, notebook?: INotebook): Promise<IJupyterVariableDataProvider> {
const jupyterVariableDataProvider = this.serviceContainer.get<IJupyterVariableDataProvider>(
IJupyterVariableDataProvider
);
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/editor-integration/hoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class HoverProvider implements INotebookExecutionLogger, vscode.HoverProv
if (notebooks && notebooks.length) {
// Just use the first one to reply if more than one.
const match = await Promise.race(
notebooks.map((n) => this.variableProvider.getMatchingVariable(n, word, t))
notebooks.map((n) => this.variableProvider.getMatchingVariable(word, n, t))
);
if (match) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ export class IntellisenseProvider implements IInteractiveWindowListener {
const notebook = await this.getNotebook(token);
if (notebook) {
try {
const value = await this.variableProvider.getMatchingVariable(notebook, wordAtPosition, token);
const value = await this.variableProvider.getMatchingVariable(wordAtPosition, notebook, token);
if (value) {
return {
contents: [`${wordAtPosition}: ${value.type} = ${value.value}`]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ export abstract class InteractiveBase extends WebviewPanelHost<IInteractiveWindo
private async requestVariables(args: IJupyterVariablesRequest): Promise<void> {
// Request our new list of variables
const response: IJupyterVariablesResponse = this._notebook
? await this.jupyterVariables.getVariables(this._notebook, args)
? await this.jupyterVariables.getVariables(args, this._notebook)
: {
totalCount: 0,
pageResponse: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.
'use strict';
import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api';
import { Uri } from 'vscode';
import { DebugProtocolVariable, DebugProtocolVariableContainer, Uri } from 'vscode';
import { DebugState, IServerState } from '../../../datascience-ui/interactive-common/mainState';

import type { KernelMessage } from '@jupyterlab/services';
Expand Down Expand Up @@ -334,6 +334,11 @@ export interface IShowDataViewer {
columnSize: number;
}

export interface IShowDataViewerFromVariablePanel {
container: DebugProtocolVariableContainer | undefined;
variable: DebugProtocolVariable;
}

export interface IRefreshVariablesRequest {
newExecutionCount?: number;
}
Expand Down
Loading