template

package
v0.12.1-pre.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2023 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

Package template contains code for dealing with templates

Index

Constants

This section is empty.

Variables

View Source
var (
	Left  = []byte("{{")
	Right = []byte("}}")
)

Functions

func Definition

func Definition(snapshot source.Snapshot, fh source.FileHandle, loc protocol.Position) ([]protocol.Location, error)

Definition finds the definitions of the symbol at loc. It does not understand scoping (if any) in templates. This code is for definitions, type definitions, and implementations. Results only for variables and templates.

func Diagnose

func Diagnose(f source.FileHandle) []*source.Diagnostic

Diagnose returns parse errors. There is only one. The errors are not always helpful. For instance { {end}} will likely point to the end of the file.

func DocumentSymbols

func DocumentSymbols(snapshot source.Snapshot, fh source.FileHandle) ([]protocol.DocumentSymbol, error)

DocumentSymbols returns a hierarchy of the symbols defined in a template file. (The hierarchy is flat. SymbolInformation might be better.)

func Hover

func Hover(ctx context.Context, snapshot source.Snapshot, fh source.FileHandle, position protocol.Position) (*protocol.Hover, error)

func References

func References(ctx context.Context, snapshot source.Snapshot, fh source.FileHandle, params *protocol.ReferenceParams) ([]protocol.Location, error)

func SemanticTokens

func SemanticTokens(ctx context.Context, snapshot source.Snapshot, spn span.URI, add func(line, start, len uint32), d func() []uint32) (*protocol.SemanticTokens, error)

Types

type All

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

All contains the Parse of all the template files

func New

func New(tmpls map[span.URI]source.FileHandle) *All

New returns the Parses of the snapshot's tmpl files (maybe cache these, but then avoiding import cycles needs code rearrangements)

type Parsed

type Parsed struct {
	ParseErr error
	// contains filtered or unexported fields
}

func (*Parsed) FindLiteralBefore

func (p *Parsed) FindLiteralBefore(pos int) (int, int)

FindLiteralBefore locates the first preceding string literal returning its position and length in buf or returns -1 if there is none. Assume double-quoted string rather than backquoted string for now.

func (*Parsed) FromPosition

func (p *Parsed) FromPosition(x protocol.Position) int

FromPosition translates a protocol.Position into an offset into the template

func (*Parsed) LineCol

func (p *Parsed) LineCol(x int) (uint32, uint32)

LineCol converts from a 0-based byte offset to 0-based line, col. col in runes

func (*Parsed) Position

func (p *Parsed) Position(pos int) protocol.Position

Position produces a protocol.Position from an offset in the template

func (*Parsed) Range

func (p *Parsed) Range(x, length int) protocol.Range

func (*Parsed) RuneCount

func (p *Parsed) RuneCount(l, s, e uint32) uint32

RuneCount counts runes in line l, from col s to e (e==0 for end of line. called only for multiline tokens)

func (*Parsed) SymsAtPos

func (p *Parsed) SymsAtPos(pos int) []symbol

func (*Parsed) TokenSize

func (p *Parsed) TokenSize(t Token) (int, error)

func (*Parsed) Tokens

func (p *Parsed) Tokens() []Token

func (*Parsed) WriteNode

func (p *Parsed) WriteNode(w io.Writer, n parse.Node)

WriteNode is for debugging

type Token

type Token struct {
	Start, End int // offset from start of template
	Multiline  bool
}

Token is a single {{...}}. More precisely, Left...Right

Jump to

Keyboard shortcuts

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