Documentation ¶
Overview ¶
Package astcontext provides context aware utilities to be used within editors.
Index ¶
- type Comment
- type Decl
- type Func
- type FuncSignature
- type Funcs
- func (f Funcs) Declarations() Funcs
- func (f Funcs) EnclosingFunc(offset int) (*Func, error)
- func (f Funcs) Len() int
- func (f Funcs) Less(i, j int) bool
- func (f Funcs) NextFunc(offset int) (*Func, error)
- func (f Funcs) NextFuncShift(offset, shift int) (*Func, error)
- func (f Funcs) PrevFunc(offset int) (*Func, error)
- func (f Funcs) PrevFuncShift(offset, shift int) (*Func, error)
- func (f Funcs) Reserve()
- func (f Funcs) Swap(i, j int)
- type Parser
- type ParserOptions
- type Position
- type Query
- type Result
- type Type
- type TypeSignature
- type Types
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 ¶
IsDeclaration returns true if the given function is a function declaration (*ast.FuncDecl)
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 ¶
Declarations returns a copy of funcs with only Function declarations
func (Funcs) EnclosingFunc ¶
EnclosingFunc returns the enclosing *Func for the given offset
func (Funcs) NextFuncShift ¶
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) PrevFuncShift ¶
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...
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 ¶
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.
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 ¶
ToPosition returns a Position from the given token.Position
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