Skip to main content

jupyterlab_jump_to_definition_fix

GitHub Actions npm version PyPI version Total PyPI downloads JupyterLab 4 Brought To You By KOLOMOLO

[!TIP] This fix is part of the stellars_jupyterlab_fixes metapackage. Install all Stellars fixes at once: pip install stellars_jupyterlab_fixes

JupyterLab extension that fixes "jump to definition" functionality for notebooks using Jedi static analysis in the kernel environment. This allows jumping to source code definitions for packages installed in the notebook's kernel, even if those packages are not installed in JupyterLab's own environment.

[!WARNING] This extension is a temporary fix until the jupyterlab-lsp project implements native support for kernel-aware jump-to-definition. Track the upstream issue: jupyter-lsp/jupyterlab-lsp#1096. Once merged and released, this extension will be deprecated.

The Problem

JupyterLab's built-in LSP "jump to definition" only works for packages installed in the same Python environment as JupyterLab itself. Notebooks often run with kernels in different environments (conda envs, virtual envs, containers) where packages are actually installed, making the stock LSP functionality useless for kernel-installed packages.

The Fix

This extension replaces the stock LSP "jump to definition" command for Python notebooks with a Jedi-based implementation that runs in the kernel's Python environment.

How it works:

  • Executes Jedi static analysis directly in the notebook's kernel
  • Uses kernel's sys.path for module resolution, finding packages installed in kernel environment
  • Analyzes all notebook cells as concatenated source to understand full context
  • Opens external definitions by converting absolute filesystem paths to JupyterLab-relative paths
  • Jumps in place for definitions inside the notebook itself - navigates to the defining cell without reopening a file
  • Seamlessly overrides stock LSP command - same keyboard shortcut, same menu entry

Implementation details:

  • Frontend: Collects all code cell sources, calculates cursor position across cells, sends to kernel
  • Backend: Provides Jedi introspection code template executed in kernel
  • Jedi: Runs Script.goto() with follow_imports=True using kernel's module search paths
  • Path resolution: Calculates server root from kernel CWD and notebook path

Fix Implementation Details

The extension consists of frontend TypeScript code and backend Python code working together to provide kernel-aware jump-to-definition.

Frontend Implementation (src/index.ts):

  • Command Registration: app.commands.addCommand(commandId) creates notebook:jump-to-definition-kernel command that collects notebook context and executes Jedi analysis
  • Cell Source Collection: Command execute function iterates through notebook.content.widgets, concatenates code cell sources, and calculates absolute cursor position accounting for multi-cell structure. Jedi requires 1-based line numbers
  • Kernel Execution: kernel.requestExecute() sends Jedi introspection code to kernel, future.onIOPub handler captures stdout (JSON result) while filtering stderr (debug logs)
  • Path Conversion: For external definitions, a secondary kernel execution gets CWD via os.getcwd(), calculates the JupyterLab server root from the notebook path, and converts absolute filesystem paths to server-relative paths for docManager.openOrReveal()
  • In-notebook Navigation: When the definition resolves to the notebook's own source, the absolute line is mapped back to a (cell, line) and the cursor moves there via the notebook API instead of reopening a file - this avoids a path-doubling 404 that occurred when the kernel CWD equalled the notebook's directory
  • Stock LSP Override: overrideLSPCommand() function dynamically intercepts lsp:jump-to-definition command when it loads, preserves original icon and label, routes Python notebooks to Jedi implementation while delegating others to stock LSP

Backend Implementation (jupyterlab_jump_to_definition_fix/routes.py):

  • Introspection Code Template: IntrospectionCodeHandler.get() method provides Python code template executed in kernel environment that imports Jedi, creates jedi.Project with kernel's sys.path, runs Script.goto() with follow_imports=True, and returns JSON with file path, line number, and an in_notebook flag set when the definition resolves to the notebook's own source (compared in-kernel, so cwd-independent)
  • API Handler: Route registered at /jupyterlab_jump_to_definition_fix/introspection-code endpoint serves template to frontend

Key Implementation Components:

  • jedi.Project(path=notebook_path, sys_path=sys.path): Creates Jedi project using kernel's module search paths for accurate resolution
  • jedi.Script(...).goto(follow_imports=True): Performs static analysis to find symbol definitions, following import chains
  • kernel.requestExecute(): Executes Jedi code in kernel's Python environment where target packages are installed
  • IOPub message filtering: Separates stdout (JSON result) from stderr (debug output) for clean parsing
  • Path calculation: kernelCwd.endsWith(notebookDir) logic strips server root from absolute paths

Features

  • Replaces stock LSP: Overrides lsp:jump-to-definition command for Python notebooks
  • Kernel-aware: Uses kernel's Python environment and sys.path for module resolution
  • Static analysis: Jedi finds definitions without requiring code execution
  • Same UX: Identical keyboard shortcut (Ctrl+B / Cmd+B) and menu entries as stock LSP
  • Automatic fallback: Delegates to stock LSP for non-Python notebooks

Usage

  1. Open a Jupyter notebook with a Python kernel
  2. Place your cursor on or select a symbol (function name, class name, module attribute, etc.)
  3. Press Ctrl+B (or Cmd+B on Mac), or run "Jump to Definition (Kernel Context)" from the command palette
  4. The source file opens at the definition location - or, for a symbol defined in the notebook itself, the cursor jumps to the defining cell

Examples of symbols you can jump to:

  • Module: numpy or pandas
  • Function: np.array, pd.DataFrame
  • Method: MyClass.my_method
  • Nested attributes: sklearn.ensemble.RandomForestClassifier

This extension is composed of a Python package named jupyterlab_jump_to_definition_fix for the server extension and a NPM package named jupyterlab_jump_to_definition_fix for the frontend extension.

Requirements

  • JupyterLab >= 4.0.0
  • Python kernel (IPython/ipykernel)

Install

To install the extension, execute:

pip install jupyterlab_jump_to_definition_fix

Uninstall

To remove the extension, execute:

pip uninstall jupyterlab_jump_to_definition_fix

Metadata

Release files for jupyterlab-jump-to-definition-fix 1.0.69

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jupyterlab-jump-to-definition-fix 1.0.69
File Size Uploaded
jupyterlab_jump_to_definition_fix-1.0.69.tar.gz 207.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jupyterlab-jump-to-definition-fix 1.0.69
File Interpreter ABI Platform
jupyterlab_jump_to_definition_fix-1.0.69-py3-none-any.whl Python 3 none any Details

Total release size: 231.2 kB

Release files / jupyterlab_jump_to_definition_fix-1.0.69.tar.gz

Download URL jupyterlab_jump_to_definition_fix-1.0.69.tar.gz
Size 207.6 kB
Tags Source
SHA-256 checksum
How to use checksums
997f7cddd2047848de45952c0ca9a9375f63906cb3fcce6113a79dbe6f52285e
BLAKE2b-256 checksum
How to use checksums
989bc7766ccdaef77ed08edda1bfccba4996a6072674b686def1fa6569f67204
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.14

Release files / jupyterlab_jump_to_definition_fix-1.0.69-py3-none-any.whl

Download URL jupyterlab_jump_to_definition_fix-1.0.69-py3-none-any.whl
Size 23.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2e3580551db5c8c47f79bd3e7c37dc4613325974d3b3c5fc7c9011395c2ebbbb
BLAKE2b-256 checksum
How to use checksums
109b79803b615a9066d9403c4e39a282e059f0d3b77ae83fef27726297214dd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

1.0.69 This release

2 release files

1.0.63

2 release files

1.0.62

2 release files

1.0.61

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page