From 1c7d44472320da41676cd62eb066465e81481aee Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Tue, 4 Feb 2020 12:39:48 -0800 Subject: [PATCH] Fix variables on mac and linux (#9897) * Fix regexes to work on other platforms * Fix data frame viewer * Fix linter problems Co-authored-by: Don Jayamanne --- .../datascience/jupyter/jupyterVariables.ts | 12 +++---- .../data-explorer/globalJQueryImports.ts | 24 ++++++++++++++ .../data-explorer/reactSlickGrid.tsx | 31 ++++++++++++------- 3 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 src/datascience-ui/data-explorer/globalJQueryImports.ts diff --git a/src/client/datascience/jupyter/jupyterVariables.ts b/src/client/datascience/jupyter/jupyterVariables.ts index 5f199e175f7d..cff731c78e20 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']); @@ -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('|'); 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..15f3d3a84cd6 100644 --- a/src/datascience-ui/data-explorer/reactSlickGrid.tsx +++ b/src/datascience-ui/data-explorer/reactSlickGrid.tsx @@ -7,29 +7,38 @@ 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;