Documentation
¶
Overview ¶
Package lsp bridges a WebSocket carrying JSON-RPC LSP messages to a language-server subprocess's stdio. Each LSP server gets a per-connection process (texlab / gopls / pyright / typescript- language-server) keyed by the language id.
Wire shape on the WS :
server → client : one JSON-RPC object per WS text frame client → server : one JSON-RPC object per WS text frame
The package strips + adds the Content-Length framing on the stdio side so the WS payload is the bare JSON, matching what the standard CodeMirror LSP clients expect (e.g. `codemirror-languageserver`, `@open-rpc/codemirror-lsp`).
Binary resolution : a language id resolves to a binary via the Servers map. The server is configurable via env variables :
WEFT_LOOM_LSP_TEXLAB — texlab binary path (default: "texlab") WEFT_LOOM_LSP_GOPLS — gopls binary path (default: "gopls") WEFT_LOOM_LSP_PYRIGHT — pyright-langserver (default: "pyright-langserver") WEFT_LOOM_LSP_TS — typescript-language-server (default: "typescript-language-server")
When the binary isn't on $PATH the bridge writes a JSON-RPC error response back to the client + closes the WS so the editor can surface a single visible failure instead of silently dropping completions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Servers = map[string]LanguageServer{ "latex": {Lang: "latex", Binary: "texlab", EnvOverride: "WEFT_LOOM_LSP_TEXLAB"}, "go": {Lang: "go", Binary: "gopls", EnvOverride: "WEFT_LOOM_LSP_GOPLS", Args: []string{"serve"}}, "python": {Lang: "python", Binary: "pyright-langserver", EnvOverride: "WEFT_LOOM_LSP_PYRIGHT", Args: []string{"--stdio"}}, "typescript": {Lang: "typescript", Binary: "typescript-language-server", EnvOverride: "WEFT_LOOM_LSP_TS", Args: []string{"--stdio"}}, "javascript": {Lang: "javascript", Binary: "typescript-language-server", EnvOverride: "WEFT_LOOM_LSP_TS", Args: []string{"--stdio"}}, "rust": {Lang: "rust", Binary: "rust-analyzer", EnvOverride: "WEFT_LOOM_LSP_RUSTANALYZER"}, "fake": {Lang: "fake", Binary: "fake-lsp-not-on-path", EnvOverride: "WEFT_LOOM_LSP_FAKE"}, }
Servers is the registry of LSP launchers. Adding a new language is a one-line change here ; the handler dispatches by the URL path's lang parameter.
Functions ¶
func AvailableLanguages ¶
func AvailableLanguages() []string
AvailableLanguages returns the set of language ids whose binary is actually resolvable on the host. The client uses this for progressive enablement : connecting to /api/lsp/<lang> when the host advertises support, and falling back to the regex-based autocomplete otherwise.
func EncodeError ¶
EncodeError writes a JSON-RPC error response. Used by the WS handler when the bridge can't be set up before the subprocess even starts.
func HandleWS ¶
func HandleWS(w http.ResponseWriter, r *http.Request, langKey string, logger *slog.Logger, acceptOpts *websocket.AcceptOptions)
HandleWS upgrades the HTTP request to a WebSocket + spawns the per-language LSP. Bidirectional pipe runs until either side closes ; the subprocess is killed on WS close.
langKey : the URL path param ("latex", "go", …) extracted by the caller's mux. Returning quickly on unknown languages keeps the editor's error path clean.
acceptOpts : the caller passes the same websocket.AcceptOptions it uses for the rest of its WS endpoints so the Origin allowlist stays uniform across /api/projects/{name}/collab, /shell and /lsp. nil = use a permissive default (dev mode).
Types ¶
type LanguageServer ¶
type LanguageServer struct {
Lang string // canonical key passed via URL path : "latex" / "go" / …
Binary string // default executable name
Args []string // additional CLI arguments
// EnvOverride : if non-empty + the env var is set, use that path
// instead of Binary. Lets ops override per-deployment without
// re-building the image.
EnvOverride string
}
LanguageServer describes how to launch one LSP for a given language.