lsp

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func EncodeError(id any, code int, msg string) []byte

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).

func WithSubject

func WithSubject(ctx context.Context, subject string) context.Context

WithSubject returns a child context tagged with the per-user counter key. Call this in the loom-server handler before HandleWS.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL