Skip to content

Commit ffdd497

Browse files
authored
Merge pull request #562 from bollwyvl/gh-561-quick-fix
Propose Extractor API (#561, Plan A)
2 parents 57612da + 5cf872d commit ffdd497

File tree

24 files changed

+236
-26
lines changed

24 files changed

+236
-26
lines changed

.github/workflows/job.test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ env:
2525
JLPM_CMD: jlpm --ignore-optional --prefer-offline --frozen-lockfile
2626

2727
# Increase this value to reset all caches
28-
CACHE_EPOCH: 1
28+
CACHE_EPOCH: 2
2929
JULIA_LANGSERVER: 3.2.0
3030

3131
jobs:

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212
- fixes IPython `pinfo` and `pinfo2` (`?` and `??`) for identifiers containing `s` ([#547])
1313
- fixes incorrect behaviour of LSP features in some IPython magics with single line of content ([#560])
1414

15+
- for extension authors:
16+
17+
- minimal functional extractor and code overrides APIs are now exported; these APIs cab be subject to change in future releases ([#562])
18+
1519
[#544]: https://github.com/krassowski/jupyterlab-lsp/pull/544
1620
[#547]: https://github.com/krassowski/jupyterlab-lsp/pull/547
1721
[#553]: https://github.com/krassowski/jupyterlab-lsp/pull/553
1822
[#560]: https://github.com/krassowski/jupyterlab-lsp/pull/560
23+
[#562]: https://github.com/krassowski/jupyterlab-lsp/pull/562
1924

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

packages/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = {
66
node: true,
77
'jest/globals': true
88
},
9+
globals: { JSX: 'readonly' },
910
root: true,
1011
extends: [
1112
'eslint:recommended',

packages/_example-extractor/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Extractor API
2+
3+
This is an example of the Extractor API. See the [discussion].
4+
5+
[discussion]: https://github.com/krassowski/jupyterlab-lsp/issues/561
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@jupyterlab/testutils/lib/babel.config');
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const func = require('@jupyterlab/testutils/lib/jest-config');
2+
const upstream = func('jupyterlab-lsp', __dirname);
3+
4+
const reuseFromUpstream = [
5+
'moduleFileExtensions',
6+
'moduleNameMapper',
7+
'setupFiles',
8+
'setupFilesAfterEnv',
9+
'testPathIgnorePatterns'
10+
];
11+
12+
let local = {
13+
globals: { 'ts-jest': { tsconfig: 'tsconfig.json' } },
14+
testRegex: `.*\.spec\.tsx?$`,
15+
transform: {
16+
'\\.(ts|tsx)?$': 'ts-jest',
17+
'\\.(js|jsx)?$': './transform.js',
18+
'\\.svg$': 'jest-raw-loader'
19+
},
20+
transformIgnorePatterns: [
21+
'/node_modules/(?!(@jupyterlab/.*|@jupyterlab-classic/.*)/)'
22+
],
23+
testLocationInResults: true,
24+
reporters: [...upstream['reporters'], 'jest-github-actions-reporter']
25+
};
26+
27+
for (const option of reuseFromUpstream) {
28+
local[option] = upstream[option];
29+
}
30+
31+
module.exports = local;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "@krassowski/jupyterlab-lsp-example-extractor",
3+
"description": "Example extractor package from @krassowski/jupyterlab-lsp",
4+
"version": "0.0.0",
5+
"private": true,
6+
"main": "lib/index.js",
7+
"types": "lib/index.d.ts",
8+
"author": "JupyterLab-LSP Development Team",
9+
"files": [
10+
"lib/**/*.{js,ts}"
11+
],
12+
"dependencies": {
13+
"@krassowski/jupyterlab-lsp": "^3.4"
14+
},
15+
"devDependencies": {
16+
"@babel/preset-env": "^7.4.3",
17+
"@types/chai": "^4.1.7",
18+
"@types/jest": "^23.3.11",
19+
"@jupyterlab/application": "^3.0.0",
20+
"typescript": "~4.1.3",
21+
"jest": "^26.0.0",
22+
"ts-jest": "^26.4.3",
23+
"chai": "^4.2.0"
24+
},
25+
"jupyterlab": {
26+
"extension": true
27+
},
28+
"scripts": {
29+
"build": "tsc -b",
30+
"test": "jest",
31+
"clean:lib": "rimraf lib"
32+
}
33+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { expect } from 'chai';
2+
3+
import { extractor } from '.';
4+
5+
import { IExtractedCode } from '@krassowski/jupyterlab-lsp';
6+
7+
const EXAMPLE = `%%foo
8+
bar
9+
`;
10+
11+
let FIXTURES: { [key: string]: IExtractedCode } = {
12+
'does extract foo': {
13+
foreign_code: 'bar\n',
14+
host_code: EXAMPLE,
15+
range: { end: { column: 0, line: 2 }, start: { column: 0, line: 1 } },
16+
virtual_shift: null
17+
},
18+
'does NOT extract bar': {
19+
foreign_code: null,
20+
host_code: 'baz',
21+
range: null,
22+
virtual_shift: null
23+
},
24+
'does NOT extract foobar': {
25+
foreign_code: null,
26+
host_code: EXAMPLE.replace('foo', 'foobar'),
27+
range: null,
28+
virtual_shift: null
29+
}
30+
};
31+
32+
FIXTURES['does extract foo -v bar'] = {
33+
...FIXTURES['does extract foo'],
34+
host_code: EXAMPLE.replace('foo', 'foo -v')
35+
};
36+
37+
describe('The foo extractor', () => {
38+
test.each(Object.entries(FIXTURES))(
39+
'%s',
40+
(_: string, expected: IExtractedCode) => {
41+
const extracted = extractor.extract_foreign_code(expected.host_code);
42+
expect(extracted).to.have.length(1);
43+
expect(extracted[0]).to.deep.equal(expected);
44+
}
45+
);
46+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {
2+
JupyterFrontEnd,
3+
JupyterFrontEndPlugin
4+
} from '@jupyterlab/application';
5+
6+
import {
7+
ILSPCodeExtractorsManager,
8+
RegExpForeignCodeExtractor
9+
} from '@krassowski/jupyterlab-lsp';
10+
11+
const NS = '@krassowski/jupyterlab-lsp-example-extractor';
12+
13+
export const extractor = new RegExpForeignCodeExtractor({
14+
language: 'foo',
15+
pattern: '^%%(foo)( .*?)?\n([^]*)',
16+
foreign_capture_groups: [3],
17+
is_standalone: true,
18+
file_extension: 'foo'
19+
});
20+
21+
const plugin: JupyterFrontEndPlugin<void> = {
22+
id: `${NS}:PLUGIN`,
23+
requires: [ILSPCodeExtractorsManager],
24+
activate: (_app: JupyterFrontEnd, extractors: ILSPCodeExtractorsManager) => {
25+
extractors.register(extractor, 'python');
26+
}
27+
};
28+
29+
export default plugin;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const config = require('./babel.config.js');
2+
module.exports = require('babel-jest').createTransformer(config);

0 commit comments

Comments
 (0)