template

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenKeyword  = 0
	TokenVariable = 1
	TokenProperty = 2
	TokenFunction = 3
	TokenString   = 4
	TokenComment  = 5
	TokenOperator = 6
	TokenNumber   = 7
)

Token type indices (must match legend in server capabilities).

View Source
const (
	ModDeclaration    = 1 << 0 // 1
	ModDefaultLibrary = 1 << 1 // 2
)

Token modifier bitmask values.

Variables

This section is empty.

Functions

func ExtractSymbols

func ExtractSymbols(pt *ParsedTemplate) []lsp.DocumentSymbol

ExtractSymbols returns document symbols for define/block in the template.

Types

type ParsedTemplate

type ParsedTemplate struct {
	URI     string
	Content string
	Trees   map[string]*parse.Tree // template name -> parse tree
	Errors  []lsp.Diagnostic
	Lines   []int // byte offset of each line start
}

ParsedTemplate holds a parsed template and its source

func Parse

func Parse(uri, content string, extraFuncs ...string) *ParsedTemplate

Parse parses template content and returns a ParsedTemplate. Uses text/template/parse directly. extraFuncs are additional function names (e.g., from FuncMap) to register so the parser doesn't reject them as undefined.

func (*ParsedTemplate) NodeAtOffset

func (pt *ParsedTemplate) NodeAtOffset(offset int) (parse.Node, string)

NodeAtOffset finds the innermost node at the given byte offset. Returns the node and its tree name.

func (*ParsedTemplate) OffsetToPosition

func (pt *ParsedTemplate) OffsetToPosition(offset int) lsp.Position

OffsetToPosition converts a byte offset to an LSP Position.

func (*ParsedTemplate) PositionToOffset

func (pt *ParsedTemplate) PositionToOffset(pos lsp.Position) int

PositionToOffset converts an LSP Position to a byte offset.

func (*ParsedTemplate) ScopeAtOffset

func (pt *ParsedTemplate) ScopeAtOffset(offset int) []ScopeEntry

ScopeAtOffset returns the chain of range/with scopes enclosing the given offset.

type ScopeEntry

type ScopeEntry struct {
	Kind  string           // "range" or "with"
	Field *parse.FieldNode // the field being ranged/withed
	Vars  []string         // variable names declared in the pipe (e.g., "$i", "$v" from range)
}

ScopeChain represents the chain of range/with scopes enclosing a given offset. Each entry is a FieldNode from the pipe of a range/with, outermost first.

type SemanticToken

type SemanticToken struct {
	Line      uint32
	StartChar uint32
	Length    uint32
	Type      uint32 // index into token types legend
	Modifiers uint32
}

SemanticToken represents a single semantic token for highlighting.

func ExtractSemanticTokens

func ExtractSemanticTokens(pt *ParsedTemplate, extraFuncs ...string) []SemanticToken

ExtractSemanticTokens walks the parse tree and extracts semantic tokens.

type TemplateIndex

type TemplateIndex struct {
	Definitions  map[string][]lsp.Location  // "name" -> define locations
	References   map[string][]lsp.Location  // "name" -> template call locations
	Trees        map[string]*ParsedTemplate // URI -> parsed template
	TemplateArgs map[string][]string        // "name" -> field chain passed via {{template "name" .Field}}
}

TemplateIndex maps template names to definition and reference locations.

func NewTemplateIndex

func NewTemplateIndex() *TemplateIndex

NewTemplateIndex creates a new empty TemplateIndex.

func (*TemplateIndex) Index

func (idx *TemplateIndex) Index(pt *ParsedTemplate)

Index indexes a parsed template, recording definitions and references.

Jump to

Keyboard shortcuts

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