base

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package base frontend.go provides shared helpers for frontend component detectors (Angular, React, Vue). Mirrors the Java FrontendDetectorHelper.

Anchor helpers — Plan §1.2 follow-on.

Many regex detectors emit cross-file "imports" / "depends_on" edges using the source file path and the imported name as endpoints. Both endpoints were free-form strings with no matching CodeNode, so every such edge got dropped at GraphBuilder.Snapshot's phantom filter.

EnsureFileAnchor and EnsureExternalAnchor materialize anchor nodes so the edges survive. The GraphBuilder dedup map collapses the per-file and per-external nodes across files at zero extra cost (every Python file importing "requests" gets one shared py:external:requests node).

Package base provides shared helpers for detector implementations. Mirrors the Java Abstract* detector hierarchy collapsed for tree-sitter.

Package base structured.go provides shared helpers for structured-data detectors (YAML / JSON / TOML / INI / properties). Mirrors the Java AbstractStructuredDetector helpers.

Index

Constants

View Source
const RegexDetectorDefaultConfidence = model.ConfidenceLexical

RegexDetectorDefaultConfidence is the floor for regex-only detectors. Java equivalent: AbstractRegexDetector.defaultConfidence() = LEXICAL.

View Source
const StructuredDetectorDefaultConfidence = model.ConfidenceSyntactic

StructuredDetectorDefaultConfidence is the floor for structured detectors. Structured parsing produces a parsed shape, not just a regex match, so the confidence floor is SYNTACTIC (matches Java AbstractStructuredDetector.defaultConfidence()).

View Source
const TreeSitterDetectorDefaultConfidence = model.ConfidenceSyntactic

TreeSitterDetectorDefaultConfidence is the floor for AST-backed detectors. Java equivalent: AbstractJavaParserDetector.defaultConfidence() = SYNTACTIC.

Variables

This section is empty.

Functions

func AddKeyNode

func AddKeyNode(fileID, fp, key, format string, ctx *detector.Context,
	nodes *[]*model.CodeNode, edges *[]*model.CodeEdge)

AddKeyNode appends a CONFIG_KEY node and a CONTAINS edge from fileID to it. Mirrors Java addKeyNode.

func AsMap

func AsMap(obj any) map[string]any

AsMap returns obj coerced to map[string]any. Returns nil when obj is nil or not a map. Used by structured detectors to navigate parsed data.

func BuildFileNode

func BuildFileNode(ctx *detector.Context, format string) *model.CodeNode

BuildFileNode constructs a CONFIG_FILE node for ctx's file. Mirrors the Java buildFileNode helper; callers append the returned node themselves.

func CreateComponentNode

func CreateComponentNode(framework, filePath, idType, name string, kind model.NodeKind, line int) *model.CodeNode

CreateComponentNode constructs a frontend component / hook / service node with the standard fields populated. Equivalent to Java FrontendDetectorHelper.createComponentNode.

framework  e.g. "angular", "react", "vue"
filePath   source file path (forward-slash, relative to repo root)
idType     namespace segment for the ID ("component", "hook", "service")
name       component / class / function name
kind       model.NodeComponent | NodeHook | NodeMiddleware
line       1-based line number

func EnsureExternalAnchor

func EnsureExternalAnchor(name, idPrefix, detectorName string, conf model.Confidence, nodes *[]*model.CodeNode, seen map[string]bool) string

EnsureExternalAnchor returns the canonical ID of an external module / package / image target and appends it to nodes once per unique name. idPrefix scopes the namespace ("py:external", "rust:external", "docker:image", etc.).

func EnsureFileAnchor

func EnsureFileAnchor(ctx *detector.Context, langPrefix, detectorName string, conf model.Confidence, nodes *[]*model.CodeNode, seen map[string]bool) string

EnsureFileAnchor returns the canonical ID of the file-as-module anchor node for ctx.FilePath and appends the node to nodes once. Caller must pass the same `seen` map across invocations within a single detector run (or nil for one-shot calls).

langPrefix scopes the anchor namespace ("py" for Python, "ts" for TypeScript, etc.) so cross-language detectors don't collide on the same path.

Detector source/confidence are stamped onto the anchor — pick a confidence that's at-or-below the actual emission detector so the merge rule (higher wins) doesn't accidentally demote a high-confidence emission later.

func FileName

func FileName(path string) string

FileName extracts just the filename component of a path (after the last '/' or '\\'). Mirrors Java AbstractRegexDetector.fileName().

func FindAllByType

func FindAllByType(root *sitter.Node, t string) []*sitter.Node

FindAllByType returns every descendant whose type matches t (pre-order DFS).

func FindFirstByType

func FindFirstByType(root *sitter.Node, t string) *sitter.Node

FindFirstByType returns the first descendant whose type matches t (pre-order DFS). Returns nil when not found.

func FindLineNumber

func FindLineNumber(text string, offset int) int

FindLineNumber returns the 1-based line number for a character offset in text. Offsets past the end clamp to the last line; empty input returns 1. Mirrors Java's findLineNumber helper used throughout the regex detectors.

func GetList

func GetList(container any, key string) []any

GetList returns the nested list at key in container. Returns nil when key is missing or the value is not a list.

func GetMap

func GetMap(container any, key string) map[string]any

GetMap returns the nested map at key in container. Returns nil when key is missing or the value is not a map.

func GetString

func GetString(container any, key string) string

GetString returns the string at key in container. Returns "" when the key is missing or the value is not a string.

func GetStringOrDefault

func GetStringOrDefault(container any, key, fallback string) string

GetStringOrDefault returns the string at key or fallback when missing or non-string.

func LineAt

func LineAt(text string, offset int) int

LineAt returns the 1-based line number for a byte offset in text. Mirrors the Java lineAt helper (counts \n characters up to offset and adds 1).

func Walk

func Walk(root *sitter.Node, visit func(*sitter.Node) bool)

Walk performs a pre-order DFS over the tree-sitter subtree rooted at root. The visitor returns false to abort the walk (siblings + descendants of the current node are still skipped if false is returned at that node).

Types

This section is empty.

Jump to

Keyboard shortcuts

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