Skip to content

Commit

Permalink
Merge pull request #562 from bollwyvl/gh-561-quick-fix
Browse files Browse the repository at this point in the history
Propose Extractor API (#561, Plan A)
  • Loading branch information
krassowski authored Mar 21, 2021
2 parents 57612da + 5cf872d commit ffdd497
Show file tree
Hide file tree
Showing 24 changed files with 236 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/job.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ env:
JLPM_CMD: jlpm --ignore-optional --prefer-offline --frozen-lockfile

# Increase this value to reset all caches
CACHE_EPOCH: 1
CACHE_EPOCH: 2
JULIA_LANGSERVER: 3.2.0

jobs:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@
- fixes IPython `pinfo` and `pinfo2` (`?` and `??`) for identifiers containing `s` ([#547])
- fixes incorrect behaviour of LSP features in some IPython magics with single line of content ([#560])

- for extension authors:

- minimal functional extractor and code overrides APIs are now exported; these APIs cab be subject to change in future releases ([#562])

[#544]: https://github.com/krassowski/jupyterlab-lsp/pull/544
[#547]: https://github.com/krassowski/jupyterlab-lsp/pull/547
[#553]: https://github.com/krassowski/jupyterlab-lsp/pull/553
[#560]: https://github.com/krassowski/jupyterlab-lsp/pull/560
[#562]: https://github.com/krassowski/jupyterlab-lsp/pull/562

### `jupyter-lsp 1.1.4` (2020-02-21)

Expand Down
1 change: 1 addition & 0 deletions packages/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
node: true,
'jest/globals': true
},
globals: { JSX: 'readonly' },
root: true,
extends: [
'eslint:recommended',
Expand Down
5 changes: 5 additions & 0 deletions packages/_example-extractor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Extractor API

This is an example of the Extractor API. See the [discussion].

[discussion]: https://github.com/krassowski/jupyterlab-lsp/issues/561
1 change: 1 addition & 0 deletions packages/_example-extractor/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@jupyterlab/testutils/lib/babel.config');
31 changes: 31 additions & 0 deletions packages/_example-extractor/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const func = require('@jupyterlab/testutils/lib/jest-config');
const upstream = func('jupyterlab-lsp', __dirname);

const reuseFromUpstream = [
'moduleFileExtensions',
'moduleNameMapper',
'setupFiles',
'setupFilesAfterEnv',
'testPathIgnorePatterns'
];

let local = {
globals: { 'ts-jest': { tsconfig: 'tsconfig.json' } },
testRegex: `.*\.spec\.tsx?$`,
transform: {
'\\.(ts|tsx)?$': 'ts-jest',
'\\.(js|jsx)?$': './transform.js',
'\\.svg$': 'jest-raw-loader'
},
transformIgnorePatterns: [
'/node_modules/(?!(@jupyterlab/.*|@jupyterlab-classic/.*)/)'
],
testLocationInResults: true,
reporters: [...upstream['reporters'], 'jest-github-actions-reporter']
};

for (const option of reuseFromUpstream) {
local[option] = upstream[option];
}

module.exports = local;
33 changes: 33 additions & 0 deletions packages/_example-extractor/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@krassowski/jupyterlab-lsp-example-extractor",
"description": "Example extractor package from @krassowski/jupyterlab-lsp",
"version": "0.0.0",
"private": true,
"main": "lib/index.js",
"types": "lib/index.d.ts",
"author": "JupyterLab-LSP Development Team",
"files": [
"lib/**/*.{js,ts}"
],
"dependencies": {
"@krassowski/jupyterlab-lsp": "^3.4"
},
"devDependencies": {
"@babel/preset-env": "^7.4.3",
"@types/chai": "^4.1.7",
"@types/jest": "^23.3.11",
"@jupyterlab/application": "^3.0.0",
"typescript": "~4.1.3",
"jest": "^26.0.0",
"ts-jest": "^26.4.3",
"chai": "^4.2.0"
},
"jupyterlab": {
"extension": true
},
"scripts": {
"build": "tsc -b",
"test": "jest",
"clean:lib": "rimraf lib"
}
}
46 changes: 46 additions & 0 deletions packages/_example-extractor/src/api.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { expect } from 'chai';

import { extractor } from '.';

import { IExtractedCode } from '@krassowski/jupyterlab-lsp';

const EXAMPLE = `%%foo
bar
`;

let FIXTURES: { [key: string]: IExtractedCode } = {
'does extract foo': {
foreign_code: 'bar\n',
host_code: EXAMPLE,
range: { end: { column: 0, line: 2 }, start: { column: 0, line: 1 } },
virtual_shift: null
},
'does NOT extract bar': {
foreign_code: null,
host_code: 'baz',
range: null,
virtual_shift: null
},
'does NOT extract foobar': {
foreign_code: null,
host_code: EXAMPLE.replace('foo', 'foobar'),
range: null,
virtual_shift: null
}
};

FIXTURES['does extract foo -v bar'] = {
...FIXTURES['does extract foo'],
host_code: EXAMPLE.replace('foo', 'foo -v')
};

describe('The foo extractor', () => {
test.each(Object.entries(FIXTURES))(
'%s',
(_: string, expected: IExtractedCode) => {
const extracted = extractor.extract_foreign_code(expected.host_code);
expect(extracted).to.have.length(1);
expect(extracted[0]).to.deep.equal(expected);
}
);
});
29 changes: 29 additions & 0 deletions packages/_example-extractor/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';

import {
ILSPCodeExtractorsManager,
RegExpForeignCodeExtractor
} from '@krassowski/jupyterlab-lsp';

const NS = '@krassowski/jupyterlab-lsp-example-extractor';

export const extractor = new RegExpForeignCodeExtractor({
language: 'foo',
pattern: '^%%(foo)( .*?)?\n([^]*)',
foreign_capture_groups: [3],
is_standalone: true,
file_extension: 'foo'
});

const plugin: JupyterFrontEndPlugin<void> = {
id: `${NS}:PLUGIN`,
requires: [ILSPCodeExtractorsManager],
activate: (_app: JupyterFrontEnd, extractors: ILSPCodeExtractorsManager) => {
extractors.register(extractor, 'python');
}
};

export default plugin;
2 changes: 2 additions & 0 deletions packages/_example-extractor/transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const config = require('./babel.config.js');
module.exports = require('babel-jest').createTransformer(config);
15 changes: 15 additions & 0 deletions packages/_example-extractor/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../tsconfigbase",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src",
"types": ["jest"],
"tsBuildInfoFile": "lib/.tsbuildinfo"
},
"include": ["src/**/*"],
"references": [
{
"path": "../jupyterlab-lsp"
}
]
}
14 changes: 14 additions & 0 deletions packages/jupyterlab-lsp/src/api/extractor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Extractor Public API
*
* Please note that this APIs can be subject to change and relocation to separate package in the future releases.
*
* @see https://github.com/krassowski/jupyterlab-lsp/issues/561
*/
export { LanguageIdentifier } from '../lsp';
export {
IForeignCodeExtractor,
IForeignCodeExtractorsRegistry,
IExtractedCode
} from '../extractors/types';
export { RegExpForeignCodeExtractor } from '../extractors/regexp';
5 changes: 5 additions & 0 deletions packages/jupyterlab-lsp/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** Extractor Public API */
export * from './extractor';

/** Overrides Public API */
export * from './overrides';
11 changes: 11 additions & 0 deletions packages/jupyterlab-lsp/src/api/overrides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Overrides Public API
*
* Please note that this APIs can be subject to change and relocation to separate package in the future releases.
*
* @see https://github.com/krassowski/jupyterlab-lsp/issues/561
*/
export {
ILSPCodeOverridesManager,
IScopedCodeOverride
} from '../overrides/tokens';
15 changes: 8 additions & 7 deletions packages/jupyterlab-lsp/src/components/statusbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,25 +293,26 @@ export class LSPStatus extends VDomRenderer<LSPStatus.Model> {
* Render the status item.
*/
render() {
if (!this.model) {
const { model } = this;

if (model == null) {
return null;
}

return (
<GroupItem
spacing={this.displayText ? 2 : 0}
title={this.model.long_message}
title={model.long_message}
onClick={this.handleClick}
className={'lsp-status-group'}
>
<this.model.status_icon.react
<model.status_icon.react
top={'2px'}
kind={'statusBar'}
title={'LSP Code Intelligence'}
/>
{this.displayText ? (
<TextItem source={this.model.short_message} />
) : null}
<TextItem source={this.model.feature_message} />
{this.displayText ? <TextItem source={model.short_message} /> : null}
<TextItem source={model.feature_message} />
</GroupItem>
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/jupyterlab-lsp/src/extractors/regexp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('getIndexOfCaptureGroup', () => {
it('extracts index of a captured group', () => {
// tests for https://github.com/krassowski/jupyterlab-lsp/issues/559
let result = getIndexOfCaptureGroup(
new RegExp('^%%(python|python2|python3|pypy)( .*?)?\n([^]*)'),
new RegExp('^%%(python|python2|python3|pypy)( .*?)?\\n([^]*)'),
'%%python\nh',
'h'
);
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('RegExpForeignCodeExtractor', () => {

let python_cell_extractor = new RegExpForeignCodeExtractor({
language: 'python',
pattern: '^%%(python|python2|python3|pypy)( .*?)?\n([^]*)',
pattern: '^%%(python|python2|python3|pypy)( .*?)?\\n([^]*)',
foreign_capture_groups: [3],
keep_in_host: true,
is_standalone: true,
Expand Down
3 changes: 3 additions & 0 deletions packages/jupyterlab-lsp/src/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ export interface IFeatureEditorIntegration<T extends IVirtualEditor<IEditor>> {
* position transformation errors).
*/
afterChange?(change: IEditorChange, root_position: IRootPosition): void;

/** no-unused-vars rule is hard to disable selectively */
__unused_editor_?: T;
}

export interface IFeatureEditorIntegrationConstructor<
Expand Down
10 changes: 8 additions & 2 deletions packages/jupyterlab-lsp/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/** The Public API, as exposed in the `main` field of package.json */

/** General public tokens, including lumino Tokens and namespaces */
export * from './tokens';

/** Component- and feature-specific APIs */
export * from './api';

import {
JupyterFrontEnd,
JupyterFrontEndPlugin
Expand Down Expand Up @@ -51,8 +59,6 @@ import { CODE_OVERRIDES_MANAGER } from './overrides';
import IPaths = JupyterFrontEnd.IPaths;
import { LOG_CONSOLE } from './virtual/console';

export * from './tokens';

export interface IFeatureOptions {
/**
* The feature to be registered.
Expand Down
2 changes: 1 addition & 1 deletion packages/lsp-ws-connection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"karma-webpack": "^4.0.2",
"mocha": "^6.1.4",
"puppeteer": "^1.17.0",
"rimraf": "^2.6.3",
"rimraf": "^3.0.2",
"sinon": "^7.3.2",
"source-map-loader": "~0.2.1",
"typescript": "~4.1.3",
Expand Down
7 changes: 4 additions & 3 deletions packages/metapackage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@
"build": "tsc -b",
"clean": "rimraf lib",
"prepublishOnly": "npm run build",
"watch": "tsc -b --watch"
"watch": "tsc -b --watch --preserveWatchOutput"
},
"dependencies": {
"lsp-ws-connection": "file:../lsp-ws-connection",
"@krassowski/completion-theme": "file:../completion-theme",
"@krassowski/theme-material": "file:../theme-material",
"@krassowski/theme-vscode": "file:../theme-vscode",
"@krassowski/code-jumpers": "file:../code-jumpers",
"@krassowski/jupyterlab-lsp": "file:../jupyterlab-lsp"
"@krassowski/jupyterlab-lsp": "file:../jupyterlab-lsp",
"@krassowski/jupyterlab-lsp-example-extractor": "file:../_example-extractor"
},
"devDependencies": {
"fs-extra": "^8.0.1",
"rimraf": "~2.6.2",
"rimraf": "^3.0.2",
"typedoc": "^0.14.2",
"typescript": "~4.1.3"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/metapackage/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@krassowski/code-jumpers';
import '@krassowski/jupyterlab-lsp';
import '@krassowski/completion-theme';
import '@krassowski/jupyterlab-lsp-example-extractor';
import '@krassowski/jupyterlab-lsp';
import '@krassowski/theme-material';
import '@krassowski/theme-vscode';
import 'lsp-ws-connection';
3 changes: 3 additions & 0 deletions packages/metapackage/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
},
{
"path": "../code-jumpers"
},
{
"path": "../_example-extractor"
}
]
}
3 changes: 1 addition & 2 deletions scripts/atest.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def atest(attempt, extra_args):
stem = get_stem(attempt, extra_args)

for non_critical in NON_CRITICAL:
extra_args += ["--noncritical", "AND".join(non_critical)]
extra_args += ["--skiponfailure", "AND".join(non_critical)]

if attempt != 1:
previous = OUT / f"{get_stem(attempt - 1, extra_args)}.robot.xml"
Expand All @@ -94,7 +94,6 @@ def atest(attempt, extra_args):
OUT / f"{stem}.log.html",
"--report",
OUT / f"{stem}.report.html",
"--xunitskipnoncritical",
"--xunit",
OUT / f"{stem}.xunit.xml",
"--variable",
Expand Down
Loading

0 comments on commit ffdd497

Please sign in to comment.