lsp

package
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package lsp bridges CalcMark's spec/impl/format layers to the Language Server Protocol. Dependencies flow inward: lsp → spec, lsp → impl, lsp → format. No package should ever import lsp.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SemanticTokensLegend added in v1.8.13

func SemanticTokensLegend() protocol.SemanticTokensLegend

SemanticTokensLegend returns the legend to register during initialize.

func ToLSPPosition

func ToLSPPosition(pos ast.Position) protocol.Position

ToLSPPosition converts a CalcMark 1-indexed position to a 0-indexed LSP position.

func ToLSPRange

func ToLSPRange(r *ast.Range) protocol.Range

ToLSPRange converts a CalcMark Range to an LSP Range.

Types

type CursorContext added in v1.13.0

type CursorContext struct {
	InRegion bool
	Position CursorPosition
	Key      string // name of the key the cursor relates to ("" when unknown)
}

CursorContext is the result of classifying a cursor against a region.

func ClassifyCursor added in v1.13.0

func ClassifyCursor(region FrontmatterRegion, position protocol.Position) CursorContext

ClassifyCursor determines where the cursor at position sits relative to the region: outside, on a fence, on a key, or in a value (including indented continuations of the most recent top-level key).

Edge case: if the cursor sits exactly on the `:` separator column, it is classified as "key" — the user has not yet stepped into the value.

Complexity: O(EndLine) worst case when scanning back for a parent key; for well-formed frontmatter this is bounded by the region size.

type CursorPosition added in v1.13.0

type CursorPosition string

CursorPosition classifies where in the frontmatter region a cursor sits. String-typed for diagnostic readability per D1 (pragmatism).

const (
	CursorOutside CursorPosition = "outside"
	CursorFence   CursorPosition = "fence"
	CursorKey     CursorPosition = "key"
	CursorValue   CursorPosition = "value"
)

type DocumentRenderedParams added in v1.8.14

type DocumentRenderedParams struct {
	URI  string `json:"uri"`
	HTML string `json:"html"`
}

DocumentRenderedParams is the payload for the calcmark/documentRendered notification.

type DocumentSnapshot

type DocumentSnapshot struct {
	Source      string
	Document    *specDoc.Document
	Evaluator   *implDoc.Evaluator
	Diagnostics []specDoc.Diagnostic
	HTML        string
}

DocumentSnapshot holds the immutable evaluation results for a document. Request handlers read from the latest snapshot without locks.

type FrontmatterRegion added in v1.13.0

type FrontmatterRegion struct {
	StartLine int            // line of opening `---`
	EndLine   int            // line of closing `---`
	KeyLines  map[int]string // line index → top-level key name
	// contains filtered or unexported fields
}

FrontmatterRegion describes the YAML frontmatter region delimited by `---` fences at the top of a CalcMark source. Lines are 0-based to match LSP.

func DetectRegion added in v1.13.0

func DetectRegion(source string) (FrontmatterRegion, bool)

DetectRegion finds the YAML frontmatter region in source. It is mid-edit robust: it does NOT parse YAML — it only locates the fences and extracts top-level key names from `key:` patterns. Returns ok=false when the source does not begin with a `---\n` fence or when no closing fence is present.

Complexity: O(n) over the bytes up to (and including) the closing fence.

type Server

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

Server is the CalcMark LSP server.

func NewServer

func NewServer() *Server

NewServer creates a new CalcMark LSP server.

func (*Server) RunStdio

func (s *Server) RunStdio() error

RunStdio starts the LSP server over stdio.

func (*Server) ServeWebSocket added in v1.12.1

func (s *Server) ServeWebSocket(conn *websocket.Conn)

ServeWebSocket serves the LSP protocol over an existing WebSocket connection. This blocks until the connection is closed. Intended for embedding the LSP inside an HTTP server that handles the WebSocket upgrade externally.

Jump to

Keyboard shortcuts

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