Skip to content

Commit 15d40c4

Browse files
Fix variables on mac and linux (#9897) (#9903)
* Fix regexes to work on other platforms * Fix data frame viewer * Fix linter problems Co-authored-by: Don Jayamanne <[email protected]> Co-authored-by: Don Jayamanne <[email protected]>
1 parent f7ad067 commit 15d40c4

File tree

3 files changed

+50
-17
lines changed

3 files changed

+50
-17
lines changed

src/client/datascience/jupyter/jupyterVariables.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import { JupyterDataRateLimitError } from './jupyterDataRateLimitError';
2323

2424
// Regexes for parsing data from Python kernel. Not sure yet if other
2525
// kernels will add the ansi encoding.
26-
const TypeRegex = /\u001b\[1;31mType:\u001b\[0m\s+(\w+)/;
27-
const ValueRegex = /\u001b\[1;31mValue:\u001b\[0m\s+(.*)/;
28-
const StringFormRegex = /\u001b\[1;31mString form:\u001b\[0m\s+([\s\S]+?)\n\u001b\[1/;
29-
const DocStringRegex = /\u001b\[1;31mDocstring:\u001b\[0m\s+(.*)/;
30-
const CountRegex = /\u001b\[1;31mLength:\u001b\[0m\s+(.*)/;
26+
const TypeRegex = /.*?\[.*?;31mType:.*?\[0m\s+(\w+)/;
27+
const ValueRegex = /.*?\[.*?;31mValue:.*?\[0m\s+(.*)/;
28+
const StringFormRegex = /.*?\[.*?;31mString form:.*?\[0m\s+([\s\S]+?)\n.*?\[.*?/;
29+
const DocStringRegex = /.*?\[.*?;31mDocstring:.*?\[0m\s+(.*)/;
30+
const CountRegex = /.*?\[.*?;31mLength:.*?\[0m\s+(.*)/;
3131
const ShapeRegex = /^\s+\[(\d+) rows x (\d+) columns\]/m;
3232

3333
const DataViewableTypes: Set<string> = new Set<string>(['DataFrame', 'list', 'dict', 'np.array', 'Series']);
@@ -99,7 +99,7 @@ export class JupyterVariables implements IJupyterVariables {
9999
}
100100

101101
// Prep our targetVariable to send over
102-
const variableString = JSON.stringify(targetVariable).replace('\\n', '\\\\n');
102+
const variableString = JSON.stringify(targetVariable).replace(/\\n/g, '\\\\n');
103103

104104
// Setup a regex
105105
const regexPattern = extraReplacements.length === 0 ? '_VSCode_JupyterTestValue' : ['_VSCode_JupyterTestValue', ...extraReplacements.map(v => v.key)].join('|');
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
/*
7+
This file exists for the sole purpose of ensuring jQuery and slickgrid load in the right sequence.
8+
We need to first load jquery into window.jQuery.
9+
After that we need to load slickgrid, and then the jQuery plugin from slickgrid event.drag.
10+
*/
11+
12+
// Slickgrid requires jquery to be defined. Globally. So we do some hacks here.
13+
// We need to manipulate the grid with the same jquery that it uses
14+
// use slickgridJQ instead of the usual $ to make it clear that we need that JQ and not
15+
// the one currently in node-modules
16+
17+
// tslint:disable-next-line: no-var-requires no-require-imports
18+
require('expose-loader?jQuery!slickgrid/lib/jquery-1.11.2.min');
19+
20+
// tslint:disable-next-line: no-var-requires no-require-imports
21+
require('slickgrid/lib/jquery-1.11.2.min');
22+
23+
// tslint:disable-next-line: no-var-requires no-require-imports
24+
require('expose-loader?jQuery.fn.drag!slickgrid/lib/jquery.event.drag-2.3.0');

src/datascience-ui/data-explorer/reactSlickGrid.tsx

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,38 @@ import * as ReactDOM from 'react-dom';
77
import { MaxStringCompare } from '../../client/datascience/data-viewing/types';
88
import { KeyCodes } from '../react-common/constants';
99
import { measureText } from '../react-common/textMeasure';
10+
import './globalJQueryImports';
1011
import { ReactSlickGridFilterBox } from './reactSlickGridFilterBox';
1112

12-
// Slickgrid requires jquery to be defined. Globally. So we do some hacks here.
13-
// We need to manipulate the grid with the same jquery that it uses
14-
// use slickgridJQ instead of the usual $ to make it clear that we need that JQ and not
15-
// the one currently in node-modules
16-
// tslint:disable-next-line: no-var-requires no-require-imports
17-
require('expose-loader?jQuery!slickgrid/lib/jquery-1.11.2.min');
13+
/*
14+
WARNING: Do not change the order of these imports.
15+
Slick grid MUST be imported after we load jQuery and other stuff from `./globalJQueryImports`
16+
*/
1817
// tslint:disable-next-line: no-var-requires no-require-imports
1918
const slickgridJQ = require('slickgrid/lib/jquery-1.11.2.min');
20-
// tslint:disable-next-line: no-var-requires no-require-imports
21-
require('expose-loader?jQuery.fn.drag!slickgrid/lib/jquery.event.drag-2.3.0');
2219

20+
// Adding comments to ensure order of imports does not change due to auto formatters.
21+
// tslint:disable-next-line: ordered-imports
2322
import 'slickgrid/slick.core';
23+
// Adding comments to ensure order of imports does not change due to auto formatters.
24+
// tslint:disable-next-line: ordered-imports
2425
import 'slickgrid/slick.dataview';
26+
// Adding comments to ensure order of imports does not change due to auto formatters.
27+
// tslint:disable-next-line: ordered-imports
2528
import 'slickgrid/slick.grid';
26-
29+
// Adding comments to ensure order of imports does not change due to auto formatters.
30+
// tslint:disable-next-line: ordered-imports
2731
import 'slickgrid/plugins/slick.autotooltips';
28-
32+
// Adding comments to ensure order of imports does not change due to auto formatters.
33+
// tslint:disable-next-line: ordered-imports
2934
import 'slickgrid/slick.grid.css';
30-
3135
// Make sure our css comes after the slick grid css. We override some of its styles.
36+
// tslint:disable-next-line: ordered-imports
3237
import './reactSlickGrid.css';
38+
/*
39+
WARNING: Do not change the order of these imports.
40+
Slick grid MUST be imported after we load jQuery and other stuff from `./globalJQueryImports`
41+
*/
3342

3443
const MinColumnWidth = 70;
3544
const MaxColumnWidth = 500;

0 commit comments

Comments
 (0)