Skip to content

relsunkaev/lspd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lspd

LSP multiplexer daemon for sharing language server instances across multiple editors.

This project is Bun/TypeScript-based (it previously had a Rust implementation, which has been removed).

Problem

Two failure modes that lspd handles:

  1. If you open multiple editor instances on the same project (multiple Neovim windows, OpenCode + Neovim, etc.), each client usually spawns its own language server process. For heavier servers like tsgo, this wastes a lot of CPU and memory.
  2. Servers like oxlint and tsgo are happiest when scoped to one config file (.oxlintrc.json, tsconfig.json). Running a single instance over a large monorepo conflates configs and can be slow. Splitting per config keeps state small and per-package settings honored.

Solution

lspd sits between your editor(s) and the language server.

  • For oxlint and tsgo (default): one server process per (nearest config file, server) pair. Files in packages/foo/ use the LSP rooted at packages/foo/; files in packages/bar/ use a separate LSP. Children are spawned lazily as you open files.
  • For other servers (or with --single-process): one server process per (projectRoot, serverName) pair, multiplexed to all editors.

Either way, multiple editor clients can share the same daemon.

Features

  • Per-manifest routing for oxlint (.oxlintrc.json) and tsgo (tsconfig.json, jsconfig.json)
  • Shared LSP instances across editor clients
  • Automatic lifecycle (daemon starts on first connection; exits after last client disconnects)
  • Binary discovery (prefers node_modules/.bin, with env overrides)
  • Request id translation (prevents collisions across multiple clients)
  • Diagnostics bridging for mixed clients
    • If a client doesn't support pull diagnostics (textDocument/diagnostic), the mux bridges pull->push using textDocument/publishDiagnostics.

Installation

This package requires bun to be installed (the CLI is a small Node wrapper that spawns Bun).

npm install -g lspd
# or
bun add -g lspd

Usage

Connect (used by editors)

lspd connect tsgo --project /path/to/project
lspd connect oxlint --project /path/to/project

# Force one process for the whole project (disables per-manifest routing):
lspd connect oxlint --project /path/to/project --single-process

Manage daemons

lspd ps
lspd ps --json

lspd kill tsgo --project /path/to/project
lspd kill oxlint --project /path/to/project --single-process
lspd kill --all

lspd prune

Your editor should start lspd connect <server> and speak LSP over stdin/stdout.

Neovim example

-- instead of: cmd = { "tsgo", "--lsp", "-stdio" }
cmd = { "lspd", "connect", "tsgo", "--project", vim.loop.cwd() }

Configuration

Environment variables:

  • LSPD_TSGO_BIN=/absolute/path/to/tsgo
  • LSPD_OXLINT_BIN=/absolute/path/to/oxlint

How it works (high-level)

  • lspd connect <server> ensures a daemon for (projectRoot, server) is running.
  • The daemon listens on a Unix domain socket under:
    • ~/.cache/lspd/daemons/<id>/daemon.sock
  • All connected editor clients are multiplexed to that daemon.
  • Inside the daemon:
    • For oxlint / tsgo: each inbound message is routed by its textDocument.uri to a child LSP whose cwd is the file's nearest manifest dir (.oxlintrc.json or tsconfig.json). Children are spawned lazily. Files outside any manifest fall back to a child rooted at --project.
    • For other servers (or with --single-process): one shared child handles everything.
  • Request ids are translated to avoid collisions; server-initiated requests are forwarded to the primary client and routed back to the originating child.

Caveats for per-manifest mode

  • Cross-config requests (e.g. tsgo find references across packages with separate tsconfig.jsons) only see the file's own subproject. If your monorepo relies on TS project references for cross-package navigation, use --single-process for tsgo.
  • workspace/symbol and similar workspace-wide queries are best-effort: they go to the --project fallback child only.

Development

bun test

Notes:

  • The smoke tests use test-fixtures/proj and will run bun install there as needed.
  • The tsgo smoke test may build tsgo from source if the prebuilt binary hangs, which requires git, go, and network access.

License

MIT (see LICENSE).

About

No description, website, or topics provided.

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors