asq

package
v0.0.0-...-e0dc6c1 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedLang = errors.New("unsupported language")
)

Functions

func ConvertToTreeSitterQuery

func ConvertToTreeSitterQuery(node ast.Node, p *QueryContext) (string, error)

ConvertToTreeSitterQuery converts a Go AST node to a tree-sitter query string

func Debug

func Debug(format string, args ...interface{})

func ExtractTreeSitterQuery

func ExtractTreeSitterQuery(filePath string) (string, error)

ExtractTreeSitterQuery parses a Go file and extracts the code between //asq_start and //asq_end comments, then converts it to a tree-sitter query.

func GetSnippetForMatch

func GetSnippetForMatch(filePath string, match Match) (string, error)

GetSnippetForMatch returns the code snippet for a given match, including context. If the match is within a function, returns the entire function. Otherwise, returns 5 lines before and after the match.

func GetTSLanguageFromEnry

func GetTSLanguageFromEnry(filename string, contents []byte) (*sitter.Language, error)

GetTSLanguageFromEnry detects the language of a file using go-enry and returns the corresponding tree-sitter language parser. Currently only supports Go.

func IsDebugging

func IsDebugging() bool

Types

type ArrayType

type ArrayType struct {
	Ast *ast.ArrayType
	Len Expr
	Elt Node
}

ArrayType wraps an ast.ArrayType node

func (*ArrayType) AstNode

func (a *ArrayType) AstNode() ast.Node

func (*ArrayType) WriteTreeSitterQuery

func (a *ArrayType) WriteTreeSitterQuery(w io.Writer) error

type AssignStmt

type AssignStmt struct {
	Ast *ast.AssignStmt
	Lhs []Expr
	Rhs []Expr
}

AssignStmt wraps an ast.AssignStmt node

func (*AssignStmt) AstNode

func (a *AssignStmt) AstNode() ast.Node

func (*AssignStmt) WriteTreeSitterQuery

func (a *AssignStmt) WriteTreeSitterQuery(w io.Writer) error

type BadDecl

type BadDecl struct {
	Ast *ast.BadDecl
}

BadDecl wraps an ast.BadDecl node

func (*BadDecl) AstNode

func (b *BadDecl) AstNode() ast.Node

func (*BadDecl) WriteTreeSitterQuery

func (b *BadDecl) WriteTreeSitterQuery(w io.Writer) error

type BadStmt

type BadStmt struct {
	Ast *ast.BadStmt
}

BadStmt wraps an ast.BadStmt node

func (*BadStmt) AstNode

func (b *BadStmt) AstNode() ast.Node

func (*BadStmt) WriteTreeSitterQuery

func (b *BadStmt) WriteTreeSitterQuery(w io.Writer) error

type BasicLit

type BasicLit struct {
	Ast *ast.BasicLit
}

BasicLit wraps an ast.BasicLit node

func (*BasicLit) AstNode

func (b *BasicLit) AstNode() ast.Node

func (*BasicLit) WriteTreeSitterQuery

func (b *BasicLit) WriteTreeSitterQuery(w io.Writer) error

type BinaryExpr

type BinaryExpr struct {
	Ast *ast.BinaryExpr
	X   Expr
	Op  token.Token
	Y   Expr
}

DefaultExpr wraps any ast.Expr type that doesn't have a specific implementation

func (*BinaryExpr) AstNode

func (b *BinaryExpr) AstNode() ast.Node

func (*BinaryExpr) WriteTreeSitterQuery

func (b *BinaryExpr) WriteTreeSitterQuery(w io.Writer) error

type BlockStmt

type BlockStmt struct {
	Ast  *ast.BlockStmt
	List []Stmt
}

BlockStmt wraps an ast.BlockStmt node

func (*BlockStmt) AstNode

func (b *BlockStmt) AstNode() ast.Node

func (*BlockStmt) WriteTreeSitterQuery

func (b *BlockStmt) WriteTreeSitterQuery(w io.Writer) error

type BranchStmt

type BranchStmt struct {
	Ast   *ast.BranchStmt
	Label *Ident
}

BranchStmt wraps an ast.BranchStmt node

func (*BranchStmt) AstNode

func (b *BranchStmt) AstNode() ast.Node

func (*BranchStmt) WriteTreeSitterQuery

func (b *BranchStmt) WriteTreeSitterQuery(w io.Writer) error

type CallExpr

type CallExpr struct {
	Ast      *ast.CallExpr
	Fun      Expr
	Args     []Expr
	Wildcard bool
}

CallExpr wraps an ast.CallExpr node

func (*CallExpr) AstNode

func (c *CallExpr) AstNode() ast.Node

func (*CallExpr) WriteTreeSitterQuery

func (c *CallExpr) WriteTreeSitterQuery(w io.Writer) error

type ChanType

type ChanType struct {
	Ast   *ast.ChanType
	Value Node
}

ChanType wraps an ast.ChanType node

func (*ChanType) AstNode

func (c *ChanType) AstNode() ast.Node

func (*ChanType) WriteTreeSitterQuery

func (c *ChanType) WriteTreeSitterQuery(w io.Writer) error

type CompositeLit

type CompositeLit struct {
	Ast  *ast.CompositeLit
	Type Node
	Elts []Expr
}

CompositeLit wraps an ast.CompositeLit node

func (*CompositeLit) AstNode

func (c *CompositeLit) AstNode() ast.Node

func (*CompositeLit) WriteTreeSitterQuery

func (c *CompositeLit) WriteTreeSitterQuery(w io.Writer) error

type Decl

type Decl interface {
	Node
	// contains filtered or unexported methods
}

Decl nodes contain declarations and implement the Decl interface.

func BuildAsqDecl

func BuildAsqDecl(decl ast.Decl, p *QueryContext) Decl

BuildAsqDecl converts an ast.Decl to its corresponding asq.Decl

type DeclStmt

type DeclStmt struct {
	Ast  *ast.DeclStmt
	Decl Decl
}

DeclStmt wraps an ast.DeclStmt node

func (*DeclStmt) AstNode

func (d *DeclStmt) AstNode() ast.Node

func (*DeclStmt) WriteTreeSitterQuery

func (d *DeclStmt) WriteTreeSitterQuery(w io.Writer) error

type DefaultDecl

type DefaultDecl struct {
	Ast ast.Decl
}

DefaultDecl wraps any ast.Decl type that doesn't have a specific implementation

func (*DefaultDecl) AstNode

func (d *DefaultDecl) AstNode() ast.Node

func (*DefaultDecl) WriteTreeSitterQuery

func (d *DefaultDecl) WriteTreeSitterQuery(w io.Writer) error

type DefaultExpr

type DefaultExpr struct {
	Node ast.Node
}

func (*DefaultExpr) AstNode

func (d *DefaultExpr) AstNode() ast.Node

func (*DefaultExpr) WriteTreeSitterQuery

func (d *DefaultExpr) WriteTreeSitterQuery(w io.Writer) error

type DefaultNode

type DefaultNode struct {
	Node ast.Node
}

DefaultNode wraps any ast.Node type that doesn't have a specific implementation

func (*DefaultNode) AstNode

func (d *DefaultNode) AstNode() ast.Node

func (*DefaultNode) WriteTreeSitterQuery

func (d *DefaultNode) WriteTreeSitterQuery(w io.Writer) error

type DefaultStmt

type DefaultStmt struct {
	Ast ast.Stmt
}

DefaultStmt wraps any ast.Stmt type that doesn't have a specific implementation

func (*DefaultStmt) AstNode

func (d *DefaultStmt) AstNode() ast.Node

func (*DefaultStmt) WriteTreeSitterQuery

func (d *DefaultStmt) WriteTreeSitterQuery(w io.Writer) error

type DeferStmt

type DeferStmt struct {
	Ast  *ast.DeferStmt
	Call Expr
}

DeferStmt wraps an ast.DeferStmt node

func (*DeferStmt) AstNode

func (d *DeferStmt) AstNode() ast.Node

func (*DeferStmt) WriteTreeSitterQuery

func (d *DeferStmt) WriteTreeSitterQuery(w io.Writer) error

type EmptyStmt

type EmptyStmt struct {
	Ast *ast.EmptyStmt
}

EmptyStmt wraps an ast.EmptyStmt node

func (*EmptyStmt) AstNode

func (e *EmptyStmt) AstNode() ast.Node

func (*EmptyStmt) WriteTreeSitterQuery

func (e *EmptyStmt) WriteTreeSitterQuery(w io.Writer) error

type Expr

type Expr interface {
	Node
	// contains filtered or unexported methods
}

Expr nodes contain expressions and implement the Expr interface.

func BuildAsqExpr

func BuildAsqExpr(node ast.Node, p *QueryContext) Expr

BuildAsqExpr converts an ast.Node to its corresponding asq.Node

type ExprStmt

type ExprStmt struct {
	Ast *ast.ExprStmt
	X   Expr
}

ExprStmt wraps an ast.ExprStmt node

func (*ExprStmt) AstNode

func (e *ExprStmt) AstNode() ast.Node

func (*ExprStmt) WriteTreeSitterQuery

func (e *ExprStmt) WriteTreeSitterQuery(w io.Writer) error

type Field

type Field struct {
	Ast   *ast.Field
	Names []*Ident
	Type  Node
	Tag   *BasicLit
}

Field wraps an ast.Field node

func (*Field) AstNode

func (f *Field) AstNode() ast.Node

func (*Field) WriteTreeSitterQuery

func (f *Field) WriteTreeSitterQuery(w io.Writer) error

type FieldList

type FieldList struct {
	Ast  *ast.FieldList
	List []*Field
}

FieldList wraps an ast.FieldList node

func (*FieldList) AstNode

func (f *FieldList) AstNode() ast.Node

func (*FieldList) WriteTreeSitterQuery

func (f *FieldList) WriteTreeSitterQuery(w io.Writer) error

type FuncDecl

type FuncDecl struct {
	Ast  *ast.FuncDecl
	Name *Ident
	Type *FuncType
	Body Node
}

FuncDecl wraps an ast.FuncDecl node

func (*FuncDecl) AstNode

func (f *FuncDecl) AstNode() ast.Node

func (*FuncDecl) WriteTreeSitterQuery

func (f *FuncDecl) WriteTreeSitterQuery(w io.Writer) error

type FuncLit

type FuncLit struct {
	Ast  *ast.FuncLit
	Type *FuncType
	Body Node
}

FuncLit wraps an ast.FuncLit node

func (*FuncLit) AstNode

func (f *FuncLit) AstNode() ast.Node

func (*FuncLit) WriteTreeSitterQuery

func (f *FuncLit) WriteTreeSitterQuery(w io.Writer) error

type FuncType

type FuncType struct {
	Ast     *ast.FuncType
	Params  *FieldList
	Results *FieldList
}

FuncType wraps an ast.FuncType node

func (*FuncType) AstNode

func (f *FuncType) AstNode() ast.Node

func (*FuncType) WriteTreeSitterQuery

func (f *FuncType) WriteTreeSitterQuery(w io.Writer) error

type GenDecl

type GenDecl struct {
	Ast   *ast.GenDecl
	Specs []Node
}

GenDecl wraps an ast.GenDecl node

func (*GenDecl) AstNode

func (g *GenDecl) AstNode() ast.Node

func (*GenDecl) WriteTreeSitterQuery

func (g *GenDecl) WriteTreeSitterQuery(w io.Writer) error

type GoStmt

type GoStmt struct {
	Ast  *ast.GoStmt
	Call Expr
}

GoStmt wraps an ast.GoStmt node

func (*GoStmt) AstNode

func (g *GoStmt) AstNode() ast.Node

func (*GoStmt) WriteTreeSitterQuery

func (g *GoStmt) WriteTreeSitterQuery(w io.Writer) error

type Ident

type Ident struct {
	Ast      *ast.Ident
	Wildcard bool
}

Ident wraps an ast.Ident node with an additional Wildcard field

func (*Ident) AstNode

func (i *Ident) AstNode() ast.Node

func (*Ident) WriteTreeSitterQuery

func (i *Ident) WriteTreeSitterQuery(w io.Writer) error

type IfStmt

type IfStmt struct {
	Ast  *ast.IfStmt
	Init Stmt
	Cond Expr
	Body *BlockStmt
	Else Stmt
}

IfStmt wraps an ast.IfStmt node

func (*IfStmt) AstNode

func (i *IfStmt) AstNode() ast.Node

func (*IfStmt) WriteTreeSitterQuery

func (i *IfStmt) WriteTreeSitterQuery(w io.Writer) error

type IncDecStmt

type IncDecStmt struct {
	Ast *ast.IncDecStmt
	X   Expr
}

IncDecStmt wraps an ast.IncDecStmt node

func (*IncDecStmt) AstNode

func (i *IncDecStmt) AstNode() ast.Node

func (*IncDecStmt) WriteTreeSitterQuery

func (i *IncDecStmt) WriteTreeSitterQuery(w io.Writer) error

type LabeledStmt

type LabeledStmt struct {
	Ast   *ast.LabeledStmt
	Label *Ident
	Stmt  Stmt
}

LabeledStmt wraps an ast.LabeledStmt node

func (*LabeledStmt) AstNode

func (l *LabeledStmt) AstNode() ast.Node

func (*LabeledStmt) WriteTreeSitterQuery

func (l *LabeledStmt) WriteTreeSitterQuery(w io.Writer) error

type MapType

type MapType struct {
	Ast   *ast.MapType
	Key   Node
	Value Node
}

MapType wraps an ast.MapType node

func (*MapType) AstNode

func (m *MapType) AstNode() ast.Node

func (*MapType) WriteTreeSitterQuery

func (m *MapType) WriteTreeSitterQuery(w io.Writer) error

type Match

type Match struct {
	Row  int
	Col  int
	Code string
}

Match represents a single tree-sitter query match

func ValidateTreeSitterQuery

func ValidateTreeSitterQuery(file, query string) ([]Match, error)

ValidateTreeSitterQuery executes a tree-sitter query directly on the given file returns all matches with their line numbers, column numbers, and matched code

type MatchGroup

type MatchGroup struct {
	FilePath    string
	StartLine   int
	EndLine     int
	Snippet     string
	IsFunction  bool
	FunctionPos token.Pos // Used for sorting function groups
}

MatchGroup represents a group of matches that should be displayed together

func GroupMatchesForCursorDedup

func GroupMatchesForCursorDedup(filePath string, matches []Match) ([]MatchGroup, error)

GroupMatchesForCursorDedup takes a list of matches for a file and groups them by their containing functions or root-level context. Returns groups sorted by position.

type Node

type Node interface {
	WriteTreeSitterQuery(w io.Writer) error
	AstNode() ast.Node
}

Node is the interface that all asq nodes implement.

func BuildAsqNode

func BuildAsqNode(node ast.Node, p *QueryContext) Node

BuildAsqNode converts an ast.Node to its corresponding asq.Node

type Package

type Package struct {
	Ast   *ast.Package
	Name  *Ident
	Files map[string]Node
}

Package wraps an ast.Package node

func (*Package) AstNode

func (p *Package) AstNode() ast.Node

func (*Package) WriteTreeSitterQuery

func (p *Package) WriteTreeSitterQuery(w io.Writer) error

type QueryContext

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

QueryContext is an internal struct used during the first pass of AST processing to track which identifiers should be treated as wildcards based on active intervals.

func NewQueryContext

func NewQueryContext(file *ast.File) (*QueryContext, token.Pos, token.Pos)

NewQueryContext creates a new QueryContext instance

func (*QueryContext) AddInterval

func (p *QueryContext) AddInterval(c *ast.Comment)

AddInterval adds a new wildcard interval

func (*QueryContext) IsWildcard

func (p *QueryContext) IsWildcard(node ast.Node) bool

IsWildcard checks if the given node should be treated as a wildcard. A node is considered a wildcard if either: 1. It is an ast.Ident node with a name prefixed by "_asq_" 2. It is the first syntactic entity in an active interval

func (*QueryContext) SetLastIntervalEnd

func (p *QueryContext) SetLastIntervalEnd(start token.Pos)

SetLastIntervalEnd sets the end of the last wildcard interval

type RangeInterval

type RangeInterval struct {
	Start    token.Pos // Start offset in the line
	TokenEnd token.Pos // End offset in the line
	End      token.Pos
	// contains filtered or unexported fields
}

RangeInterval represents an active interval for a wildcard tag

type RangeStmt

type RangeStmt struct {
	Ast   *ast.RangeStmt
	Key   Expr
	Value Expr
	X     Expr
	Body  *BlockStmt
}

RangeStmt wraps an ast.RangeStmt node

func (*RangeStmt) AstNode

func (r *RangeStmt) AstNode() ast.Node

func (*RangeStmt) WriteTreeSitterQuery

func (r *RangeStmt) WriteTreeSitterQuery(w io.Writer) error

type ReturnStmt

type ReturnStmt struct {
	Ast     *ast.ReturnStmt
	Results []Expr
}

ReturnStmt wraps an ast.ReturnStmt node

func (*ReturnStmt) AstNode

func (r *ReturnStmt) AstNode() ast.Node

func (*ReturnStmt) WriteTreeSitterQuery

func (r *ReturnStmt) WriteTreeSitterQuery(w io.Writer) error

type SelectStmt

type SelectStmt struct {
	Ast  *ast.SelectStmt
	Body *BlockStmt
}

SelectStmt wraps an ast.SelectStmt node

func (*SelectStmt) AstNode

func (s *SelectStmt) AstNode() ast.Node

func (*SelectStmt) WriteTreeSitterQuery

func (s *SelectStmt) WriteTreeSitterQuery(w io.Writer) error

type SelectorExpr

type SelectorExpr struct {
	Ast      *ast.SelectorExpr
	X        Expr
	Wildcard bool
}

SelectorExpr wraps an ast.SelectorExpr node

func (*SelectorExpr) AstNode

func (s *SelectorExpr) AstNode() ast.Node

func (*SelectorExpr) WriteTreeSitterQuery

func (s *SelectorExpr) WriteTreeSitterQuery(w io.Writer) error

type SendStmt

type SendStmt struct {
	Ast   *ast.SendStmt
	Chan  Expr
	Value Expr
}

SendStmt wraps an ast.SendStmt node

func (*SendStmt) AstNode

func (s *SendStmt) AstNode() ast.Node

func (*SendStmt) WriteTreeSitterQuery

func (s *SendStmt) WriteTreeSitterQuery(w io.Writer) error

type Stmt

type Stmt interface {
	Node
	// contains filtered or unexported methods
}

Stmt nodes contain statements and implement the Stmt interface.

func BuildAsqStmt

func BuildAsqStmt(stmt ast.Stmt, p *QueryContext) Stmt

BuildAsqStmt converts an ast.Stmt to its corresponding asq.Stmt

type StructType

type StructType struct {
	Ast    *ast.StructType
	Fields *FieldList
}

StructType wraps an ast.StructType node

func (*StructType) AstNode

func (s *StructType) AstNode() ast.Node

func (*StructType) WriteTreeSitterQuery

func (s *StructType) WriteTreeSitterQuery(w io.Writer) error

type SwitchStmt

type SwitchStmt struct {
	Ast  *ast.SwitchStmt
	Init Stmt
	Tag  Expr
	Body *BlockStmt
}

SwitchStmt wraps an ast.SwitchStmt node

func (*SwitchStmt) AstNode

func (s *SwitchStmt) AstNode() ast.Node

func (*SwitchStmt) WriteTreeSitterQuery

func (s *SwitchStmt) WriteTreeSitterQuery(w io.Writer) error

type TypeSpec

type TypeSpec struct {
	Ast  *ast.TypeSpec
	Name *Ident
	Type Node
}

TypeSpec wraps an ast.TypeSpec node

func (*TypeSpec) AstNode

func (t *TypeSpec) AstNode() ast.Node

func (*TypeSpec) WriteTreeSitterQuery

func (t *TypeSpec) WriteTreeSitterQuery(w io.Writer) error

type TypeSwitchStmt

type TypeSwitchStmt struct {
	Ast    *ast.TypeSwitchStmt
	Init   Stmt
	Assign Stmt
	Body   *BlockStmt
}

TypeSwitchStmt wraps an ast.TypeSwitchStmt node

func (*TypeSwitchStmt) AstNode

func (t *TypeSwitchStmt) AstNode() ast.Node

func (*TypeSwitchStmt) WriteTreeSitterQuery

func (t *TypeSwitchStmt) WriteTreeSitterQuery(w io.Writer) error

type ValueSpec

type ValueSpec struct {
	Ast    *ast.ValueSpec
	Names  []*Ident
	Type   Node
	Values []Expr
}

ValueSpec wraps an ast.ValueSpec node

func (*ValueSpec) AstNode

func (v *ValueSpec) AstNode() ast.Node

func (*ValueSpec) WriteTreeSitterQuery

func (v *ValueSpec) WriteTreeSitterQuery(w io.Writer) error

Jump to

Keyboard shortcuts

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