Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed Jun 27, 2022
1 parent b55f2f9 commit 4050478
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def _VSCODE_getDataFrame(what_to_get, *args):
def _VSCODE_getDataFrame(what_to_get, is_debugging, *args):

import pandas as _VSCODE_pd
import builtins as _VSCODE_builtins
Expand Down Expand Up @@ -152,9 +152,13 @@ def _VSCODE_getDataFrameRows(df, start, end):
)
except:
pass
_VSCODE_builtins.print(
_VSCODE_pd_json.to_json(None, df, orient="split", date_format="iso")
)

if is_debugging:
return _VSCODE_pd_json.to_json(None, df, orient="split", date_format="iso")
else:
return _VSCODE_builtins.print(
_VSCODE_pd_json.to_json(None, df, orient="split", date_format="iso")
)

# Function to get info on the passed in data frame
def _VSCODE_getDataFrameInfo(df):
Expand Down Expand Up @@ -205,15 +209,19 @@ def _VSCODE_getDataFrameInfo(df):
target["rowCount"] = rowCount

# return our json object as a string
_VSCODE_builtins.print(_VSCODE_json.dumps(target))

if what_to_get == "rows":
_VSCODE_getDataFrameRows(*args)
else:
_VSCODE_getDataFrameInfo(*args)

del _VSCODE_pd
del _VSCODE_json
del _VSCODE_pd_json
del _VSCODE_np
del _VSCODE_builtins
if is_debugging:
return _VSCODE_json.dumps(target)
else:
return _VSCODE_builtins.print(_VSCODE_json.dumps(target))

try:
if what_to_get == "rows":
return _VSCODE_getDataFrameRows(*args)
else:
return _VSCODE_getDataFrameInfo(*args)
except:
del _VSCODE_pd
del _VSCODE_json
del _VSCODE_pd_json
del _VSCODE_np
del _VSCODE_builtins
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def _VSCODE_getVariable(what_to_get, *args):
def _VSCODE_getVariable(what_to_get, is_debugging, *args):

# Query Jupyter server for the info about a dataframe
import json as _VSCODE_json
Expand Down Expand Up @@ -50,15 +50,21 @@ def _VSCODE_getVariableInfo(var):
pass

# return our json object as a string
_VSCODE_builtins.print(_VSCODE_json.dumps(result))
if is_debugging:
return _VSCODE_json.dumps(result)
else:
return _VSCODE_builtins.print(_VSCODE_json.dumps(result))

def _VSCODE_getVariableProperties(var, listOfAttributes):
result = {
attr: repr(getattr(var, attr))
for attr in listOfAttributes
if hasattr(var, attr)
}
_VSCODE_builtins.print(_VSCODE_json.dumps(result))
if is_debugging:
return _VSCODE_json.dumps(result)
else:
return _VSCODE_builtins.print(_VSCODE_json.dumps(result))

def _VSCODE_getVariableTypes(varnames):
# Map with key: varname and value: vartype
Expand All @@ -70,14 +76,18 @@ def _VSCODE_getVariableTypes(varnames):
result[name] = vartype.__name__
except TypeError:
pass
_VSCODE_builtins.print(_VSCODE_json.dumps(result))
if is_debugging:
return _VSCODE_json.dumps(result)
else:
return _VSCODE_builtins.print(_VSCODE_json.dumps(result))

if what_to_get == "properties":
_VSCODE_getVariableProperties(*args)
elif what_to_get == "info":
_VSCODE_getVariableInfo(*args)
else:
_VSCODE_getVariableTypes(*args)

del _VSCODE_json
del _VSCODE_builtins
try:
if what_to_get == "properties":
return _VSCODE_getVariableProperties(*args)
elif what_to_get == "info":
return _VSCODE_getVariableInfo(*args)
else:
return _VSCODE_getVariableTypes(*args)
finally:
del _VSCODE_json
del _VSCODE_builtins
85 changes: 61 additions & 24 deletions src/kernels/variables/debuggerVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,17 @@ export class DebuggerVariables
}

// Then eval calling the main function with our target variable
const code = await this.dfScriptGenerator.generateCodeToGetDataFrameInfo({
const { cleanupCode, initializeCode, code } = await this.dfScriptGenerator.generateCodeToGetDataFrameInfo({
isDebugging: true,
variableName: expression
});
const results = await this.evaluate(
const results = await this.evaluate({
code,
cleanupCode,
initializeCode,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(targetVariable as any).frameId
);
frameId: (targetVariable as any).frameId
});

const notebook = getAssociatedNotebookDocument(kernel);
let fileName = notebook ? path.basename(notebook.uri.path) : '';
Expand Down Expand Up @@ -208,16 +210,19 @@ export class DebuggerVariables
expression = `${targetVariable.name}${sliceExpression}`;
}

const code = await this.dfScriptGenerator.generateCodeToGetDataFrameRows({
const { cleanupCode, initializeCode, code } = await this.dfScriptGenerator.generateCodeToGetDataFrameRows({
isDebugging: true,
variableName: expression,
startIndex: start,
endIndex: end
});
const results = await this.evaluate(
const results = await this.evaluate({
code,
cleanupCode,
initializeCode,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(targetVariable as any).frameId
);
frameId: (targetVariable as any).frameId
});
return parseDataFrame(JSON.parse(results.result));
}

Expand Down Expand Up @@ -301,35 +306,67 @@ export class DebuggerVariables
this.importedGetVariableInfoScriptsIntoKernel.delete(key);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private async evaluate(code: string, frameId?: number): Promise<any> {
private async evaluate({
code,
cleanupCode,
frameId,
initializeCode
}: {
code: string;
initializeCode?: string;
cleanupCode?: string;
frameId?: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}): Promise<any> {
if (this.debugService.activeDebugSession) {
traceVerbose(`Evaluating in debugger : ${this.debugService.activeDebugSession.id}: ${code}`);
const results = await this.debugService.activeDebugSession.customRequest('evaluate', {
expression: code,
frameId: this.topMostFrameId || frameId,
frameId = this.topMostFrameId || frameId;
const defaultEvalOptions = {
frameId,
context: 'repl',
format: { rawString: true }
});
if (results && results.result !== 'None') {
return results;
} else {
traceError(`Cannot evaluate ${code}`);
return undefined;
};
traceVerbose(`Evaluating in debugger : ${this.debugService.activeDebugSession.id}: ${code}`);
try {
if (initializeCode) {
await this.debugService.activeDebugSession.customRequest('evaluate', {
...defaultEvalOptions,
expression: initializeCode
});
}
const results = await this.debugService.activeDebugSession.customRequest('evaluate', {
...defaultEvalOptions,
expression: code
});
if (results && results.result !== 'None') {
return results;
} else {
traceError(`Cannot evaluate ${code}`);
return undefined;
}
} finally {
if (cleanupCode) {
await this.debugService.activeDebugSession.customRequest('evaluate', {
...defaultEvalOptions,
expression: cleanupCode
});
}
}
}
throw Error('Debugger is not active, cannot evaluate.');
}
public async getFullVariable(variable: IJupyterVariable): Promise<IJupyterVariable> {
// Then eval calling the variable info function with our target variable
const code = await this.varScriptGenerator.generateCodeToGetVariableInfo({
const { initializeCode, code, cleanupCode } = await this.varScriptGenerator.generateCodeToGetVariableInfo({
isDebugging: true,
variableName: variable.name
});
const results = await this.evaluate(
const results = await this.evaluate({
code,
initializeCode,
cleanupCode,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(variable as any).frameId
);
frameId: (variable as any).frameId
});
if (results && results.result) {
// Results should be the updated variable.
return {
Expand Down
Loading

0 comments on commit 4050478

Please sign in to comment.