lsp

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 23 Imported by: 0

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.

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

View Source
const Version = "1.3.1"

Version is the server's reported version, surfaced via Initialize so clients can include it in trace logs.

Variables

This section is empty.

Functions

func Serve

func Serve(ctx context.Context, in io.Reader, out io.Writer) error

Serve runs the LSP loop on the supplied stdio streams. It blocks until the peer closes the connection or context is cancelled, and returns the terminating error (nil on a clean shutdown).

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server holds the server-side state. The zero value is not useful - call Serve which constructs and wires one for the duration of the session.

Jump to

Keyboard shortcuts

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