-
Notifications
You must be signed in to change notification settings - Fork 154
Fix/jupyterlab jump to definition fix #1160
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
base: main
Are you sure you want to change the base?
Fix/jupyterlab jump to definition fix #1160
Conversation
When LSP returns no jump targets, fall back to using Jedi in the kernel environment. This enables jump-to-definition for packages installed only in the kernel environment (not in JupyterLab's environment). Changes: - Add IntrospectionCodeHandler backend endpoint at /lsp/introspection-code - Add jumpWithKernelJedi() method with detailed logging - Add enableKernelFallback setting (default: true) - Bump version to 5.2.1
- Fix premature "No jump targets found" notification showing before kernel fallback completes - Add local development files to .gitignore (Makefile, .claude/, PULL_REQUEST.md)
- Fix line length issues in handlers.py introspection code - Prettier formatting for jump_to.ts - Add changelog entry for jupyterlab-lsp 5.2.1
|
Thank you for opening the PR! While I see the benefits of using the kernel to get such information, I think the solution for LSP specifically would be to have a way to pass environment path to the LSP server, otherwise we end up reimplementing the LSP logic for each feature and each language. |
|
agreed, that was one of the reasons why I built the fix as an extension - to have the capability in the absence of the official support in the jupyterlab-lsp having kernel-based jump-to-definition is quite critical, as for now project package (cookiecutter based projects) would need to be installed in base to make the jump-to-definition work |
but it should not be the case; it should be as simple as configuring the LSP server to look in your environment. What we should have in jupyterlab-lsp is a way to automatically pass the path of the kernel environment down to LSP server config. |
|
I see, so that when LSP launches for the given kernel session - it does make use of the kerne's environment, is that what you meant? Because I have been finishing another project - to embark more environments to present kernels to Jupyterlab It introduces VEnvKernelSpecManager for uv, venv (python) and conda (fallback to CondaKernelSpecManager) as virtual environment accesible to Jupyterlab via ipykernel package. |
|
I can try figure it out within jupyterlab-lsp architecture to make it, so that kernel's environment would be seen by the language server all along, but that'd take some digging |
References
Fixes #1096
Based on standalone extension: jupyterlab_jump_to_definition_fix
Jump-to-definition fails when packages are installed in a kernel environment different from the JupyterLab server environment. This is common in multi-environment deployments using
nb_conda_kernelsor similar setups.Code changes
Added a kernel-based Jedi fallback mechanism that activates when the LSP server returns no jump targets.
Backend (
python_packages/jupyter_lsp/jupyter_lsp/handlers.py):IntrospectionCodeHandlerclass servingGET /lsp/introspection-codesys.pathfor accurate import resolutionFrontend (
packages/jupyterlab-lsp/src/features/jump_to.ts):isPythonNotebook()- Detects Python kernels via notebook language metadata_fetchIntrospectionCode()- Retrieves introspection template from serverjumpWithKernelJedi()- Executes Jedi in kernel, parses result, opens target fileFallback flow:
kernel.requestExecute()documentManager.openOrReveal()Schema (
packages/jupyterlab-lsp/schema/jump_to.json):enableKernelFallbackboolean setting (default:true)User-facing changes
jedipackage installed in kernel environment for fallback to workBefore: "No jump targets found" when package exists only in kernel env
After: Opens source file at definition line
Backwards-incompatible changes
None. Existing LSP-based behavior is unchanged. Fallback only triggers when LSP returns no targets.
Chores
jlpm prettier,flake8,eslint:check- all pass)