languageservice

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package languageservice provides editor-independent analysis used by the REPL and future browser and language-server adapters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildContexts added in v0.2.26

func BuildContexts(programs []*ir.Program) map[string]Context

BuildContexts indexes project-wide type metadata once, then derives the declarations visible from each module through its explicit imports.

Types

type CallInfo

type CallInfo struct {
	ParameterCount        int
	ExplicitTypeArguments bool
	TypeParameters        []string
	Parameters            []CallParameter
	// BlockParameters retains compiler-known block binding types for editor
	// queries. Ordinary source callbacks do not need this metadata; structured
	// package operations such as File.open use it to type their scoped binding.
	BlockParameters []types.Type
	Alternatives    []CallSignature
}

CallInfo records structured call syntax without making adapters parse the human-readable signature in Detail.

type CallParameter added in v0.2.0

type CallParameter struct {
	Name                 string
	Label                string
	NamedOnly            bool
	Keyword              bool
	Optional             bool
	Definition           *DefinitionLocation
	ReferenceScopes      []ReferenceScope
	LiteralValues        []string
	LiteralArrays        [][]string
	LiteralArrayElements []string
}

type CallSignature added in v0.2.0

type CallSignature struct {
	Parameters []CallParameter
}

type CompletionItem

type CompletionItem struct {
	Label           string
	InsertText      string
	Kind            CompletionKind
	Detail          string
	Replacement     OffsetRange
	AdditionalEdits []TextEdit
}

CompletionItem separates the displayed label from the exact source text that replaces Replacement.

func Complete

func Complete(request CompletionRequest) []CompletionItem

type CompletionKind

type CompletionKind string
const (
	CompletionKeyword    CompletionKind = "keyword"
	CompletionVariable   CompletionKind = "variable"
	CompletionParameter  CompletionKind = "parameter"
	CompletionConstant   CompletionKind = "constant"
	CompletionFunction   CompletionKind = "function"
	CompletionMethod     CompletionKind = "method"
	CompletionField      CompletionKind = "field"
	CompletionType       CompletionKind = "type"
	CompletionEnumMember CompletionKind = "enum_member"
	CompletionModule     CompletionKind = "module"
	CompletionValue      CompletionKind = "value"
	CompletionCommand    CompletionKind = "command"
)

type CompletionRequest

type CompletionRequest struct {
	Source     string
	Cursor     int
	Mode       string
	Context    Context
	Candidates Context
	// RepairImports lets candidates replace checked symbols that are no longer
	// declared or imported by the current editor source. LSP adapters use this
	// while retaining a last-good checked context across invalid edits.
	RepairImports bool
}

type Context

type Context struct {
	Symbols         []Symbol
	TypeMembers     map[string][]Symbol
	Types           map[string]TypeInfo
	Implementations map[SymbolID][]DefinitionLocation
	// ModulePaths maps an authored import path to its resolved source filename.
	ModulePaths map[string]string
}

Context is the checked project information available at a cursor position. REPL contexts are rebuilt from typed IR after every accepted submission.

func BuildContext

func BuildContext(programs []*ir.Program, modulePath string) Context

BuildContext indexes only declarations visible from modulePath. Other project modules contribute names through explicit imports.

func BuildImportCandidates added in v0.2.9

func BuildImportCandidates(programs []*ir.Program, modulePath string) Context

BuildImportCandidates indexes declarations from other project modules. A name is offered only when its import path is unambiguous.

func MergeContexts added in v0.2.9

func MergeContexts(current, candidates Context) Context

MergeContexts adds completion-only declarations without overriding symbols already visible in checked source.

func MergeImportCandidateSets added in v0.2.9

func MergeImportCandidateSets(contexts ...Context) Context

MergeImportCandidateSets keeps only names with one possible source package. Editors must not silently choose between a project and standard declaration.

func MergeImportCandidates added in v0.2.9

func MergeImportCandidates(current, candidates Context, source string) Context

MergeImportCandidates replaces symbols retained from a stale checked snapshot when the current source no longer declares or imports that name. This lets completion repair a missing import without weakening diagnostics.

func StandardImportCandidates added in v0.2.9

func StandardImportCandidates(mode string) Context

StandardImportCandidates returns public portable declarations that can be made visible by inserting one explicit import. Duplicate top-level names are omitted, while package roots retain their qualified member completion.

type DefinitionInfo added in v0.2.5

type DefinitionInfo struct {
	ID     SymbolID
	Name   string
	Path   string
	Range  OffsetRange
	Origin *OffsetRange
}

func Definition added in v0.2.5

func Definition(request SemanticRequest) (DefinitionInfo, bool)

Definition resolves project declarations, imported declarations, receiver members, and common lexical bindings to their TypeRB source location.

func Implementations added in v0.2.26

func Implementations(request SemanticRequest) ([]DefinitionInfo, bool)

Implementations resolves an interface type or method to the concrete class declarations that explicitly implement it.

type DefinitionLocation added in v0.2.5

type DefinitionLocation struct {
	ID    SymbolID
	Name  string
	Path  string
	Range OffsetRange
}

type DocumentSymbol added in v0.2.6

type DocumentSymbol struct {
	Name           string
	Detail         string
	Kind           DocumentSymbolKind
	Range          OffsetRange
	SelectionRange OffsetRange
	Children       []DocumentSymbol
}

DocumentSymbol describes one declaration in a source file without exposing an editor protocol. Range covers the declaration and SelectionRange covers the authored name.

func DocumentSymbols added in v0.2.6

func DocumentSymbols(source string) []DocumentSymbol

DocumentSymbols returns the structural outline available from a single source file. It intentionally uses the lossless syntax tree so an editor can keep showing an outline while the project has type errors.

type DocumentSymbolKind added in v0.2.6

type DocumentSymbolKind string
const (
	DocumentSymbolModule     DocumentSymbolKind = "module"
	DocumentSymbolClass      DocumentSymbolKind = "class"
	DocumentSymbolMethod     DocumentSymbolKind = "method"
	DocumentSymbolField      DocumentSymbolKind = "field"
	DocumentSymbolEnum       DocumentSymbolKind = "enum"
	DocumentSymbolInterface  DocumentSymbolKind = "interface"
	DocumentSymbolFunction   DocumentSymbolKind = "function"
	DocumentSymbolVariable   DocumentSymbolKind = "variable"
	DocumentSymbolConstant   DocumentSymbolKind = "constant"
	DocumentSymbolEnumMember DocumentSymbolKind = "enum_member"
	DocumentSymbolRecord     DocumentSymbolKind = "record"
	DocumentSymbolType       DocumentSymbolKind = "type"
)

type FoldingRange added in v0.2.6

type FoldingRange struct {
	Range OffsetRange
}

FoldingRange identifies one structural source region without exposing an editor protocol. The LSP adapter translates byte offsets to UTF-16 positions.

func FoldingRanges added in v0.2.6

func FoldingRanges(source string) []FoldingRange

FoldingRanges returns structural regions from the lossless syntax tree. It remains available while a document has parse or type errors.

type HighlightKind

type HighlightKind string
const (
	HighlightKeyword  HighlightKind = "keyword"
	HighlightType     HighlightKind = "type"
	HighlightConstant HighlightKind = "constant"
	HighlightString   HighlightKind = "string"
	HighlightNumber   HighlightKind = "number"
	HighlightBoolean  HighlightKind = "boolean"
	HighlightComment  HighlightKind = "comment"
	HighlightFunction HighlightKind = "function"
	HighlightMethod   HighlightKind = "method"
	HighlightInvalid  HighlightKind = "invalid"
)

type HighlightRequest

type HighlightRequest struct {
	Source  string
	Mode    string
	Context Context
}

type HighlightSpan

type HighlightSpan struct {
	Range OffsetRange
	Kind  HighlightKind
}

func Highlight

func Highlight(request HighlightRequest) []HighlightSpan

Highlight classifies source without adding terminal or browser formatting. Lexical diagnostics override ordinary token classifications.

type HoverInfo added in v0.2.5

type HoverInfo struct {
	Range  OffsetRange
	Detail string
}

func Hover added in v0.2.5

func Hover(request SemanticRequest) (HoverInfo, bool)

Hover resolves the checked symbol at a source position without exposing any editor-protocol representation to the compiler service.

type Import added in v0.2.9

type Import struct {
	Path string
	// ModulePath remains the canonical declaration owner when Path is shortened
	// for insertion into source.
	ModulePath string
	Symbol     string
}

Import identifies the explicit source import required by a completion.

type OffsetRange

type OffsetRange struct {
	Start int
	End   int
}

OffsetRange is a half-open UTF-8 byte range. Protocol adapters may convert it to their own position representation without changing completion logic.

type ProjectImportCandidates added in v0.2.30

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

ProjectImportCandidates is an immutable project-wide index of declaration import origins. Ambiguity is resolved after excluding the requesting module.

func BuildProjectImportCandidates added in v0.2.30

func BuildProjectImportCandidates(programs []*ir.Program) ProjectImportCandidates

BuildProjectImportCandidates indexes declaration origins once for a complete project. Call ForModule to omit declarations owned by the module requesting completion and resolve the remaining names.

func (ProjectImportCandidates) ForModule added in v0.2.30

func (c ProjectImportCandidates) ForModule(modulePath string) Context

ForModule returns names with exactly one origin after declarations from modulePath have been excluded.

type ReferenceInfo added in v0.2.5

type ReferenceInfo struct {
	ID          SymbolID
	Path        string
	Range       OffsetRange
	Declaration bool
}

func References added in v0.2.5

func References(request SemanticRequest, documents []SemanticDocument, includeDeclaration bool) ([]ReferenceInfo, bool)

References resolves only occurrences that bind to the same checked source declaration. Textually equal names owned by another type or lexical binding are intentionally excluded.

type ReferenceScope added in v0.2.28

type ReferenceScope struct {
	Owner   string
	Range   OffsetRange
	Symbols []Symbol
}

ReferenceScope makes provider-owned project declarations visible only in a declarative call argument owned by one source declaration.

type RunnableDeclaration added in v0.2.7

type RunnableDeclaration struct {
	Kind  RunnableDeclarationKind
	Range OffsetRange
}

RunnableDeclaration identifies a source declaration that an editor can run. Range covers the authored declaration name rather than its complete body.

func RunnableDeclarations added in v0.2.7

func RunnableDeclarations(source string) []RunnableDeclaration

RunnableDeclarations returns executable declarations from the lossless syntax tree. It remains available while unrelated project code has errors.

type RunnableDeclarationKind added in v0.2.7

type RunnableDeclarationKind string
const RunnableDeclarationMain RunnableDeclarationKind = "main"

type SelectionRange added in v0.2.6

type SelectionRange struct {
	Range  OffsetRange
	Parent *SelectionRange
}

SelectionRange describes one source selection and the next enclosing selection. It is editor-independent and uses UTF-8 byte offsets.

func SelectionRanges added in v0.2.6

func SelectionRanges(source string, cursors []int) []SelectionRange

SelectionRanges builds token, line, and structural selection chains for the requested source offsets. It uses syntax ranges so it remains available for incomplete or type-invalid documents.

type SemanticDocument added in v0.2.5

type SemanticDocument struct {
	Path    string
	Source  string
	Mode    string
	Context Context
}

SemanticDocument supplies one checked project file to project-wide semantic queries without exposing compiler snapshots or editor protocol types.

type SemanticRequest added in v0.2.5

type SemanticRequest struct {
	Path    string
	Source  string
	Cursor  int
	Mode    string
	Context Context
}

SemanticRequest identifies a source position using the same checked context as completion while keeping editor protocol details outside this package.

type Service

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

Service owns a checked project snapshot while keeping terminal and browser presentation concerns outside the language analysis layer.

func New

func New(mode string) *Service

func (*Service) Complete

func (s *Service) Complete(source string, cursor int) []CompletionItem

func (*Service) Definition added in v0.2.5

func (s *Service) Definition(path, source string, cursor int) (DefinitionInfo, bool)

func (*Service) Highlight

func (s *Service) Highlight(source string) []HighlightSpan

func (*Service) Hover added in v0.2.5

func (s *Service) Hover(source string, cursor int) (HoverInfo, bool)

func (*Service) Implementations added in v0.2.26

func (s *Service) Implementations(path, source string, cursor int) ([]DefinitionInfo, bool)

func (*Service) SetCandidates added in v0.2.3

func (s *Service) SetCandidates(context Context)

SetCandidates adds declarations that tooling may offer before source has imported them. They participate in completion and highlighting only; the compiler remains responsible for activating the corresponding import.

func (*Service) Signatures added in v0.2.5

func (s *Service) Signatures(source string, cursor int) (SignatureHelp, bool)

func (*Service) Update

func (s *Service) Update(programs []*ir.Program, modulePath string)

type SignatureHelp added in v0.2.5

type SignatureHelp struct {
	Signatures      []SignatureInfo
	ActiveSignature int
	ActiveParameter int
}

func Signatures added in v0.2.5

func Signatures(request SemanticRequest) (SignatureHelp, bool)

Signatures resolves the innermost call and its active argument using the same structured call metadata that powers completion.

type SignatureInfo added in v0.2.5

type SignatureInfo struct {
	Label      string
	Parameters []SignatureParameter
}

type SignatureParameter added in v0.2.5

type SignatureParameter struct {
	Label string
}

type Symbol

type Symbol struct {
	Name       string
	Kind       CompletionKind
	Detail     string
	Type       types.Type
	Call       *CallInfo
	Members    []Symbol
	Definition *DefinitionLocation
	Import     *Import
}

Symbol is the UI-independent semantic shape consumed by completion.

type SymbolID added in v0.2.5

type SymbolID string

SymbolID is a project-stable identity derived from a source declaration. Protocol adapters use it indirectly through semantic queries; generated and built-in symbols intentionally have no identity or source location.

type TextEdit added in v0.2.9

type TextEdit struct {
	Range   OffsetRange
	NewText string
}

TextEdit is an editor-independent source change applied together with a completion. Protocol adapters translate byte offsets to their wire format.

type TypeInfo added in v0.2.26

type TypeInfo struct {
	TypeParameters []string
	AliasTarget    *types.Type
}

TypeInfo retains generic parameters and transparent alias targets needed to instantiate checked member types for editor queries. Nominal newtypes keep their explicit new/value members instead of forwarding representation APIs.

Jump to

Keyboard shortcuts

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