astutil

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package astutil provides various AST utility functions for gopls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal added in v0.18.0

func Equal(x, y ast.Node, identical func(x, y *ast.Ident) bool) bool

Equal reports whether two nodes are structurally equal, ignoring fields of type token.Pos, ast.Object, and ast.Scope, and comments.

The operands x and y may be nil. A nil slice is not equal to an empty slice.

The provided function determines whether two identifiers should be considered identical.

func FlatFields added in v0.17.0

func FlatFields(list *ast.FieldList) iter.Seq2[*ast.Ident, *ast.Field]

FlatFields 'flattens' an ast.FieldList, returning an iterator over each (name, field) combination in the list. For unnamed fields, the identifier is nil.

func NodeContains

func NodeContains(n ast.Node, pos token.Pos) bool

NodeContains reports whether the Pos/End range of node n encloses the given position pos.

It is inclusive of both end points, to allow hovering (etc) when the cursor is immediately after a node.

For unfortunate historical reasons, the Pos/End extent of an ast.File runs from the start of its package declaration---excluding copyright comments, build tags, and package documentation---to the end of its last declaration, excluding any trailing comments. So, as a special case, if n is an ast.File, NodeContains uses n.FileStart <= pos && pos <= n.FileEnd to report whether the position lies anywhere within the file.

Precondition: n must not be nil.

func PurgeFuncBodies

func PurgeFuncBodies(src []byte) []byte

PurgeFuncBodies returns a copy of src in which the contents of each outermost {...} region except struct and interface types have been deleted. This reduces the amount of work required to parse the top-level declarations.

PurgeFuncBodies does not preserve newlines or position information. Also, if the input is invalid, parsing the output of PurgeFuncBodies may result in a different tree due to its effects on parser error recovery.

func UnpackRecv

func UnpackRecv(rtyp ast.Expr) (ptr bool, rname *ast.Ident, tparams []*ast.Ident)

UnpackRecv unpacks a receiver type expression, reporting whether it is a pointer receiver, along with the type name identifier and any receiver type parameter identifiers.

Copied (with modifications) from go/types.

Types

This section is empty.

Jump to

Keyboard shortcuts

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