jupyterlab-lsp
jupyterlab-lsp copied to clipboard
Trying to create a jupyterlab extension which uses jupyterlab-lsp
Description
I followed the jupterlab extension tutorial https://jupyterlab.readthedocs.io/en/stable/extension/extension_tutorial.html
I was able to create an extension, build it and see it in action in jupyterlab. So I know my project is setup correctly.
I then proceeded to add a requirement on ILSPCodeExtractorsManager because I want to add a new transclusion.
const plugin: JupyterFrontEndPlugin<void> = {
id: 'jupyterlab_jc:plugin',
autoStart: true,
optional: [ISettingRegistry],
requires: [ICommandPalette, ILSPCodeExtractorsManager],
activate: (app: JupyterFrontEnd, extractors_manager: ILSPCodeExtractorsManager, palette: ICommandPalette, settingRegistry: ISettingRegistry | null) => {
const extractor = new RegExpForeignCodeExtractor({
language: 'sql',
pattern: `(--start-sql-syntax)( .*?)?\n([^]*?)(--end-sql-syntax)`,
foreign_capture_groups: [1],
is_standalone: true,
file_extension: 'sql'
});
extractors_manager.register(extractor, 'python');
I then added the following packages to my project.
jlpm add @krassowski/jupyterlab-lsp
jlpm add lsp-ws-connection
jlpm add @jupyterlab/logconsole
jlpm add @jupyterlab/docmanager
Then proceeded to build it and got these errors
jlpm run build
node_modules/@krassowski/jupyterlab-lsp/lib/tokens.d.ts:7:62 - error TS2307: Cannot find module './_plugin' or its corresponding type declarations.
7 import { LanguageServer2 as LSPLanguageServerSettings } from './_plugin';
Strange why the _plugin and _schema files are only in the src directory but not the lib directory. I worked around that issue by copying the missing files into the lib directory
cp node_modules/@krassowski/jupyterlab-lsp/src/_* node_modules/@krassowski/jupyterlab-lsp/lib
But still I'm getting these errors
jlpm run build
$ tsc
node_modules/@krassowski/jupyterlab-lsp/lib/positioning.d.ts:2:34 - error TS7016: Could not find a declaration file for module 'codemirror'. '/Users/jccote/jupyter-ext/jupyterlab_jc/node_modules/codemirror/lib/codemirror.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/codemirror` if it exists or add a new declaration (.d.ts) file containing `declare module 'codemirror';`
2 import type * as CodeMirror from 'codemirror';
node_modules/@krassowski/jupyterlab-lsp/lib/virtual/document.d.ts:3:31 - error TS2307: Cannot find module 'lsp-ws-connection/src' or its corresponding type declarations.
3 import { IDocumentInfo } from 'lsp-ws-connection/src';
Is something wrong with the way jupyterlab-lsp is packaged that prevents me from using it to build a jupyter lab extension? Or I'm missing something? I'm new to jupyterlab extension building so it's totally plausible.
Indeed we could package the schema bits. Thank you for reporting. As for code mirror you could install the types to workaround the issue for now:
jlpm add --dev @types/codemirror
Thanks @krassowski , adding the codemirror dependency got rid of my error. There is still a small snag in the package.
node_modules/@krassowski/jupyterlab-lsp/lib/virtual/document.d.ts:3:31 - error TS2307: Cannot find module 'lsp-ws-connection/src' or its corresponding type declarations.
3 import { IDocumentInfo } from 'lsp-ws-connection/src';
To fix this I modified the document.d.ts file, removing the /src
import { IDocumentInfo } from 'lsp-ws-connection';
I can now build the extension. When I run it I get this error. I made sure jupyterlab-lsp is installed properly and is running fine.
jlab_core.e9e49407afea635b7583.js?v=e9e49407afea635b7583:2 Error: No provider for: @krassowski/jupyterlab-lsp:ILSPCodeExtractorsManager.
at W.e.resolveRequiredService (jlab_core.e9e49407afea635b7583.js?v=e9e49407afea635b7583:2)
at jlab_core.e9e49407afea635b7583.js?v=e9e49407afea635b7583:2
at Array.map (<anonymous>)
at W.e.activatePlugin (jlab_core.e9e49407afea635b7583.js?v=e9e49407afea635b7583:2)
at jlab_core.e9e49407afea635b7583.js?v=e9e49407afea635b7583:2
at Array.map (<anonymous>)
at W.e.start (jlab_core.e9e49407afea635b7583.js?v=e9e49407afea635b7583:2)
at q (1641.7a3009ffbb5939cb2c8c.js?v=7a3009ffbb5939cb2c8c:1)
Not sure why the provider would not be found. Maybe it's not being registered by jupyterlab-lsp?
I figured out the issue. I had to declare that I want to use the tokens from jupyterlab-lsp and not get a copy of them. That's what I gather anyways. I added this to my package.json and not it works.
"jupyterlab": {
...
"sharedPackages": {
"@krassowski/jupyterlab-lsp": {
"bundled": false,
"singleton": true
}
}
},
Got the information from this paragraph https://jupyterlab.readthedocs.io/en/stable/extension/extension_dev.html#requiring-a-service
I'd have thought it would already be hoisted as a singleton, as jupyterlab-lsp is itself an extension, but if you're encountering issues, we should add that to our example package:
https://github.com/krassowski/jupyterlab-lsp/blob/master/packages/_example-extractor/package.json#L26