Documentation
¶
Overview ¶
Decorator-arg/name LSP completions: dispatcher, context detection, error categories.
Import path + package-decl LSP completions.
Token-level helpers: duration/size unit completions + keyword list + extend-service context.
Type/decl LSP completions: project-wide decls + service/middleware/security/enum-value lookups.
Cursor-context classification for completion / hover: the primitive category of the field or scalar at the cursor, and declaration summaries / docs for hover rendering.
Project loading: the design root a buffer belongs to, walked once per request, every design file parsed once, and the semantic project built from them. Every handler that looks past the current buffer reads this view, so diagnostics, navigation and completion see the same project.
Package lsp implements the CraftGo Language Server Protocol surface.
The server speaks LSP over stdio (a jsonrpc2.Stream wrapped around the caller's io.Reader / io.Writer) and forwards each open document through the existing parser + semantic analyser. Diagnostics published by the server are exactly the diagnostics the CLI would emit for the same source, so editor and CLI behaviour stay aligned by construction.
Currently supported:
- initialize / initialized / shutdown / exit lifecycle
- textDocument/didOpen / didChange / didSave / didClose
- textDocument/publishDiagnostics on every successful parse pass
- textDocument/hover (decorator, type ref, builtin docs)
- textDocument/completion (decorators, types, fields)
- textDocument/definition (cross-file decl resolution)
- textDocument/references (find all uses)
- textDocument/documentSymbol (outline)
- textDocument/formatting (canonical re-print via internal/format)
- textDocument/rename (declarations + every reference)
Any other request returns jsonrpc2.ErrMethodNotFound, which clients treat as "feature unsupported".
UTF-16 ↔ internal position conversion. The LSP protocol measures Position.Character in UTF-16 code units, whereas craftgo's lexer counts runes (Position.Column) and bytes (Position.Offset). A character in the Basic Multilingual Plane (<= U+FFFF) is one UTF-16 unit; a supplementary character (emoji, rare CJK, ...) is a surrogate PAIR - two units. Every crossing between an editor position and an internal position therefore has to go through these helpers, or columns drift on any line that carries multi-byte UTF-8 (byte ≠ rune) or supplementary runes (rune ≠ UTF-16).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Version = "1.7.0"
Version is the server's reported version, surfaced via Initialize so clients can include it in trace logs. The source value is the fallback for `go install`; release builds inject the git tag via `-ldflags="-X ...internal/lsp.Version=<tag>"` (see .goreleaser.yaml), so it must be a var - `-X` cannot write a const.