grammarlsp

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompletionContext

type CompletionContext struct {
	Line   int
	Column int
	Prefix string // text before cursor on current line
	Source []byte // full document source
}

CompletionContext provides context for completion requests.

type CompletionItem

type CompletionItem struct {
	Label      string
	Kind       int    // LSP CompletionItemKind: 14=keyword, 7=class, 3=function
	Detail     string // short description
	InsertText string // text to insert (can be snippet)
}

CompletionItem is a single completion suggestion.

type Config

type Config struct {
	GoplsPath  string      // path to gopls binary (default: "gopls")
	ShadowDir  string      // directory for shadow .go files
	Extensions []Extension // registered grammar extensions
	Logger     *log.Logger
}

Config configures the LSP proxy.

type Diagnostic

type Diagnostic struct {
	Line     int
	Column   int
	EndLine  int
	EndCol   int
	Message  string
	Severity int // 1=error, 2=warning, 3=info, 4=hint
}

Diagnostic is an additional diagnostic from the extension.

type Document

type Document struct {
	URI        string
	Source     string
	GoCode     string
	ShadowPath string
	Map        *SourceMap
	Version    int
	Extension  *Extension
}

type DocumentManager

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

func NewDocumentManager

func NewDocumentManager(shadowDir string, extensions []Extension) *DocumentManager

func (*DocumentManager) Close

func (dm *DocumentManager) Close(uri string)

func (*DocumentManager) ExtensionFor

func (dm *DocumentManager) ExtensionFor(uri string) *Extension

func (*DocumentManager) Get

func (dm *DocumentManager) Get(uri string) (*Document, bool)

func (*DocumentManager) IsManaged

func (dm *DocumentManager) IsManaged(uri string) bool

func (*DocumentManager) Open

func (dm *DocumentManager) Open(uri, source string) error

func (*DocumentManager) Update

func (dm *DocumentManager) Update(uri, source string) error

type Extension

type Extension struct {
	// Name identifies this extension (e.g., "danmuji", "dingo")
	Name string

	// FileExtension is the file extension this handles (e.g., ".dmj", ".dingo")
	FileExtension string

	// Transpile converts source in the custom language to valid Go code.
	// This is the only required function.
	Transpile func(source []byte) (string, error)

	// Completions returns completion items for the given context. Optional.
	Completions func(ctx CompletionContext) []CompletionItem

	// Hover returns hover documentation for the given context. Optional.
	Hover func(ctx HoverContext) string

	// Diagnostics returns additional diagnostics beyond what gopls provides. Optional.
	Diagnostics func(source []byte) []Diagnostic
}

Extension defines what a grammar extension provides to the LSP proxy. Implement this interface and register it with the proxy to get full IDE support for your grammar's file extension.

type HoverContext

type HoverContext struct {
	Line   int
	Column int
	Word   string // word under cursor
	Source []byte // full document source
}

HoverContext provides context for hover requests.

type Mapping

type Mapping struct {
	SrcLine, SrcCol int
	DstLine, DstCol int
}

Mapping links a source position to a destination position.

type Position

type Position struct {
	Line, Col int
}

Position is a 0-indexed line/column pair.

type Proxy

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

Proxy sits between the editor and gopls, intercepting DSL files.

func NewProxy

func NewProxy(config Config) *Proxy

func (*Proxy) Run

func (p *Proxy) Run(ctx context.Context, stdin io.ReadCloser, stdout io.WriteCloser) error

type SourceMap

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

SourceMap provides bidirectional position mapping between DSL source and generated Go code. Two sorted indices for O(log n) lookup.

func BuildFromDiff

func BuildFromDiff(srcLines, dstLines []string) *SourceMap

BuildFromDiff builds a source map by comparing source and destination line-by-line.

func NewSourceMap

func NewSourceMap() *SourceMap

func (*SourceMap) AddLineMapping

func (sm *SourceMap) AddLineMapping(srcLine, dstLine int)

func (*SourceMap) AddMapping

func (sm *SourceMap) AddMapping(m Mapping)

func (*SourceMap) Build

func (sm *SourceMap) Build()

func (*SourceMap) ToDst

func (sm *SourceMap) ToDst(pos Position) Position

func (*SourceMap) ToSrc

func (sm *SourceMap) ToSrc(pos Position) Position

Jump to

Keyboard shortcuts

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