protolsp

module
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT

README

protolsp

Go Language Server for .pxf files (Proto eXpressive Format) — schema-aware authoring backed by protoregistry.

protolsp powers parse + schema diagnostics, hover with namespace provenance, completion (field names, message types, enum values), quick-fix code actions, and go-to-definition for any LSP-capable editor (VS Code via the PXF extension, Neovim, Zed, Helix) plus the hosted Monaco IDE over WebSocket.

Install

git clone https://github.com/trendvidia/protolsp
cd protolsp
go install ./cmd/protolsp ./cmd/protolsp-ws    # stdio, websocket

For a release, check out its tag first (git checkout v0.23.0).

Releases after v0.23.1 can also be installed without a clone:

go install github.com/trendvidia/protolsp/cmd/protolsp@latest
go install github.com/trendvidia/protolsp/cmd/protolsp-ws@latest

The default build is the community build. Building with -tags protocheck adds protocheck runtime validation through the govm expression engine, and needs the govm and protocheck-govm modules, which are not public.

Features

  • Parse diagnostics via pxf.Parse — syntax errors with 1-indexed position fidelity from the parser, converted to LSP's 0-indexed range.
  • Schema-aware diagnostics via pxf.UnmarshalDescriptor. The bound resolver is constructed with WithServerChain so an organization's namespace hierarchy resolves automatically.
  • Hover with field type, defining file path, leading proto doc comments, and namespace provenance (Defined in <path> (namespace <id>)) when the resolver attributes the file to a tracked namespace.
  • Completion for field names (AST-aware nested-block context), message types on @type directives, and enum values on the RHS of enum-typed field assignments.
  • Code actions — Hint diagnostics with Tags: [Deprecated] for [deprecated = true] fields plus a "Remove field" quick-fix for unknown fields.
  • Go-to-definition for field assignments, block names, and @type FQNs. URI precedence: local file:// when on disk → registry://<namespace>/<file-path> for registry-backed virtual documents → blind file:// last-resort.
  • Chameleon chain support — layer classification, chain-aware required-field weighting, ${field.path} go-to-definition and cycle detection, merged-value hover. See docs/design/chameleon-integration.md.
  • Secret redaction — pxf.Secret values are scrubbed from diagnostics, hover, and completion details before reaching the wire. Literal-secret warnings + env-ref quick-fix.
  • Dataset region awareness — @dataset block detection, per-row validation for huge regions, region-aware hover.

Custom LSP methods

protolsp exposes several protolsp/* requests + notifications beyond the standard LSP surface. Editor implementers wiring status bars, sidebars, or extension UIs consume these directly.

Requests:

Method Purpose Design
protolsp/sourceContent Fetch bytes for a registry:// URI via protoregistry/client.Resolver.GetSource. Routes _proto_files_ to the workspace proto sources and _internal_ to the embedded shipped types (see Registry URI namespaces). mvp
protolsp/listMessages Enumerate every message type the resolver knows (sorted, deduped, prefix-filterable). mvp
protolsp/registryStatus {configured, stale} — is the resolver wired, and is it serving live or from on-disk cache? Status-bar input. mvp
protolsp/configList Enumerate every config attribute known to the four-tier resolver, with type + section metadata. Drives the "configurable attributes" UI in editors that want to render a settings explorer. config-protocol
protolsp/configGet Read one attribute's effective value + tier provenance. config-protocol
protolsp/configSet Set or clear one attribute at the override tier. Drives the per-attribute settings forms. config-protocol
protolsp/getEffectiveConfig Four-tier-resolved (default / file / settings / override) view of every known config section, with provenance. revealSecrets flag opts out of name-pattern redaction. config-protocol
protolsp/setOverrides Install Tier 4 session overrides (e.g. for "Show debug logs for this session" UI). config-protocol
protolsp/secretRanges Per-document ranges of every pxf.Secret-typed value. Editors mask these exactly. secret-handling
protolsp/datasetRegions Per-document @dataset regions with row counts + Huge flag for placeholder rendering. dataset-regions
protolsp/chainStatus Workspace's chameleon chain summary: environments, ancestors, errors. chameleon-integration
protolsp/layerInfo Per-document classification: is this file a chain layer? Which environment? chameleon-integration

Notifications:

Method Fires when
protolsp/effectiveConfigChanged A setOverrides call changes any effective value. Payload mirrors the changed subset of getEffectiveConfig.
protolsp/secretRangesChanged Re-analyze produced a SecretRanges slice that differs from the prior snapshot.
protolsp/datasetRegionsChanged Re-analyze produced a DatasetRegions slice that differs from the prior snapshot.

Wire shapes live next to each method's dispatcher in internal/server (search for MethodSourceContent etc.); the linked design docs cover the protocol-level intent.

Connect-RPC services

protolsp 0.3+ runs a typed Connect-RPC sidecar alongside the LSP surface. Strongly-typed clients (pxfed, future hosted IDE) prefer the RPC path; legacy LSP custom methods stay registered for backward compatibility (deprecation horizon tracked in #113).

Service definitions live in proto/protolsp/v1/rpc/*.proto. Request/response message shapes regenerate from those .proto files via cd proto && buf generate (see Regenerating proto bindings).

Service Method Kind Mirrors LSP method
ConfigService ListAttributes unary protolsp/configList
GetAttribute unary protolsp/configGet
SetAttribute unary protolsp/configSet
RegistryService GetStatus unary protolsp/registryStatus
SchemaService ListMessages unary protolsp/listMessages
GetSourceContent unary protolsp/sourceContent
ChameleonService GetChainStatus unary protolsp/chainStatus
GetLayerInfo unary protolsp/layerInfo
SecretsService GetRanges unary protolsp/secretRanges
Subscribe server-streaming protolsp/secretRangesChanged
DatasetsService GetRegions unary protolsp/datasetRegions
Subscribe server-streaming protolsp/datasetRegionsChanged
EffectiveConfigService GetEffectiveConfig unary protolsp/getEffectiveConfig
SetOverrides unary protolsp/setOverrides
Subscribe server-streaming protolsp/effectiveConfigChanged

Subscribe streams send the current snapshot as their first message, then change events for every subsequent update — clients don't need a separate Get* round-trip before subscribing.

Sidecar discovery

The sidecar listens on 127.0.0.1:<ephemeral> over HTTP/2 (h2c). Its address and a per-session bearer token are returned in the LSP initialize result so clients can dial in without out-of-band coordination:

{
  "capabilities": { ... },
  "serverInfo": {
    "name": "protolsp",
    "version": "0.x.y",
    "rpc": {
      "address": "http://127.0.0.1:54321",
      "token":   "<64-char hex>"
    }
  }
}

Clients present Authorization: Bearer <token> on every request. The token is 32 random bytes hex-encoded — sufficient against drive-by connections from other local processes; no replay protection since loopback-only. The address + token are stable for the lifetime of the LSP session and regenerated on each restart.

Editors that don't know about rpc ignore the extra key.

Registry URI namespaces

registry://<namespace>/<path> URIs returned by go-to-definition and consumed by GetSourceContent use two reserved namespaces in addition to real registry namespace IDs:

Namespace Backed by Use
_proto_files_ The workspace's .protolsp.pxf proto_files { paths = [...] } block. Types defined in local .proto files alongside the .pxf workspace.
_internal_ Embedded shipped .proto descriptors compiled into the protolsp binary. Types protolsp ships internally (e.g. protolsp.v1.WorkspaceConfig).
any other The configured protoregistry namespace. Schema-as-a-service: registry-backed types fetched over the wire and cached on disk.

Both reserved names use leading/trailing underscores so they're distinguishable from real reverse-DNS namespace IDs while staying URI-safe per RFC 3986 (parentheses in the original (proto_files) were rejected by Monaco's URI parser).

Transports

  • stdio (cmd/protolsp): the universal LSP transport. Editor extensions spawn the binary as a child process.
  • WebSocket (cmd/protolsp-ws): for browser-hosted Monaco clients. --addr, --path, --origins, --insecure-skip-origin-verify, --max-message-bytes flags; /healthz endpoint.
  • Connect-RPC sidecar (bound at initialize): typed proto services covering the custom-method surface, advertised in InitializeResult.serverInfo.rpc. See Connect-RPC services above for the per-service method table and the discovery payload.

Regenerating proto bindings

The proto files live under proto/. Go bindings (*.pb.go, rpcpbconnect/*.connect.go) are committed alongside their sources; regenerate after editing a .proto:

cd proto && buf generate

Prerequisites (one-time):

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install connectrpc.com/connect/cmd/protoc-gen-connect-go@latest

TypeScript stubs for clients like pxfed are NOT generated here — each client owns its own codegen. See pxfed/buf.gen.ts.yaml + pnpm rpc:gen for the pxfed-side pipeline.

Configuration

protolsp resolves configuration through four tiers, highest precedence first:

  1. Override — session-scoped via protolsp/setOverrides. In-memory only.
  2. Settings — Tier 3, pulled from the editor via standard workspace/configuration (or seeded once from initializationOptions for legacy clients — see below).
  3. File — .protolsp.pxf checked into the repo.
  4. Default — compiled into the binary.

See docs/design/config-protocol.md for the full model.

Commit a .protolsp.pxf to the workspace root (or any subtree — nearest-ancestor wins, monorepos with per-service config work out of the box):

@type protolsp.v1.WorkspaceConfig

registry {
  address   = "registry.example.com:443"
  namespace = "acme-billing"
  token     = "${env.PROTOREGISTRY_TOKEN}"
  cache_dir = "${env.HOME}/.cache/protolsp"
}

chameleon {
  enabled    = true
  chain_spec = "chain.pxf"
}

${env.X} interpolation reads from the LSP process's environment at parse time — keep secrets out of the committed file.

See docs/design/workspace-config.md for the full schema (registry, chameleon, schema_sources, security) and the multi-root / sub-workspace discovery model.

Editor settings (Tier 3)

Editors that implement workspace/configuration deliver settings under the protolsp.* namespace. The VS Code extension wires the standard protolsp.registry.address, protolsp.registry.namespace, protolsp.registry.token, protolsp.registry.cacheDir, protolsp.security.inline_secrets keys.

initializationOptions (legacy seed)

For clients that don't implement workspace/configuration, protolsp still accepts the legacy seed shape at initialize:

{
  "registry": {
    "address":   "registry.example.com:443",
    "namespace": "acme-billing",
    "token":     "<optional bearer token>",
    "cacheDir":  "/path/to/cache"
  }
}

This path is deprecated — clients that supply registry config via initializationOptions AND advertise workspace/configuration capability receive a one-time window/showMessage nudge at initialized to migrate. The seed will be removed in a future release (see the migration plan in docs/design/config-protocol.md).

Schema validation lifecycle

Empty registry.address (across all four tiers) disables schema validation — protolsp degrades to parse-only diagnostics.

cacheDir, when set, enables the protoregistry client's on-disk descriptor cache. Successful refreshes are persisted, and if the registry is unreachable at startup the resolver falls back to the last-known-good snapshot. Clients can read the live/stale state via the protolsp/registryStatus custom request, and a warning window/showMessage is sent at initialized time when the resolver loaded stale.

Design

Status

Pre-1.0. The LSP feature surface is stable; custom LSP method shapes (protolsp/sourceContent, protolsp/listMessages) may still evolve in 0.x. See CHANGELOG.md.

License

MIT

Directories

Path Synopsis
Package analysis is protolsp's transport-free analysis engine : the document store, schema lookup, workspace/chain/config state, and every analysis pass (parse + schema diagnostics, hover, completion, definition, code actions, secret ranges, dataset regions, effective config) — importable without jsonrpc2 or Connect-RPC.
Package analysis is protolsp's transport-free analysis engine : the document store, schema lookup, workspace/chain/config state, and every analysis pass (parse + schema diagnostics, hover, completion, definition, code actions, secret ranges, dataset regions, effective config) — importable without jsonrpc2 or Connect-RPC.
Package buftool wraps the external `buf` CLI for the proto-authoring phase 5 LSP features (lint; formatting moved to protocompile's printer).
Package buftool wraps the external `buf` CLI for the proto-authoring phase 5 LSP features (lint; formatting moved to protocompile's printer).
Package chain implements protolsp's edit-time view of a chameleon chain spec (C1 of the chameleon-integration design).
Package chain implements protolsp's edit-time view of a chameleon chain spec (C1 of the chameleon-integration design).
cmd
protolsp command
Command protolsp is the Language Server for .pxf (Proto eXpressive Format) files.
Command protolsp is the Language Server for .pxf (Proto eXpressive Format) files.
protolsp-ws command
Command protolsp-ws serves protolsp over WebSocket, the transport used by the hosted Monaco IDE.
Command protolsp-ws serves protolsp over WebSocket, the transport used by the hosted Monaco IDE.
internal
lspcodec
Package lspcodec encodes JSON-RPC payloads for the server's connections.
Package lspcodec encodes JSON-RPC payloads for the server's connections.
server
Package server implements protolsp's Language Server runtime — the piece that owns the document store, dispatches every JSON-RPC method the client sends, and runs the side-channel Connect-RPC sidecar pxfed uses for typed RPC access to the same state.
Package server implements protolsp's Language Server runtime — the piece that owns the document store, dispatches every JSON-RPC method the client sends, and runs the side-channel Connect-RPC sidecar pxfed uses for typed RPC access to the same state.
transport
Package transport hosts the LSP-over-{stdio,websocket} loops.
Package transport hosts the LSP-over-{stdio,websocket} loops.
Package positions converts between LSP positions and byte offsets in source bytes, in either of the position encodings the LSP spec allows: UTF-8 (LSP 3.17+) or UTF-16 (the pre-3.17 default).
Package positions converts between LSP positions and byte offsets in source bytes, in either of the position encodings the LSP spec allows: UTF-8 (LSP 3.17+) or UTF-16 (the pre-3.17 default).
Package proto exposes the on-disk .proto sources of protolsp's own descriptors as an embed.FS.
Package proto exposes the on-disk .proto sources of protolsp's own descriptors as an embed.FS.
pxf
Package pxfpb is an alias of github.com/trendvidia/protos/pxf, which owns the generated code for pxf/annotations.proto.
Package pxfpb is an alias of github.com/trendvidia/protos/pxf, which owns the generated code for pxf/annotations.proto.
Package protoast wraps trendvidia/protocompile's parser for the LSP features that retain a per-document AST (hover, definition, completion, cross-file navigation, protocheck / protovalidate schema walks).
Package protoast wraps trendvidia/protocompile's parser for the LSP features that retain a per-document AST (hover, definition, completion, cross-file navigation, protocheck / protovalidate schema walks).
Package redact holds the helpers that prevent secret bytes from leaking through LSP wire payloads and server logs.
Package redact holds the helpers that prevent secret bytes from leaking through LSP wire payloads and server logs.
Package schema exposes the message-descriptor lookup protolsp uses to answer every schema-aware question (hover, go-to-definition, completion, validation).
Package schema exposes the message-descriptor lookup protolsp uses to answer every schema-aware question (hover, go-to-definition, completion, validation).
Package workspaceconfig owns the .protolsp.pxf file as both a Tier 2 configuration source and an editable settings store.
Package workspaceconfig owns the .protolsp.pxf file as both a Tier 2 configuration source and an editable settings store.

Jump to

Keyboard shortcuts

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