Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activate Jupyterlab-lsp within my extension #774

Open
fcxjlsw05 opened this issue Mar 9, 2022 · 3 comments
Open

Activate Jupyterlab-lsp within my extension #774

fcxjlsw05 opened this issue Mar 9, 2022 · 3 comments

Comments

@fcxjlsw05
Copy link

I am currently building an extension which includes components hosting code mirror editor (@jupyterlab/codemirror).
7hNUvKhonTGGbLJ
According to the doc https://github.com/jupyter-lsp/jupyterlab-lsp/blob/master/docs/Extending.ipynb, I thought jupyterlap-lsp should be supported by default. But it turns out not. If I press tab outside my extension(just open the file in document widget), jupyterlab-lsp is activated
GzSgQDzFHnD38Qg

Reading through the document, I don't find a solution how to integrate jupyterlab-lsp with my extension.

Any hint what I should do here?

@bollwyvl
Copy link
Collaborator

bollwyvl commented Mar 9, 2022 via email

@krassowski
Copy link
Member

Thanks for the interest!

If your widget implements IDocumentWidget<FileEditor> interface, and you have a tracker implementing IWidgetTracker<IDocumentWidget<FileEditor>> interface you could re-use the registration code linked below:

import { JupyterFrontEndPlugin } from '@jupyterlab/application';
import { IDocumentWidget } from '@jupyterlab/docregistry';
import { IEditorTracker } from '@jupyterlab/fileeditor';
import { CommandEntryPoint } from '../../command_manager';
import { ILSPAdapterManager, PLUGIN_ID } from '../../tokens';
import { FileEditorAdapter } from './file_editor';
export const FileEditorContextMenuEntryPoint: CommandEntryPoint =
'file-editor-context-menu';
export const FILE_EDITOR_ADAPTER: JupyterFrontEndPlugin<void> = {
id: PLUGIN_ID + ':FileEditorAdapter',
requires: [ILSPAdapterManager],
optional: [IEditorTracker],
activate(
app,
adapterManager: ILSPAdapterManager,
fileEditorTracker: IEditorTracker | null
) {
if (fileEditorTracker === null) {
console.warn(
'LSP: no fileEditorTracker - not registering file editor capabilities'
);
} else {
adapterManager.registerAdapterType({
name: 'file_editor',
tracker: fileEditorTracker,
adapter: FileEditorAdapter,
entrypoint: FileEditorContextMenuEntryPoint,
get_id(widget: IDocumentWidget): string {
return widget.id;
},
context_menu: {
selector: '.jp-FileEditor',
rank_group: 0,
rank_group_size: 4
}
});
}
},
autoStart: true
};

I think we do not export FileEditorAdapter, but we can include it in the roadmap for the 4.0 version (#742). The interface of ILSPAdapterManager will likely be subject to some changes in 4.0 too.

@fcxjlsw05
Copy link
Author

Thanks for quick response! It will be great if we could get it work soon. I will seek a work-around for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants