$ show jupyter-lsp/jupyterlab-lsp
This repository is a monorepo implementing a Language Server Protocol (LSP) integration for JupyterLab, consisting of a Python backend (`jupyter-lsp`) and a TypeScript frontend (`jupyterlab-lsp`). The backend manages multiple language server processes (Python, R, Julia, bash, SQL, etc.) via WebSocket proxying, file system shadowing for disk-based servers, and configurable spec discovery. The frontend provides LSP features (autocompletion, diagnostics, hover, jump-to-definition, rename, signature help, syntax highlighting) as JupyterLab plugins, with custom CodeMirror 6 extensions, a diagnostics panel, and a status bar. The architecture includes virtual documents for notebook cells with IPython magic handling, foreign code extraction (e.g., `%%R`, `%%sql`), and a settings schema system that dynamically populates language server configuration UIs. The codebase is well-tested with Python unit tests, TypeScript unit tests, and Robot Framework acceptance tests running in CI. While the core functionality is robust, there is moderate technical drift due to reliance on undocumented JupyterLab internal APIs, fragile regex-based magic parsing, and some deprecated language server specifications.
The LLM identified 4 files worth highlighting for reuse:
Manages temporary shadow files on disk for LSP servers that require physical files instead of in-memory documents. Handles creation, cleanup, symlink resolution (with security checks to avoid symlink attacks), and URI mapping. This pattern is reusable for any LSP client that needs to bridge in-memory and disk-based document representations.
Provides base classes (`SpecBase`, `SimpleSpecMaker`) and utilities for discovering and configuring language server executables. Uses Python entry points (`jupyter_lsp_spec_v1`) to register spec finders. The pattern is cleanly extensible and could be extracted for any tool needing pluggable discovery of external processes.
Implements `GenericCompleterModel` and `LSPCompleterModel` with custom prefix matching, sorting (by score, by length, type-based ordering), and HTML-safe label rendering. Separates model logic from UI, making it reusable for any completion widget in a CodeMirror or web-based editor.
Uses `RegExpForeignCodeExtractor` and `ReversibleOverridesMap` to transform IPython cell/line magics (e.g., `%%R`, `%%sql`) into analyzable Python code for LSP analysis. The pattern of regex-based extraction with reversible overrides is reusable for any kernel that supports foreign language blocks.