analysis

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StdLibFunctions = map[string]*Function{}/* 112 elements not displayed */
View Source
var StdLibValue = func(fns map[string]*Function) *Value {
	res := &Value{
		Type:    ObjectType,
		Comment: []string{"The built-in jsonnet standard library"},
		Object: &Object{
			AllFieldsKnown: true,
			FieldMap:       map[string]*Field{},
		},
	}

	keys := []string{}
	for name := range fns {
		keys = append(keys, name)
	}
	sort.Strings(keys)
	for _, k := range keys {
		fn := fns[k]
		res.Object.Fields = append(res.Object.Fields, Field{
			Name:    k,
			Type:    FunctionType,
			Comment: []string{k + fn.String()},
		})
		res.Object.FieldMap[k] = &res.Object.Fields[len(res.Object.Fields)-1]
	}
	return res
}(StdLibFunctions)

Functions

func FmtNode

func FmtNode(n ast.Node) string

func FmtNodeIndent

func FmtNodeIndent(n ast.Node, level int) string

func LogAst

func LogAst(root ast.Node)

func LogNodeTrace

func LogNodeTrace(n ast.Node, indentLevel int)

func PrintAst added in v0.2.3

func PrintAst(root ast.Node, out io.Writer)

func SafeIdent

func SafeIdent(name string) string

func StackAtLoc

func StackAtLoc(root ast.Node, loc ast.Location) (res []ast.Node)

func StackAtNode

func StackAtNode(root ast.Node, find ast.Node) (found []ast.Node)

func WalkStack added in v0.1.2

func WalkStack(node ast.Node, fn func(n ast.Node, stack []ast.Node) bool)

WalkStack will walk the AST in depth first order, and keep track of the stack from the root of the AST. It will call callback function `fn` on every node it traverses. If `fn` returns false, it will not traverse to that nodes children.

Types

type Field

type Field struct {
	Name    string            `json:"name,omitempty"`
	Type    ValueType         `json:"type"`
	Range   ast.LocationRange `json:"-"`
	Comment []string          `json:"comment,omitempty"`
	Hidden  bool              `json:"hidden,omitempty"`
	Node    ast.Node          `json:"-"`
}

type Function

type Function struct {
	Comment    []string  `json:"comment,omitempty"`
	Params     []Param   `json:"params,omitempty"`
	Return     ast.Node  `json:"-"`
	ReturnType ValueType `json:"returnType"`
}

func (*Function) String

func (f *Function) String() string

type Object

type Object struct {
	Fields         []Field           `json:"fields"`
	FieldMap       map[string]*Field `json:"-"`
	AllFieldsKnown bool              `json:"allFieldsKnown"`
}

type Param

type Param struct {
	Name    string            `json:"name"`
	Comment []string          `json:"comment,omitempty"`
	Range   ast.LocationRange `json:"-"`
	Type    ValueType         `json:"type"`
	Default ast.Node          `json:"-"`
}

func (*Param) String

func (p *Param) String() string

type Resolver

type Resolver interface {
	// Gets the variable with name `name` the ast node `from`
	// We need from, as the available variables change depending
	// on where in the document the caller is
	Vars(from ast.Node) VarMap
	NodeAt(loc ast.Location) (node ast.Node, stack []ast.Node)
	Import(from, path string) ast.Node
}

type Value

type Value struct {
	Type    ValueType         `json:"type"`
	Range   ast.LocationRange `json:"-"`
	Comment []string          `json:"comment,omitempty"`
	Node    ast.Node          `json:"-"`

	StringValue *string

	Object   *Object   `json:"object,omitempty"`
	Function *Function `json:"function,omitempty"`
}

func NodeToValue

func NodeToValue(node ast.Node, resolver Resolver) (res *Value)

type ValueType

type ValueType int
const (
	AnyType      ValueType = 0
	FunctionType ValueType = 1
	ObjectType   ValueType = 2
	ArrayType    ValueType = 3
	BooleanType  ValueType = 4
	NumberType   ValueType = 5
	StringType   ValueType = 6
	NullType     ValueType = 7
)

func NewValueType added in v0.1.4

func NewValueType(v string) (ValueType, bool)

func (ValueType) String

func (v ValueType) String() string

type Var

type Var struct {
	Name string
	Loc  ast.LocationRange
	Node ast.Node
	Type ValueType
	// The position in the stack, used for sorting most
	// relevant autocomplete responses.
	StackPos int
}

type VarMap

type VarMap map[string]*Var

func StackVars

func StackVars(stk []ast.Node) VarMap

func UnwindLocals

func UnwindLocals(root ast.Node) (VarMap, ast.Node)

func (VarMap) Get

func (v VarMap) Get(name string) *Var

func (VarMap) Names

func (v VarMap) Names() []string

Jump to

Keyboard shortcuts

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