From e5ca20400d486ef13a1d6d98a43bd4f0639c0f64 Mon Sep 17 00:00:00 2001 From: rchiodo Date: Tue, 4 Feb 2020 09:18:00 -0800 Subject: [PATCH 1/3] Fix regexes to work on other platforms --- .../datascience/jupyter/jupyterVariables.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/client/datascience/jupyter/jupyterVariables.ts b/src/client/datascience/jupyter/jupyterVariables.ts index 5f199e175f7d..b0cf7194c4a2 100644 --- a/src/client/datascience/jupyter/jupyterVariables.ts +++ b/src/client/datascience/jupyter/jupyterVariables.ts @@ -23,11 +23,11 @@ import { JupyterDataRateLimitError } from './jupyterDataRateLimitError'; // Regexes for parsing data from Python kernel. Not sure yet if other // kernels will add the ansi encoding. -const TypeRegex = /\u001b\[1;31mType:\u001b\[0m\s+(\w+)/; -const ValueRegex = /\u001b\[1;31mValue:\u001b\[0m\s+(.*)/; -const StringFormRegex = /\u001b\[1;31mString form:\u001b\[0m\s+([\s\S]+?)\n\u001b\[1/; -const DocStringRegex = /\u001b\[1;31mDocstring:\u001b\[0m\s+(.*)/; -const CountRegex = /\u001b\[1;31mLength:\u001b\[0m\s+(.*)/; +const TypeRegex = /.*?\[.*?;31mType:.*?\[0m\s+(\w+)/; +const ValueRegex = /.*?\[.*?;31mValue:.*?\[0m\s+(.*)/; +const StringFormRegex = /.*?\[.*?;31mString form:.*?\[0m\s+([\s\S]+?)\n.*?\[.*?/; +const DocStringRegex = /.*?\[.*?;31mDocstring:.*?\[0m\s+(.*)/; +const CountRegex = /.*?\[.*?;31mLength:.*?\[0m\s+(.*)/; const ShapeRegex = /^\s+\[(\d+) rows x (\d+) columns\]/m; const DataViewableTypes: Set = new Set(['DataFrame', 'list', 'dict', 'np.array', 'Series']); @@ -45,7 +45,7 @@ export class JupyterVariables implements IJupyterVariables { private languageToQueryMap = new Map(); private notebookState = new Map(); - constructor(@inject(IFileSystem) private fileSystem: IFileSystem, @inject(IConfigurationService) private configService: IConfigurationService) {} + constructor(@inject(IFileSystem) private fileSystem: IFileSystem, @inject(IConfigurationService) private configService: IConfigurationService) { } // IJupyterVariables implementation public async getVariables(notebook: INotebook, request: IJupyterVariablesRequest): Promise { @@ -99,7 +99,7 @@ export class JupyterVariables implements IJupyterVariables { } // Prep our targetVariable to send over - const variableString = JSON.stringify(targetVariable).replace('\\n', '\\\\n'); + const variableString = JSON.stringify(targetVariable).replace(/\\n/g, '\\\\n'); // Setup a regex const regexPattern = extraReplacements.length === 0 ? '_VSCode_JupyterTestValue' : ['_VSCode_JupyterTestValue', ...extraReplacements.map(v => v.key)].join('|'); @@ -256,7 +256,7 @@ export class JupyterVariables implements IJupyterVariables { result.pageStartIndex = startPos; // Do one at a time. All at once doesn't work as they all have to wait for each other anyway - for (let i = startPos; i < startPos + chunkSize && i < list.variables.length; ) { + for (let i = startPos; i < startPos + chunkSize && i < list.variables.length;) { const fullVariable = list.variables[i].value ? list.variables[i] : await this.getVariableValueFromKernel(list.variables[i], notebook); // See if this is excluded or not. From 0157ac9ab77b42871efc69ae69934142096e6769 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Tue, 4 Feb 2020 10:59:18 -0800 Subject: [PATCH 2/3] Fix data frame viewer --- .../data-explorer/globalJQueryImports.ts | 24 ++++++++++++++ .../data-explorer/reactSlickGrid.tsx | 32 ++++++++++++------- 2 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 src/datascience-ui/data-explorer/globalJQueryImports.ts diff --git a/src/datascience-ui/data-explorer/globalJQueryImports.ts b/src/datascience-ui/data-explorer/globalJQueryImports.ts new file mode 100644 index 000000000000..d3bfae0a054b --- /dev/null +++ b/src/datascience-ui/data-explorer/globalJQueryImports.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +'use strict'; + +/* +This file exists for the sole purpose of ensuring jQuery and slickgrid load in the right sequence. +We need to first load jquery into window.jQuery. +After that we need to load slickgrid, and then the jQuery plugin from slickgrid event.drag. +*/ + +// Slickgrid requires jquery to be defined. Globally. So we do some hacks here. +// We need to manipulate the grid with the same jquery that it uses +// use slickgridJQ instead of the usual $ to make it clear that we need that JQ and not +// the one currently in node-modules + +// tslint:disable-next-line: no-var-requires no-require-imports +require('expose-loader?jQuery!slickgrid/lib/jquery-1.11.2.min'); + +// tslint:disable-next-line: no-var-requires no-require-imports +require('slickgrid/lib/jquery-1.11.2.min'); + +// tslint:disable-next-line: no-var-requires no-require-imports +require('expose-loader?jQuery.fn.drag!slickgrid/lib/jquery.event.drag-2.3.0'); diff --git a/src/datascience-ui/data-explorer/reactSlickGrid.tsx b/src/datascience-ui/data-explorer/reactSlickGrid.tsx index 9f839a1d0f96..dfd893a94247 100644 --- a/src/datascience-ui/data-explorer/reactSlickGrid.tsx +++ b/src/datascience-ui/data-explorer/reactSlickGrid.tsx @@ -7,29 +7,39 @@ import * as ReactDOM from 'react-dom'; import { MaxStringCompare } from '../../client/datascience/data-viewing/types'; import { KeyCodes } from '../react-common/constants'; import { measureText } from '../react-common/textMeasure'; +import './globalJQueryImports'; import { ReactSlickGridFilterBox } from './reactSlickGridFilterBox'; -// Slickgrid requires jquery to be defined. Globally. So we do some hacks here. -// We need to manipulate the grid with the same jquery that it uses -// use slickgridJQ instead of the usual $ to make it clear that we need that JQ and not -// the one currently in node-modules -// tslint:disable-next-line: no-var-requires no-require-imports -require('expose-loader?jQuery!slickgrid/lib/jquery-1.11.2.min'); +/* +WARNING: Do not change the order of these imports. +Slick grid MUST be imported after we load jQuery and other stuff from `./globalJQueryImports` +*/ // tslint:disable-next-line: no-var-requires no-require-imports const slickgridJQ = require('slickgrid/lib/jquery-1.11.2.min'); -// tslint:disable-next-line: no-var-requires no-require-imports -require('expose-loader?jQuery.fn.drag!slickgrid/lib/jquery.event.drag-2.3.0'); +// Adding comments to ensure order of imports does not change due to auto formatters. +// tslint:disable-next-line: ordered-imports import 'slickgrid/slick.core'; +// Adding comments to ensure order of imports does not change due to auto formatters. +// tslint:disable-next-line: ordered-imports import 'slickgrid/slick.dataview'; +// Adding comments to ensure order of imports does not change due to auto formatters. +// tslint:disable-next-line: ordered-imports import 'slickgrid/slick.grid'; - +// Adding comments to ensure order of imports does not change due to auto formatters. +// tslint:disable-next-line: ordered-imports import 'slickgrid/plugins/slick.autotooltips'; - +// Adding comments to ensure order of imports does not change due to auto formatters. +// tslint:disable-next-line: ordered-imports import 'slickgrid/slick.grid.css'; - // Make sure our css comes after the slick grid css. We override some of its styles. +// tslint:disable-next-line: ordered-imports import './reactSlickGrid.css'; +/* +WARNING: Do not change the order of these imports. +Slick grid MUST be imported after we load jQuery and other stuff from `./globalJQueryImports` +*/ + const MinColumnWidth = 70; const MaxColumnWidth = 500; From b19761ad9d307b7cb62414ef00255480f06e1121 Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Tue, 4 Feb 2020 12:14:36 -0800 Subject: [PATCH 3/3] Fix linter problems --- src/client/datascience/jupyter/jupyterVariables.ts | 4 ++-- src/datascience-ui/data-explorer/reactSlickGrid.tsx | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/client/datascience/jupyter/jupyterVariables.ts b/src/client/datascience/jupyter/jupyterVariables.ts index b0cf7194c4a2..cff731c78e20 100644 --- a/src/client/datascience/jupyter/jupyterVariables.ts +++ b/src/client/datascience/jupyter/jupyterVariables.ts @@ -45,7 +45,7 @@ export class JupyterVariables implements IJupyterVariables { private languageToQueryMap = new Map(); private notebookState = new Map(); - constructor(@inject(IFileSystem) private fileSystem: IFileSystem, @inject(IConfigurationService) private configService: IConfigurationService) { } + constructor(@inject(IFileSystem) private fileSystem: IFileSystem, @inject(IConfigurationService) private configService: IConfigurationService) {} // IJupyterVariables implementation public async getVariables(notebook: INotebook, request: IJupyterVariablesRequest): Promise { @@ -256,7 +256,7 @@ export class JupyterVariables implements IJupyterVariables { result.pageStartIndex = startPos; // Do one at a time. All at once doesn't work as they all have to wait for each other anyway - for (let i = startPos; i < startPos + chunkSize && i < list.variables.length;) { + for (let i = startPos; i < startPos + chunkSize && i < list.variables.length; ) { const fullVariable = list.variables[i].value ? list.variables[i] : await this.getVariableValueFromKernel(list.variables[i], notebook); // See if this is excluded or not. diff --git a/src/datascience-ui/data-explorer/reactSlickGrid.tsx b/src/datascience-ui/data-explorer/reactSlickGrid.tsx index dfd893a94247..15f3d3a84cd6 100644 --- a/src/datascience-ui/data-explorer/reactSlickGrid.tsx +++ b/src/datascience-ui/data-explorer/reactSlickGrid.tsx @@ -40,7 +40,6 @@ WARNING: Do not change the order of these imports. Slick grid MUST be imported after we load jQuery and other stuff from `./globalJQueryImports` */ - const MinColumnWidth = 70; const MaxColumnWidth = 500;