lsp

package
v0.0.0-...-668df90 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package lsp implements the EDBML language server. It wraps the DBML front end (scanner, parser, check, vet) behind the Language Server Protocol: diagnostics, completion, hover, definition, references, rename and document symbols. One Document per open file holds the parse result, the semantic model and the symbol occurrence index.

Index

Constants

View Source
const Version = "0.1.0"

Version is stamped into the initialize response.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document struct {
	URI  string
	Text string

	File  *ast.File
	Info  *check.Info
	Diags []diag.Diagnostic
	Index *Index
	// contains filtered or unexported fields
}

Document is one open text document plus everything derived from it.

func NewDocument

func NewDocument(uri, text string) *Document

NewDocument analyzes text and returns a ready document.

func (*Document) Complete

func (d *Document) Complete(pos protocol.Position) []protocol.CompletionItem

Complete computes completion items for the position.

func (*Document) Definition

func (d *Document) Definition(pos protocol.Position) *protocol.Location

Definition returns the location of the declaration of the symbol at pos.

func (*Document) DocumentSymbols

func (d *Document) DocumentSymbols() []protocol.DocumentSymbol

DocumentSymbols builds the outline tree.

func (*Document) FromLSP

func (d *Document) FromLSP(pos protocol.Position) int

FromLSP converts an LSP position to a byte offset into d.Text.

func (*Document) Hover

func (d *Document) Hover(pos protocol.Position) *protocol.Hover

Hover renders documentation for the symbol at pos.

func (*Document) LSPDiagnostics

func (d *Document) LSPDiagnostics() []protocol.Diagnostic

LSPDiagnostics converts the front end's diagnostics for publishing.

func (*Document) RangeOf

func (d *Document) RangeOf(n ast.Node) protocol.Range

RangeOf converts a node's extent to an LSP range.

func (*Document) References

func (d *Document) References(pos protocol.Position, includeDecl bool) []protocol.Location

References returns every occurrence of the symbol at pos.

func (*Document) Rename

func (d *Document) Rename(pos protocol.Position, newName string) (*protocol.WorkspaceEdit, error)

Rename renames the symbol at pos. Only occurrences spelled like the ident under the cursor are rewritten: renaming a table by its name leaves alias usages alone, and renaming the alias leaves the table name alone.

func (*Document) ToLSP

func (d *Document) ToLSP(p token.Position) protocol.Position

ToLSP converts a front-end position to an LSP position.

func (*Document) Update

func (d *Document) Update(text string)

Update replaces the document text and re-runs the whole front end.

type Index

type Index struct {
	Occs []Occurrence

	Tables   map[string]*check.TableInfo // canonical key AND alias -> table
	Enums    map[string]*check.EnumInfo  // canonical key -> enum
	Partials map[string]*check.PartialInfo
	// contains filtered or unexported fields
}

Index is every symbol occurrence in a document, plus resolution maps.

func NewIndex

func NewIndex(f *ast.File, info *check.Info) *Index

NewIndex resolves every name in the file against the semantic model.

func (*Index) At

func (ix *Index) At(offset int) *Occurrence

At returns the occurrence whose identifier spans the byte offset.

func (*Index) Decl

func (ix *Index) Decl(id SymbolID) *ast.Ident

Decl returns the declaring identifier of a symbol, or nil.

func (*Index) OccurrencesOf

func (ix *Index) OccurrencesOf(id SymbolID) []Occurrence

OccurrencesOf returns all occurrences of a symbol.

type Occurrence

type Occurrence struct {
	ID     SymbolID
	Ident  *ast.Ident
	IsDecl bool
}

Occurrence is one identifier that denotes a symbol.

type Server

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

Server owns the open documents and the protocol handler.

func NewServer

func NewServer() *Server

NewServer wires up the LSP handler.

func (*Server) RunStdio

func (s *Server) RunStdio() error

RunStdio serves LSP over stdin/stdout until the client disconnects.

type SymKind

type SymKind int

SymKind classifies the symbols the server can navigate.

const (
	SymTable SymKind = iota
	SymEnum
	SymPartial
	SymColumn
	SymEnumValue
)

type SymbolID

type SymbolID struct {
	Kind      SymKind
	Container string
	Name      string
}

SymbolID names one symbol. Tables and enums use their canonical "schema.name" key; columns live in a container — "table:<key>" for direct definitions or "partial:<name>" for columns defined in a TablePartial, so every table sharing the partial shares the symbol (a rename edits the partial once). Enum values live in "enum:<key>".

Jump to

Keyboard shortcuts

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