A unified Language Server Protocol (LSP) proxy that intelligently combines the Svelte Language Server and TypeScript Language Server, providing comprehensive IDE support for Svelte applications with no client-side configuration complexity.
npm install -g svelte-proxy-lsp
npm install --save-dev svelte-proxy-lsp
npx svelte-proxy-lsp --stdio
This proxy acts as a transparent middleware between LSP clients and the actual language servers:
┌─────────────────────────────────────────────────────────┐
│ LSP Client │
│ (VS Code, Neovim, etc.) │
└─────────────────────┬───────────────────────────────────┘
│ LSP Protocol (Single Connection)
┌─────────────────────▼───────────────────────────────────┐
│ Svelte Proxy LSP │
│ │
│ ┌─────────────────────────────────────────────────┐ │
│ │ ProxyServer │ │
│ │ │ │
│ │ ┌──────────────────┬─────────────────────────┐ │ │
│ │ │ Request Router │ Document Manager │ │ │
│ │ │ - Position │ - Parse .svelte │ │ │
│ │ │ Analysis │ - Track Changes │ │ │
│ │ │ - Service │ - Sync State │ │ │
│ │ │ Selection │ │ │ │
│ │ └──────────────────┴─────────────────────────┘ │ │
│ └─────────────────────────────────────────────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌────────────────┐ ┌─────────────────┐ │
│ │ Svelte │ │ TypeScript │ │
│ │ Language │ │ Language │ │
│ │ Server │ │ Server │ │
│ │ (Process) │ │ (Process) │ │
│ └────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────┘
.svelte
files to determine which server(s) to querysvelte-language-server
and typescript-language-server
as child processesThe proxy intelligently routes requests based on where your cursor is:
<script>
tags): Routes to TypeScript Language Server<style>
tags): Routes to Svelte Language Server<script>
blocks with Svelte-aware TypeScript plugin<style>
blocks# Using npx (no installation required)
npx svelte-proxy-lsp --stdio
# After global installation
svelte-proxy-lsp --stdio
# With socket
svelte-proxy-lsp --socket=5000
# With verbose logging for debugging
svelte-proxy-lsp --stdio --verbose
# With trace logging (most detailed)
svelte-proxy-lsp --stdio --trace
# Quiet mode (errors only)
svelte-proxy-lsp --stdio --quiet
# Custom log level
svelte-proxy-lsp --stdio --log-level=debug
# Show help
svelte-proxy-lsp --help
The proxy supports configurable logging levels:
--verbose
- Debug level logging (shows server startup, requests, etc.)--trace
- Most detailed logging (includes all requests and responses)--quiet
- Only shows errors--log-level=<level>
- Set specific level: error
, warn
, info
, debug
, trace
Note: In --stdio
mode (default), logging is automatically set to error
level to avoid interfering with LSP communication. Use --verbose
or --trace
to override this for debugging.
Add to settings.json
:
{
"svelte.enable": false,
"typescript.suggest.enabled": false,
"eslint.enable": false
}
Then configure the proxy in your language client settings or use with a VS Code extension that points to:
node /path/to/svelte-proxy-lsp/dist/server.js --stdio
local lspconfig = require('lspconfig')
-- Custom LSP configuration for Svelte Proxy
lspconfig.svelteproxy = {
default_config = {
cmd = { 'node', '/path/to/svelte-proxy-lsp/dist/server.js', '--stdio' },
filetypes = { 'svelte', 'typescript', 'javascript' },
root_dir = lspconfig.util.root_pattern('package.json', 'svelte.config.js', '.git'),
settings = {},
},
}
-- Use the proxy
lspconfig.svelteproxy.setup{}
(lsp-register-client
(make-lsp-client
:new-connection (lsp-stdio-connection '("node" "/path/to/svelte-proxy-lsp/dist/server.js" "--stdio"))
:major-modes '(svelte-mode typescript-mode js-mode)
:server-id 'svelte-proxy-lsp))
# Start the proxy server
node dist/server.js --stdio
# Test with a simple request (requires LSP client)
# The server will automatically spawn svelte-language-server and typescript-language-server
src/
├── server.ts # Main entry point
├── proxy/
│ ├── ProxyServer.ts # Core proxy logic and request routing
│ └── LSPServerProcess.ts # Child process management for LSP servers
└── utils/
└── documentParser.ts # Svelte document parsing and region detection
.svelte
files to identify script/template/style regionspnpm build # Compile TypeScript
pnpm dev # Watch mode development
pnpm clean # Clean build artifacts
pnpm start # Start the proxy server
The project includes comprehensive unit and integration tests:
# Run all tests (47 passing, 1 skipped)
pnpm test
# Run tests in watch mode
pnpm test:watch
# Run specific test suites
pnpm test -- --testPathPattern="diagnostics"
pnpm test -- --testPathPattern="symbol-insertion"
pnpm test -- --testPathPattern="workspace-symbols"
For manual testing:
# Start the proxy directly
npx tsx src/server.ts --stdio
# Or build and run
pnpm build && pnpm start --stdio
The proxy automatically detects and configures the underlying language servers. No additional configuration needed - it inherits the capabilities of both servers.
The proxy automatically finds language servers in this order:
svelte-language-server
via require.resolve()
typescript-language-server
via PATH lookupsvelte-language-server@^0.16.14
typescript-language-server@^4.3.3
typescript-svelte-plugin@^0.3.40
(automatically configured)vscode-languageserver@^10.0.0
- LSP protocol types and utilitiesvscode-jsonrpc@^9.0.0-next.8
- Direct JSON-RPC communicationvscode-languageserver-protocol@^3.17.6
- Protocol definitionsMIT