astcontext

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: BSD-3-Clause Imports: 8 Imported by: 3

Documentation

Overview

Package astcontext provides context aware utilities to be used within editors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	StartLine int `json:"startLine" vim:"startLine"`
	StartCol  int `json:"startCol" vim:"startCol"`
	EndLine   int `json:"endLine" vim:"endLine"`
	EndCol    int `json:"endCol" vim:"endCol"`
}

Comment specified the result of the "comment" mode.

type Decl

type Decl struct {
	Keyword  string `json:"keyword" vim:"keyword"`
	Ident    string `json:"ident" vim:"ident"`
	Full     string `json:"full" vim:"full"`
	Filename string `json:"filename" vim:"filename"`
	Line     int    `json:"line" vim:"line"`
	Col      int    `json:"col" vim:"col"`
}

Decl specifies the result of the "decls" mode

type Func

type Func struct {
	// Signature of the function
	Signature *FuncSignature `json:"sig" vim:"sig"`

	// position of the "func" keyword
	FuncPos *Position `json:"func" vim:"func"`
	Lbrace  *Position `json:"lbrace" vim:"lbrace"` // position of "{"
	Rbrace  *Position `json:"rbrace" vim:"rbrace"` // position of "}"

	// position of the doc comment, only for *ast.FuncDecl
	Doc *Position `json:"doc,omitempty" vim:"doc,omitempty"`
	// contains filtered or unexported fields
}

Func represents a declared (*ast.FuncDecl) or an anonymous (*ast.FuncLit) Go function

func (*Func) IsDeclaration

func (f *Func) IsDeclaration() bool

IsDeclaration returns true if the given function is a function declaration (*ast.FuncDecl)

func (*Func) IsLiteral

func (f *Func) IsLiteral() bool

IsLiteral returns true if the given function is a function literal (*ast.FuncLit)

func (*Func) String

func (f *Func) String() string

type FuncSignature

type FuncSignature struct {
	// Full signature representation
	Full string `json:"full" vim:"full"`

	// Receiver representation. Empty for non methods.
	Recv string `json:"recv" vim:"recv"`

	// Name of the function. Empty for function literals.
	Name string `json:"name" vim:"name"`

	// Input arguments of the function, if present
	In string `json:"in" vim:"in"`

	// Output argument of the function, if present
	Out string `json:"out" vim:"out"`
}

FuncSignature defines the function signature

func NewFuncSignature

func NewFuncSignature(node ast.Node) *FuncSignature

NewFuncSignature returns a function signature from the given node. Node should be of type *ast.FuncDecl or *ast.FuncLit

func (*FuncSignature) String

func (s *FuncSignature) String() string

type Funcs

type Funcs []*Func

Funcs represents a list of functions

func (Funcs) Declarations

func (f Funcs) Declarations() Funcs

Declarations returns a copy of funcs with only Function declarations

func (Funcs) EnclosingFunc

func (f Funcs) EnclosingFunc(offset int) (*Func, error)

EnclosingFunc returns the enclosing *Func for the given offset

func (Funcs) Len

func (f Funcs) Len() int

func (Funcs) Less

func (f Funcs) Less(i, j int) bool

func (Funcs) NextFunc

func (f Funcs) NextFunc(offset int) (*Func, error)

NextFunc returns the nearest next Func for the given offset.

func (Funcs) NextFuncShift

func (f Funcs) NextFuncShift(offset, shift int) (*Func, error)

NextFuncShift returns the nearest next Func for the given offset. Shift shifts the index before returning. This is useful to get the second nearest next function (shift being 1), third nearest next function (shift being 2), etc...

func (Funcs) PrevFunc

func (f Funcs) PrevFunc(offset int) (*Func, error)

PrevFunc returns the nearest previous *Func for the given offset.

func (Funcs) PrevFuncShift

func (f Funcs) PrevFuncShift(offset, shift int) (*Func, error)

PrevFuncShift returns the nearest previous Func for the given offset. Shift shifts the index before returning. This is useful to get the second nearest previous function (shift being 1), third nearest previous function (shift being 2), etc...

func (Funcs) Reserve

func (f Funcs) Reserve()

Reserve reserves the Function data

func (Funcs) Swap

func (f Funcs) Swap(i, j int)

type Parser

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

Parser defines the customized parser

func NewParser

func NewParser(opts *ParserOptions) (*Parser, error)

NewParser creates a new Parser reference from the given options

func (*Parser) Funcs

func (p *Parser) Funcs() Funcs

Funcs returns a list of Func's from the parsed source. Func's are sorted according to the order of Go functions in the given source.

func (*Parser) Run

func (p *Parser) Run(query *Query) (*Result, error)

Run runs the given query and returns the result

func (*Parser) Types

func (p *Parser) Types() Types

Types returns a list of Type's from the parsed source. Type's are sorted according to the order of Go type declaration in the given source.

type ParserOptions

type ParserOptions struct {
	// File defines the filename to be parsed
	File string

	// Dir defines the directory to be parsed
	Dir string

	// Src defines the source to be parsed
	Src []byte

	// If enabled parses the comments too
	Comments bool
}

ParserOptions defines the options that changes the Parser's behavior

type Position

type Position struct {
	Filename string `json:"filename" vim:"filename"`
	Offset   int    `json:"offset" vim:"offset"` // offset, starting at 0
	Line     int    `json:"line" vim:"line"`     // line number, starting at 1
	Column   int    `json:"col" vim:"col"`       // column number, starting at 1 (byte count)
}

Position describes a function position

func ToPosition

func ToPosition(pos token.Position) *Position

ToPosition returns a Position from the given token.Position

func (Position) IsValid

func (pos Position) IsValid() bool

IsValid returns true if position is valid

type Query

type Query struct {
	Mode     string
	Offset   int
	Shift    int
	Includes []string
}

Query specifies a single query to the parser

type Result

type Result struct {
	Mode string `json:"mode" vim:"mode"`

	Comment Comment `json:"comment,omitempty" vim:"comment,omitempty"`
	Decls   []Decl  `json:"decls,omitempty" vim:"decls,omitempty"`
	Func    *Func   `json:"func,omitempty" vim:"fn,omitempty"`
}

Result is the common result of any motion query. It contains a query-specific result element.

type Type

type Type struct {
	// Signature is the simplified representation of the Type declaration
	Signature *TypeSignature `json:"sig" vim:"sig"`

	// position of the TypeSpec's ident
	TypePos *Position `json:"type" vim:"type"`

	// position of the doc comment
	Doc *Position `json:"doc,omitempty" vim:"doc,omitempty"`
	// contains filtered or unexported fields
}

Type represents a type declaration

type TypeSignature

type TypeSignature struct {
	// Full signature representation
	Full string `json:"full" vim:"full"`

	// Name of the type declaration
	Name string `json:"name" vim:"name"`

	// Type is the representation of the type of a TypeSpec. Ie.: type MyInt
	// int. Type is here: "int".
	Type string `json:"type" vim:"type"`
}

TypeSignature represents a type declaration signature

func NewTypeSignature

func NewTypeSignature(node *ast.TypeSpec) *TypeSignature

NewTypeSignature returns a TypeSignature from the given typespec node

type Types

type Types []*Type

Types represents a list of type declarations

func (Types) TopLevel

func (t Types) TopLevel() Types

TopLevel returns a copy of Types with only top level type declarations

Jump to

Keyboard shortcuts

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