• Stars
    star
    214
  • Rank 184,678 (Top 4 %)
  • Language
    TypeScript
  • License
    BSD 3-Clause "New...
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Navigate to variable's definition with a click in JupyterLab (or with a few key strokes)

Go to definition extension for JupyterLab

Build Status codebeat badge Binder

Status: inactive

This extension is no longer maintained. Please use jupyterlab-lsp which provides more features, including advanced autocompletion, code navigation, hover suggestions, linters, etc. The code shared between the jupyterlab-lsp and jupyterlab-go-to-definition extensions was moved to @krassowski/code-jumpers library and could be re-used to update jupyterlab-go-to-definition to work with current JupyterLab versions, however I do not have time to support both extensions and focus on making jupyterlab-lsp better.

Description

Jump to definition of a variable or function in JupyterLab notebook and file editor.

Use Alt + click to jump to a definition using your mouse, or Ctrl + Alt + B keyboard-only alternative.

Go to definition

You can replace the key modifier for mouse click from Alt to Control, Shift, Meta or AltGraph in the settings (see remarks below).

To jump back to the variable/function usage, use Alt + o.

The plugin is language-agnostic, though optimized for Python and R. Support for other languages is possible (PRs welcome).

Jumping to definitions in other files

Python:

  • alt-click on the name of a module in Python (e.g. from x.y import z - alt-click on x or z) (new in v0.5)
  • alt-click on a class, function or method imported from any module (except for builtin modules written in C as such do not have a corresponding Python source file) in a notebook with active Python 3 kernel (new in v0.6)

R (new in v0.5):

  • alt-click on source function (e.g. alt-clicking on source in source('test.R') will open test.R file)
  • alt-click on .from of import::here(x, y, .from='some_file.R')

Background: there are two ways to solve the definitions location: static analysis and inspection performed in the kernel. The latter is more accurate, although it currently only works in notebooks (not in the file editor). For the implementation overview, please see the design page. In order to jump to a file outside of the JupyterLab project directory (e.g. the built-in Python libraries) a symlink-based workaround is required.

Changing the modifiers key from alt

Please go to Settings > Advanced Setting Editor > Go-to-definition and set a modifier of your choice in the User Preferences panel. For full list of physical keys mapped to the modifiers (which depend on your Operating System), please see the MDN documentation.

Safari users: Safari does not implement MouseEvent.getModifierState (see #3), thus only Alt, Control, Shift and Meta are supported.

Prerequisites

  • JupyterLab >= 1.0, <= 2.2

Installation

jupyter labextension install @krassowski/jupyterlab_go_to_definition   # JuupyterLab 2.x
jupyter labextension install @krassowski/[email protected]   # JupyterLab 1.x

To update already installed extension:

jupyter labextension update @krassowski/jupyterlab_go_to_definition

Development

For a development install (requires npm version 4 or later), do the following in the repository directory:

npm install
npm run build
jupyter labextension link .

To rebuild the package and the JupyterLab app:

npm run build
jupyter lab build

To run tests suite:

npm test

Adding support for additional languages

Support for new languages should be provided by implementation of abstract LanguageAnalyzer class (in case of languages which support use of semicolons to terminate statements LanguageWithOptionalSemicolons helper class can be utilized).

Each new language class needs to be included in chooseLanguageAnalyzer function and the developer needs to verify if setLanguageFromMime in fileeditor.ts will be able to recognize the language properly.

Symlink workaround (jump to any file outside of the project root)

JupyterLab attempts to protect users from accessing system files by restricting the accessible files to those within the directory it was started in (so called project root). If you wish to jump to files outside of the project root, you cold use a symlink workaround as follows:

  1. create .jupyter_symlinks in the top directory of your JupyterLab project, and
  2. symlink your home, usr, or any other location which includes the files that you wish to make possible to open in there. The Linux following commands demonstrate the idea:
mkdir .jupyter_symlinks
cd .jupyter_symlinks
ln -s /home home
ln -s /usr usr

Which directories to symlink?

To find out which paths you need to symlink for Python you could run python3 -v which will list where are the specific built-in modules imported from. Look out for lines like these:

# /srv/conda/envs/notebook/lib/python3.7/__pycache__/_collections_abc.cpython-37.pyc matches /srv/conda/envs/notebook/lib/python3.7/_collections_abc.py
# code object from '/srv/conda/envs/notebook/lib/python3.7/__pycache__/_collections_abc.cpython-37.pyc'
import '_collections_abc' # <_frozen_importlib_external.SourceFileLoader object at 0x7f77ba22c400>

which mean that you want /srv/conda/envs/notebook/lib/python3.7/ to be symlinked to access _collections_abc. You can do this by:

# still in .jupyter_symlinks
mkdir -p srv/conda/envs/notebook/lib
# note: no slash (/) at the begining of the second path
ln -s /srv/conda/envs/notebook/lib/python3.7 srv/conda/envs/notebook/lib/python3.7

Please note that not every Python built-in module has a corresponding Python file, as many are written in C for performance reasons.

More Repositories

1

complex-upset

A library for creating complex UpSet plots with ggplot2 geoms
R
353
star
2

jupyter-manim

manim cell magic for IPython/Jupyter to show the output video
Python
187
star
3

Anki-Night-Mode

Enabling studying at night with Anki - without eye strain
Python
72
star
4

jupyterlab-citation-manager

Citation Manager for JupyterLab using Zotero Web API
TypeScript
47
star
5

jupyter-helpers

A collection of helpers for Jupyter/IPython
Python
45
star
6

easy-entrez

Retrieve PubMed articles, text-mining annotations, or molecular data from >35 Entrez databases via easy to use Python package - built on top of Entrez E-utilities API.
Python
45
star
7

declarative-parser

Modern, declarative argument parser for Python 3.6+
Python
34
star
8

multi-omics-state-of-the-field

Analyses for "State of the field in multi-omics research: from computational needs to data mining and sharing"
Jupyter Notebook
24
star
9

Anki-TouchScreen

Touchscreen functionality for Anki
Python
22
star
10

nbpipeline

Snakemake-like pipeline manager for reproducible Jupyter Notebooks
Python
15
star
11

drug-disease-profile-matching

Multi-omics disease sub-type specific drug repositioning aided with expression signatures from ConnectivityMap
Jupyter Notebook
14
star
12

data-vault

IPython magic for simple, organized, compressed and encrypted: storage & transfer of files between notebooks.
Python
12
star
13

computational-notebooks-for-biomedical-research

NGSeminar on the use of Jupyter and R notebooks in biomedical research
Jupyter Notebook
11
star
14

anki_testing

A small utility for testing Anki 2.1 addons
Python
10
star
15

jupyterlab-dagitty

JupyterLab renderer of dagitty causal diagrams
TypeScript
10
star
16

gsea-api

Pandas API for multiple Gene Set Enrichment Analysis implementations in Python (GSEApy, cudaGSEA, GSEA)
Python
8
star
17

rpy2-complex-heatmap-grammar

Python heatmap interface using intuitive grammar of graphics, implemented as an rpy2 wrapper around ComplexHeatmap package.
Python
8
star
18

Anki-Zoom

Zoom add-on for Anki 2.1, forked from ospalh/anki-addons
Python
6
star
19

enhanced-multiprocessing

A wrapper around Python's multiprocessing, providing support for tqdm progress bars and shared arguments
Python
3
star
20

plotnine3d

3D geoms for plotnine (grammar of graphics in Python)
Python
3
star
21

jupyterlab-citation-data

Citation data for jupyterlab-citation-manager
Python
2
star
22

jupyterlab-voice-control

Voice control over JupyterLab and Jupyter notebooks
TypeScript
2
star
23

vmd-agr-parser

Simple script for plotting .agr (Grace) files created with VMD (Visual Molecular Dynamics). Allows export to csv/svg/png.
Python
1
star