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

No provider for: @jupyter-lsp/jupyterlab-lsp:ILSPAdapterManager #977

Closed
skbitsp opened this issue Sep 7, 2023 · 16 comments
Closed

No provider for: @jupyter-lsp/jupyterlab-lsp:ILSPAdapterManager #977

skbitsp opened this issue Sep 7, 2023 · 16 comments

Comments

@skbitsp
Copy link

skbitsp commented Sep 7, 2023

Hi, facing a weird issue with importing an instance of ILSPAdapterManager in our extension. I have tried with LSP versions 4.2.0 and 3.10.2, both.

Steps:

  1. importing: import {ILSPAdapterManager} from '@jupyter-lsp/jupyterlab-lsp';
  2. Putting it in requires and then in activate function of the extension and then using it:
const extensions = [{
  id: '<redacted>',
  requires: [ILSPAdapterManager],
  activate: async (app, adapterManager) => {
      adapterManager.registerAdapterType(...)
  }

It fails saying: index.es6.js:2289 Error: No provider for: @jupyter-lsp/jupyterlab-lsp:ILSPAdapterManager., similarly in the setup for 3.x version of LSP, it fails with: No provider for: @krassowski/jupyterlab-lsp:ILSPAdapterManager.

On putting a breakpoint there, I can see that a corresponding entry is present for these Tokens:

Screenshot 2023-09-07 at 7 47 47 PM

I am assuming the token its asking for and the token present are different "instances" even though the "name" of the tokens is the same. Any ideas?

....

One more thing is, I was able to get it working in a specific setup (by chance) with pip install jupyterlab-lsp==3.10.2 and having a dependency of lsp extension 4.2.0 in my project. Basically jupyterlab extension version was 4.2.0, but the python version was 3.10.2. In this specific combination using import {ILSPAdapterManager} from '@jupyter-lsp/jupyterlab-lsp, the extension comes up! But that leads to double instances of the extension, hence this is not a clean solution.

@krassowski
Copy link
Member

For the JS version you may want to try something like:

{
"sharedPackages": { 
   "@jupyter-lsp/jupyterlab-lsp": { 
     "bundled": false, 
     "singleton": true, 
     "strictVersion": true
   } 
 }
}

in your package.json. See: https://jupyterlab.readthedocs.io/en/stable/extension/extension_dev.html#deduplication-of-dependencies

@krassowski
Copy link
Member

In production strictVersion may be an overkill, but it's good for sanity during development and testing.

@krassowski
Copy link
Member

Another thing to try if the above does not help: can you require ILSPExtension token? If so, this could be a bug in other tokens having mismatching IDs vs plugins that provide them.

@skbitsp
Copy link
Author

skbitsp commented Sep 8, 2023

I added that shared packages, didn't help. Also, the other tokens like ILSPExtension, etc. are also not found.
As a hack, tried setting the instance to a global variable in adapter_manager.ts inside activate function:

      let wam = new WidgetAdapterManager(shell);
      console.log("Inside LSP. Setting the adatper manager");
      console.log(wam)
      window.lspAdapterManager = wam;
      return wam;

Then in my extension reading it using window.lspAdapterManager. Both the instances are same..
Screenshot 2023-09-08 at 3 30 43 PM

The registeration (adapterManager.registerAdapterType) also goes through but the extension doesn't come up! :(

@skbitsp
Copy link
Author

skbitsp commented Sep 11, 2023

The way I am installing is the extension from local is:

  1. Inside both the python packages jupyter_lsp and jupyterlab_lsp, i am doing pip install .
  2. Under packages/jupyterlab-lsp, I have done a yarn link and linked it to my swb extension.

---Ideally the above steps should have installed the extension, but the changes were not coming in the application's node_modules, so the 3rd step---

  1. Did jupyter labextension install .

Do you think these steps might lead to any duplication of the extension installed and the token which is in my extension vs which is getting registered are different? 🤔

Basically, I think the issue might be that we are installing the extension and also, having it as a dependency to use the token it provides.

@skbitsp
Copy link
Author

skbitsp commented Sep 11, 2023

Put debugger points and was able to understand that the issue is that it sets the language server here (the Private.setLanguageServerManager in connection_manager.ts):

(notice the file location)

Screenshot 2023-09-11 at 2 57 03 PM

Whereas the Private.getLanguageServerManager() is called here (inside my extension's node_modules):
Screenshot 2023-09-11 at 2 58 23 PM

Because of the mismatch of these file locations, its not able to get the language server manager when its invoked. How to install the extension and also use it as a dependency in my local extension without this separation of concerns 🤔

@krassowski
Copy link
Member

krassowski commented Sep 11, 2023

As you correctly notice your extension ships a copy of jupyterlab-lsp but it should not. As previously mentioned, configuring sharedPackages within jupyterlab stanza of package.json should ensure that webpack resolves it correctly. I know that you already tried that, but seeing my comment now it may have not been obvious that it needs to go within the jupyterlab stanza. Can you give it another go?

@krassowski
Copy link
Member

As for the installation, I do not see why you would use yarn link, unless you are forking this extension. Normally it would be just adding it to the dependencies. On jupyter labextension install - are you using it to install your own extension, or jupyterlab-lsp? I would say it should never be used except for deployment of source extensions. For development of your own extension jupyter labextension develop is appropriate. For dependencies, these should not be explicitly installed but handled by the package manager of choice (jlpm/yarn/npm) and configured in package.json for webpack to de-duplicate. If you had indeed forked jupyterlab-lsp locally for some reason, installing a second copy via pip would indeed lead to two different copies.

This is about as much as I can help without more detailed info or reproducer.

@skbitsp
Copy link
Author

skbitsp commented Sep 11, 2023

If you had indeed forked jupyterlab-lsp locally for some reason, installing a second copy via pip would indeed lead to two different copies.

-- Sorry I forgot to mention before, yes, I am forking the extension - reason being that I have to export these tokens (from index.ts) which I am using in my extension:

export {FileEditorAdapter} from './adapters/file_editor/file_editor';
export {FileEditorContextMenuEntryPoint} from './adapters/file_editor';
export {PositionConverter} from './converter';
export {VirtualDocument} from './virtual/document';
export {EditorAdapter} from './editor_integration/editor_adapter';
export {LSPConnection} from './connection';
export {WidgetAdapterManager} from './adapter_manager';

You are right the multiple installations is causing the issue. Do you have any idea to get a local setup working with both these extensions on my local and my swb extension depending on the local version of LSP? If not yarn link then how to link this local version of LSP to my extension and also install it as a JL extension on my local?

@krassowski
Copy link
Member

You should not need to do that. While they are not exported from index.ts, these are themselves all exported symbols, so you should be able to access them from lib:

import {WidgetAdapterManager} from '@jupyter-lsp/jupyterlab-lsp/lib/adapter_manager';

This is of course not ideal, which is why it was reworked for JupyterLab 4/jupyterlab-lsp 5.0.

Does this help?

@skbitsp
Copy link
Author

skbitsp commented Sep 11, 2023

I tried that only initially, but it was leading to same issue of file duplication. The two locations:

webpack://jupyterlab/application-top/node_modules/@jupyter-lsp/jupyterlab-lsp/lib/connection_manager.js
webpack://jupyterlab/application-top/darwin-tabular-analysis/node_modules/@jupyter-lsp/jupyterlab-lsp/src/connection_manager.ts

The Private.setLanguageServerManager() was getting called in connection-manager.js and the getter is called in connection-manager.ts.

Putting the exports solved this issue. But the issue was solved for a specific environment of python version 3.10 and other version 4.2.0 (which I cloned in my local and made these export changes on top of and linked to my swb extension).

If I use just one of the versions, then I am unable to bypass the issue of No provider for: @jupyter-lsp/jupyterlab-lsp:ILSPAdapterManager, which brings us to the starting of this issue thread 😄.

P.S. can we export these in the Open source version of 4.x? I can raise the PR and you can help releasing a corresponding version, then I won't have to make a local copy and export these statements.

@krassowski
Copy link
Member

Feel welcome to open a PR.

Regarding ILSPAdapterManager/de-duplication:

  • ensure sharedPackages setting gets picked up from your package.json; you can test it by putting a dependency on fake version of @jupyter-lsp/jupyterlab-lsp in dependencies, say ^100.0 and enabling strictVersion.

@skbitsp
Copy link
Author

skbitsp commented Sep 13, 2023

Great! I was able to resolve the issue :) Basically I was doing an additional pip install of jupyterlab-lsp. But still had to export the classes.

Raised this PR: #980. Would require your help in merging it and releasing a version we can use.

Also, can we change the configuration settings (like Automatic hover) while deploying?

Thanks.

@skbitsp skbitsp closed this as completed Sep 13, 2023
@skbitsp
Copy link
Author

skbitsp commented Sep 14, 2023

Hi, I guess the PR got missed. Would need your help in getting this merged :) - #980

@skbitsp skbitsp reopened this Sep 14, 2023
@krassowski
Copy link
Member

Checking back, did #980 fix the issue for you @skbitsp?

@krassowski
Copy link
Member

Closing as resolved, feel welcome to open any follow-up issues.

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

2 participants