A simple Python tool that allows multiple Language Server Protocol (LSP) servers to be multiplexed into a single LSP connection. This is useful when you want to combine the capabilities of multiple language servers - for example, using both Pyright (for type checking) and Ruff-LSP (for linting) with a single LSP client connection.
Requires Python 3.8 or higher.
git clone https://github.com/garyo/lsp-multiplexer
cd lsp-multiplexer
The multiplexer can run either over TCP or stdio:
# Run over TCP (default port 8888)
python lsp-multiplexer.py
# Run using stdio (for editors that expect LSP over stdio)
python lsp-multiplexer.py --stdio
# Run on a specific host and port
python lsp-multiplexer.py --host localhost --port 9999
--stdio
: Use stdio instead of TCP--host
: Host to listen on (default: 127.0.0.1)--port
: Port to listen on (default: 8888)--log-level
: Set logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
Edit the server configurations in lsp-multiplexer.py
:
multiplexer = LSPMultiplexer([
["pyright-langserver", "--stdio"], # Local process
"tcp://localhost:8080", # Remote server
["ruff-lsp"] # Another local process
])
Each server can be specified either as:
- A list of strings for a local process (command and arguments)
- A URL string for a remote server
vim.lsp.start({
name = 'multiplexed-python',
cmd = {'nc', 'localhost', '8888'}, -- For TCP mode
-- or
cmd = {'python', 'path/to/lsp-multiplexer.py', '--stdio'}, -- For stdio mode
root_dir = vim.fs.dirname(vim.fs.find({'pyproject.toml', 'setup.py'}, { upward = true })[1]),
})
(lsp-register-client
(make-lsp-client
:new-connection (lsp-tcp-connection '("python" "path/to/lsp-multiplexer.py"))
:major-modes '(python-mode)
:server-id 'multiplexed-python))
For debugging, use the --log-level DEBUG
flag to see detailed logs:
python lsp-multiplexer.py --stdio --log-level DEBUG
MIT