-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Propose Extractor API (#561, Plan A)
- Loading branch information
Showing
24 changed files
with
236 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('@jupyterlab/testutils/lib/babel.config'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,9 @@ | |
}, | ||
{ | ||
"path": "../code-jumpers" | ||
}, | ||
{ | ||
"path": "../_example-extractor" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.