From e7b982e0b14701802b036322550f131c7ed0edfe Mon Sep 17 00:00:00 2001 From: krassowski Date: Fri, 11 Sep 2020 06:23:11 +0100 Subject: [PATCH] fix too aggressive overrides of IPython's pinfo (`?`) and pinfo2 (`??`) --- CHANGELOG.md | 8 ++++++++ .../src/transclusions/ipython/overrides.spec.ts | 14 ++++++++++++++ .../src/transclusions/ipython/overrides.ts | 9 +++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4358f9923..855203d8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ ## CHANGELOG +### `@krassowski/jupyterlab-lsp 2.0.5` (2020-09-11) + +- bug fixes + + - fix too aggressive overrides of IPython's pinfo (`?`) and pinfo2 (`??`) ([#352]) + +[#352]: https://github.com/krassowski/jupyterlab-lsp/issues/352 + ### `@krassowski/jupyterlab-lsp 2.0.4` (2020-09-11) - bug fixes diff --git a/packages/jupyterlab-lsp/src/transclusions/ipython/overrides.spec.ts b/packages/jupyterlab-lsp/src/transclusions/ipython/overrides.spec.ts index 1cf444dcd..eaca1c22c 100644 --- a/packages/jupyterlab-lsp/src/transclusions/ipython/overrides.spec.ts +++ b/packages/jupyterlab-lsp/src/transclusions/ipython/overrides.spec.ts @@ -206,5 +206,19 @@ describe('Default IPython overrides', () => { reverse = line_magics_map.reverse.override_for(override); expect(reverse).to.equal('int??'); }); + + it('does not override standalone question marks', () => { + let override = line_magics_map.override_for("'q?'"); + expect(override).to.equal(null); + + override = line_magics_map.override_for('#?'); + expect(override).to.equal(null); + + override = line_magics_map.override_for("?q'"); + expect(override).to.equal(null); + + override = line_magics_map.override_for("?#'"); + expect(override).to.equal(null); + }); }); }); diff --git a/packages/jupyterlab-lsp/src/transclusions/ipython/overrides.ts b/packages/jupyterlab-lsp/src/transclusions/ipython/overrides.ts index 399553f04..1e3d9b484 100644 --- a/packages/jupyterlab-lsp/src/transclusions/ipython/overrides.ts +++ b/packages/jupyterlab-lsp/src/transclusions/ipython/overrides.ts @@ -42,6 +42,8 @@ function empty_or_escaped(x: string) { */ export const LINE_MAGIC_PREFIX = '^(\\s*|\\s*\\S+\\s*=\\s*)'; +export const PYTHON_IDENTIFIER = '([^?s\'"\\(\\)-\\+\\/#]+)'; + export let overrides: IScopedCodeOverride[] = [ /** * Line magics @@ -60,7 +62,10 @@ export let overrides: IScopedCodeOverride[] = [ }, { // note: assignments of pinfo/pinfo2 are not supported by IPython - pattern: '^(\\s*)' + '(\\?{1,2})(\\S+)(\n)?', + // and only "simple" identifiers are supported, i.e. + // ?x['a'] + // would not be solved, leading to "Object `x['a']` not found." + pattern: '^(\\s*)' + '(\\?{1,2})' + PYTHON_IDENTIFIER + '(\n)?$', replacement: (match, prefix, marks, name, line_break) => { const cmd = marks == '?' ? 'pinfo' : 'pinfo2'; line_break = line_break || ''; @@ -79,7 +84,7 @@ export let overrides: IScopedCodeOverride[] = [ } }, { - pattern: '^(\\s*)' + '([^\\?\\s]+)(\\?{1,2})(\n)?', + pattern: '^(\\s*)' + PYTHON_IDENTIFIER + '(\\?{1,2})(\n)?', replacement: (match, prefix, name, marks, line_break) => { const cmd = marks == '?' ? 'pinfo' : 'pinfo2'; line_break = line_break || '';