parser

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildID

func BuildID(parts ...string) string

BuildID optimizes string concatenation for node IDs using strings.Builder

func RepoNodeID

func RepoNodeID(repoID string) string

func ShouldSkipFile

func ShouldSkipFile(name string) bool

func ShouldSkipFolder

func ShouldSkipFolder(name string) bool

func WorkspaceNodeID

func WorkspaceNodeID(workspaceID string) string

Types

type Edge

type Edge struct {
	From        string
	To          string
	Type        EdgeType
	RepoID      string           // The ID of the repository that discovered this edge
	Occurrences []EdgeOccurrence `json:"occurrences,omitempty"`
}

Edge represents a relation between two nodes

func NewEdge

func NewEdge() *Edge

NewEdge creates a graph edge.

type EdgeOccurrence

type EdgeOccurrence struct {
	FilePath string `json:"filepath,omitempty"`
	Line     int    `json:"line,omitempty"`
	Column   int    `json:"column,omitempty"`
}

type EdgeType

type EdgeType string

EdgeType defines the relation between two nodes

const (
	EdgeTypeCalls          EdgeType = "CALLS"
	EdgeTypeImplements     EdgeType = "IMPLEMENTS"
	EdgeTypeImports        EdgeType = "IMPORTS"
	EdgeTypeReferences     EdgeType = "REFERENCES"
	EdgeTypeInstantiates   EdgeType = "INSTANTIATES"
	EdgeTypeSpawns         EdgeType = "SPAWNS"
	EdgeTypeSendsTo        EdgeType = "SENDS_TO"
	EdgeTypeReceivesFrom   EdgeType = "RECEIVES_FROM"
	EdgeTypeContains       EdgeType = "CONTAINS" // e.g. Package contains File, File contains Func
	EdgeTypeRegistersRoute EdgeType = "REGISTERS_ROUTE"
)

type Node

type Node struct {
	ID       string // Unique identifier (e.g. fully qualified name or path)
	Type     NodeType
	Name     string
	PkgPath  string
	FilePath string
	Lines    [2]int // Start, End line
	RepoID   string // The ID of the repository this node belongs to
}

func NewNode

func NewNode() *Node

NewNode creates a graph node.

type NodeType

type NodeType string

NodeType defines the type of a parsed node

const (
	NodeTypePackage   NodeType = "PACKAGE"
	NodeTypeFile      NodeType = "FILE"
	NodeTypeFolder    NodeType = "FOLDER"
	NodeTypeStruct    NodeType = "STRUCT"
	NodeTypeInterface NodeType = "INTERFACE"
	NodeTypeFunc      NodeType = "FUNC"
	NodeTypeMethod    NodeType = "METHOD"
	NodeTypeConstant  NodeType = "CONSTANT"
	NodeTypeVariable  NodeType = "VARIABLE"
	NodeTypeTypeAlias NodeType = "TYPE_ALIAS"
	NodeTypeChannel   NodeType = "CHANNEL"
	NodeTypeGoroutine NodeType = "GOROUTINE"
	NodeTypeRoute     NodeType = "ROUTE"
	NodeTypeBoundary  NodeType = "BOUNDARY" // External package/func
	NodeTypeRepo      NodeType = "REPO"
	NodeTypeWorkspace NodeType = "WORKSPACE"
)

type ParseResult

type ParseResult struct {
	Nodes []*Node
	Edges []*Edge
	// contains filtered or unexported fields
}

type Parser

type Parser struct {
	ModulePrefix string
	RepoID       string
	WorkspaceID  string
	IncludeTests bool
}

func NewParser

func NewParser(modulePrefix, repoID string) *Parser

func NewWorkspaceParser

func NewWorkspaceParser(modulePrefix, repoID, workspaceID string) *Parser

func (*Parser) BuildRepositoryStructure

func (p *Parser) BuildRepositoryStructure(ctx context.Context, dir string, packageFolders map[string]map[string]bool) (*ParseResult, error)

BuildRepositoryStructure builds the physical folder tree and folder-to-package containment edges for the repository root using already-known package locations. The packageFolders map is keyed by slash-separated relative folder path, with "." representing the repository root.

func (*Parser) ParsePackage

func (p *Parser) ParsePackage(ctx context.Context, dir string) (*ParseResult, error)

ParsePackage parses a single package directory and returns its entities. Prefer ParsePackageIncremental for watch-mode updates.

func (*Parser) ParsePackageIncremental

func (p *Parser) ParsePackageIncremental(ctx context.Context, dir string) (*ParseResult, error)

ParsePackageIncremental parses a single package for watch-mode incremental updates. It intentionally omits NeedDeps to avoid loading hundreds of transitive dependency packages into memory on every file save, keeping the RAM footprint low. Cross-package IMPLEMENTS edges are not resolved here as they require full dependency info; those edges remain from the last full analysis run.

func (*Parser) ParseWorkspace

func (p *Parser) ParseWorkspace(ctx context.Context, dir string) (*ParseResult, error)

ParseWorkspace loads and parses the Go codebase in the given directory.

func (*Parser) WithTests

func (p *Parser) WithTests(includeTests bool) *Parser

Jump to

Keyboard shortcuts

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