Skip to content

Commit 64f8c9d

Browse files
exclude list for variable viewer (microsoft#5186)
1 parent deb3fa7 commit 64f8c9d

6 files changed

Lines changed: 34 additions & 4 deletions

File tree

news/1 Enhancements/5104.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add exclude list to variable viewer

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,12 @@
13881388
"description": "Show the variable explorer in the Python Interactive window. (experimental)",
13891389
"scope": "resource"
13901390
},
1391+
"python.dataScience.variableExplorerExclude": {
1392+
"type": "string",
1393+
"default": "module;builtin_function_or_method",
1394+
"description": "Types to exclude from showing in the Python Interactive variable explorer",
1395+
"scope": "resource"
1396+
},
13911397
"python.dataScience.codeRegularExpression": {
13921398
"type": "string",
13931399
"default": "^(#\\s*%%|#\\s*\\<codecell\\>|#\\s*In\\[\\d*?\\]|#\\s*In\\[ \\])",
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# Query Jupyter server for defined variables list
22
# Tested on 2.7 and 3.6
3-
from sys import getsizeof
3+
from sys import getsizeof as _VSCODE_getsizeof
44
import json as _VSCODE_json
55

66
# who_ls is a Jupyter line magic to fetch currently defined vars
77
_VSCode_JupyterVars = %who_ls
88

99
print(_VSCODE_json.dumps([{'name': var,
1010
'type': type(eval(var)).__name__,
11-
'size': getsizeof(var),
11+
'size': _VSCODE_getsizeof(var),
1212
'expensive': True
1313
} for var in _VSCode_JupyterVars]))
14+
15+
del _VSCode_JupyterVars
16+
del _VSCODE_json
17+
del _VSCODE_getsizeof

pythonFiles/datascience/getJupyterVariableValue.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@
2222
else:
2323
_VSCODE_targetVariable['value'] = _VSCODE_targetValue
2424

25-
print(_VSCODE_json.dumps(_VSCODE_targetVariable))
25+
print(_VSCODE_json.dumps(_VSCODE_targetVariable))
26+
27+
# Cleanup
28+
del _VSCODE_max_len
29+
del _VSCODE_json
30+
del _VSCODE_targetVariable
31+
del _VSCODE_evalResult
32+
del _VSCODE_targetValue

src/client/common/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ export interface IDataScienceSettings {
303303
errorBackgroundColor: string;
304304
ignoreVscodeTheme?: boolean;
305305
showJupyterVariableExplorer?: boolean;
306+
variableExplorerExclude?: string;
306307
}
307308

308309
export const IConfigurationService = Symbol('IConfigurationService');

src/client/datascience/history/history.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,18 @@ export class History extends WebViewHost<IHistoryMapping> implements IHistory {
920920

921921
private requestVariables = async (): Promise<void> => {
922922
// Request our new list of variables
923-
const vars: IJupyterVariable[] = await this.jupyterVariables.getVariables();
923+
let vars: IJupyterVariable[] = await this.jupyterVariables.getVariables();
924+
925+
const settings = this.configuration.getSettings();
926+
const excludeString = settings.datascience.variableExplorerExclude;
927+
928+
if (excludeString) {
929+
const excludeArray = excludeString.split(';');
930+
vars = vars.filter((value) => {
931+
return excludeArray.indexOf(value.type) === -1;
932+
});
933+
}
934+
924935
this.postMessage(HistoryMessages.GetVariablesResponse, vars).ignoreErrors();
925936
}
926937

0 commit comments

Comments
 (0)