ast

package
v0.0.0-...-f100050 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Copyright © 2024 Gareth Watts <gareth@omnipotent.net>

Mostly written by an LLM.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(source string) string

Format re-formats the supplied source code.

Types

type ASTProcessor

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

ASTProcessor handles parsing source files and extracting method calls.

func NewASTProcessor

func NewASTProcessor() *ASTProcessor

NewASTProcessor creates a new ASTProcessor.

func (*ASTProcessor) ExtractFullCall

func (a *ASTProcessor) ExtractFullCall(filePath string, line, character int) (string, error)

ExtractFullCall extracts the call expression corresponding to the reference.

func (*ASTProcessor) FindFuncDefinitions

func (a *ASTProcessor) FindFuncDefinitions(pkgPath string, funcPattern ...string) (matches []Match, err error)

FindFuncDefinitions locates the position of all supplied exported functions or methods within a package. funcPattern is one or more globs. methods can be specified as `TypeName.MethodName`

func (*ASTProcessor) GetEnclosingFunctionName

func (a *ASTProcessor) GetEnclosingFunctionName(filePath string, line, character int) (functionName, receiverType, receiverName string, err error)

GetEnclosingFunctionName finds the name and receiver type of the function/method containing the given position.

func (*ASTProcessor) ParseFile

func (a *ASTProcessor) ParseFile(filePath string) error

ParseFile parses a Go source file and caches the AST.

type Match

type Match struct {
	Pkg        string
	RecvType   string
	RecvName   string
	FuncName   string
	Filename   string
	OffsetLine int
	OffsetCol  int
}

Match holds a matching function reference located by FindFuncDefinitions.

func (Match) MethodName

func (m Match) MethodName() string

MethodName returns the pretty-printed name of a method or function call.

Jump to

Keyboard shortcuts

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