lsp

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package lsp consumes LLO's typed event-log artifacts (.bindings.capnp, future .ast.capnp / .source.capnp) sitting next to a SQLite .db.

The capnp event log is the canonical Σ data plane (per ley-line-open/rs/ll-core/schema-capnp/README.md, T8 thread). The SQLite tables (`_lsp_refs`, `_lsp_defs`, `_ast`) are local projections of the same records. Consuming the log directly avoids the leaf-vs-call-expression ambiguity that broke Falsifiability B at the SQL boundary — the capnp record carries BOTH `constructNodeId` and `refSiteNodeId`, so each consumer picks its own AST level without rebuilding the walk-up at query time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IterateBindingLog

func IterateBindingLog(path string, fn func(Binding) error) error

IterateBindingLog streams records to fn one at a time without buffering the full set. Use when memory pressure matters or when the consumer can short-circuit (e.g. early-exit on first match). Returning a non-nil error from fn aborts iteration; the error is propagated up wrapped with the record index for diagnostics.

Decode and projection errors are wrapped with both the record index AND the file path so streaming callers can identify which log failed when they're consuming several. Callback (fn) errors are wrapped with the record index only — the caller already knows what they passed in, but they don't necessarily know the record number where they aborted.

func SiblingBindingLogPath

func SiblingBindingLogPath(dbPath string) string

SiblingBindingLogPath returns the path to the binding event log that LLO writes alongside a `.db`. Mirrors LLO's `Path::with_extension` semantics from cmd_lsp.rs and daemon/lsp_pass.rs: the trailing extension on dbPath (typically `.db`) is REPLACED with `bindings.capnp`. Pins the convention on the consumer side so a typo can't silently drift from the producer.

Examples:

"/tmp/foo.db"       → "/tmp/foo.bindings.capnp"
"/tmp/no-ext"       → "/tmp/no-ext.bindings.capnp"
"/tmp/multi.dot.db" → "/tmp/multi.dot.bindings.capnp"

Types

type Binding

type Binding struct {
	// TargetNodeID is the symbol's defining node — what the LSP
	// resolved to. Same as `_lsp_refs.node_id` in the SQL projection.
	TargetNodeID string

	// RefToken is the textual lemma at the ref site (e.g. "Validate").
	RefToken string

	// ConstructNodeID is the smallest enclosing function/method/
	// constructor declaration. What `find_callers` MCP wants and
	// what `node_refs.node_id` records (after construct-level
	// normalization). Empty when the ref site has no enclosing
	// construct in `_ast`.
	ConstructNodeID string

	// RefSiteNodeID is the smallest enclosing AST node at the ref
	// location — typically a leaf identifier. Most precise locator
	// but can sit several levels below ConstructNodeID. Empty under
	// the same missing-_ast conditions as ConstructNodeID.
	RefSiteNodeID string

	// RefURI is the file URI the ref appears in (canonicalized;
	// matches `_source.path` post-be6136). `file://` scheme.
	RefURI string

	// RefRange locates the reference site for byte-precise tooling.
	RefRange Range

	// ParseGen is the parse generation that emitted this record.
	// T8.5 will replace this with a content hash linked into Σ root.
	ParseGen uint64

	// Qualifier is the LHS of the selector_expression containing the
	// ref site. In `pkg.Method`, qualifier is `pkg`; in `obj.method`,
	// `obj`; for a bare-identifier call (`Foo()`) qualifier is empty.
	// Distinguishes structurally equivalent shapes (qualified vs
	// unqualified) without consumer-side AST re-walks. Source for the
	// qualifier-aware fan_out_skew metric (mache-6c0d07).
	//
	// Empty when the producer didn't see a selector_expression
	// upstream of the ref site OR when this record came from a
	// pre-T8.7 .bindings.capnp log.
	Qualifier string
}

Binding is the Go-native projection of one bindings.BindingRecord. Decoupling consumers from the generated capnp types means swapping the underlying schema (e.g. when LLO ships T8.5's parseGen → Hash reframe) is a one-file change here, not a fan-out across the rule engine.

func ReadBindingLog

func ReadBindingLog(path string) ([]Binding, error)

ReadBindingLog opens a `.bindings.capnp` event log and returns every record in stream order. Returns (nil, nil) for an empty file — that is a valid LLO output when the LSP pass found no references.

Returns an os.ErrNotExist-wrapping error when the file is absent so callers can distinguish "no log produced yet" from "log corrupt".

Reads everything into memory. Mache-scale event logs are ≪100 MB even for large repos (323K NVD records map to <30K LSP refs in practice; idiomatic Go projects are smaller still). If a real workload pushes past that, switch to IterateBindingLog.

type Range

type Range struct {
	StartLine, StartColumn uint32
	StartByte              uint64
	EndLine, EndColumn     uint32
	EndByte                uint64
}

Range is the Go-native projection of common.Range — inclusive-start, exclusive-end, matching tree-sitter's convention.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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