lspmux-rust-analyzer
WARNING: This is mostly vibe coded and works for me (Rain) personally. This may
or may not work for you.
Uses lspmux, a Language Server Protocol multiplexer, to share
a single rust-analyzer instance across multiple LSP clients. This reduces memory and CPU usage when
running multiple editors or Claude Code sessions on the same workspace.
Problem
Each LSP client (editor, Claude Code session, etc.) spawns its own rust-analyzer
process. On systems running multiple editors, this causes significant memory
pressure since rust-analyzer is memory-intensive.
Solution
lspmux acts as an intermediary between LSP clients and language servers:
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Claude Code │ │ Zed │ │ Neovim │
│ (LSP client) │ │ (LSP client) │ │ (LSP client) │
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ │ │
│ stdio │ stdio │ stdio
▼ ▼ ▼
┌────────────────────────────────────────────────────┐
│ lspmux client shim │
│ (invoked as "rust-analyzer") │
└────────────────────────┬───────────────────────────┘
│ socket (localhost:27631)
▼
┌────────────────────────────────────────────────────┐
│ lspmux server │
│ (systemd user service) │
└────────────────────────┬───────────────────────────┘
│ manages
▼
┌────────────────────────────────────────────────────┐
│ rust-analyzer (one per workspace) │
└────────────────────────────────────────────────────┘
Quick start
./setup
The setup script:
- Downloads rust-analyzer from GitHub releases (with SHA256 verification)
- Installs lspmux via
cargo install --locked if not found
- Installs systemd services (Linux) or launchd agents (macOS)
After setup completes, configure your editor (see below).
Editor configuration
Claude Code
claude plugin marketplace add /path/to/lspmux-rust-analyzer
claude plugin disable rust-analyzer-lsp@claude-plugins-official --scope user
claude plugin install lspmux-rust@lspmux-plugins --scope user
Zed
In ~/.config/zed/settings.json:
{
"lsp": {
"rust-analyzer": {
"binary": {
"path": "lspmux",
"arguments": ["client", "--server-path", "/path/to/.local/share/lspmux-rust-analyzer/current/rust-analyzer"]
}
}
}
}
Replace /path/to with the actual path (e.g., /home/username or the value of $HOME).
Neovim (untested)
With nvim-lspconfig:
require('lspconfig').rust_analyzer.setup {
cmd = {
"lspmux", "client", "--server-path",
vim.fn.expand("$HOME/.local/share/lspmux-rust-analyzer/current/rust-analyzer")
},
}
Or if using rustaceanvim:
vim.g.rustaceanvim = {
server = {
cmd = function()
return {
"lspmux", "client", "--server-path",
vim.fn.expand("$HOME/.local/share/lspmux-rust-analyzer/current/rust-analyzer")
}
end,
},
}
Vim (untested)
With vim-lsp:
if executable('lspmux')
au User lsp_setup call lsp#register_server({
\ 'name': 'rust-analyzer',
\ 'cmd': ['lspmux', 'client', '--server-path', expand('$HOME/.local/share/lspmux-rust-analyzer/current/rust-analyzer')],
\ 'allowlist': ['rust'],
\ })
endif
With coc.nvim, in coc-settings.json:
{
"languageserver": {
"rust-analyzer": {
"command": "lspmux",
"args": ["client", "--server-path", "/path/to/.local/share/lspmux-rust-analyzer/current/rust-analyzer"],
"filetypes": ["rust"]
}
}
}
Requirements
- Linux (systemd) or macOS (launchd)
- Rust toolchain (for
cargo install)
- curl, jq
Directory structure
All paths respect the XDG base directory specification:
rust-analyzer
| Purpose | Default path |
|---|
| Binary versions | $XDG_DATA_HOME/lspmux-rust-analyzer/versions/ or ~/.local/share/lspmux-rust-analyzer/versions/ |
| Active version | $XDG_DATA_HOME/lspmux-rust-analyzer/current or ~/.local/share/lspmux-rust-analyzer/current (symlink) |
| Update script | $XDG_DATA_HOME/lspmux-rust-analyzer/bin/update-rust-analyzer or ~/.local/share/lspmux-rust-analyzer/bin/update-rust-analyzer |
| Update log | $XDG_STATE_HOME/lspmux-rust-analyzer/update.log or ~/.local/state/lspmux-rust-analyzer/update.log |
lspmux