extract

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package extract provides AST-based symbol extraction for Go and TypeScript/JavaScript files. It is a port of src/extraction/ from github.com/colbymchenry/codegraph (MIT).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectLanguage

func DetectLanguage(filePath string) model.Language

DetectLanguage returns the model.Language for the given file path, based solely on the file extension. Mirrors EXTENSION_MAP in src/extraction/grammars.ts. File-level-only languages (yaml, twig, properties) return their own Language constant so the indexer records a file row with zero nodes, matching the original's behaviour.

func DetectLanguageContent

func DetectLanguageContent(path string, content []byte) model.Language

DetectLanguageContent returns the model.Language for path, using content to disambiguate ambiguous extensions. For unambiguous extensions it delegates to the path-only DetectLanguage. For `.h` (which DetectLanguage defaults to C for back-compat) it sniffs content: Objective-C markers (`@interface`/`@protocol`/ `@implementation`/`#import`) win first → LangObjC; else C++ markers → LangCPP; else LangC. Callers that have the file content available (the indexer extract path, the parity test) should prefer this over DetectLanguage.

func DetectSpecScore

func DetectSpecScore(filePath string, content []byte) bool

DetectSpecScore reports whether the file at filePath is a SpecScore artifact: a `.md`/`README.md` file located under a `spec/` path segment whose leading YAML frontmatter (delimited by `---` … `---` at the very top) carries a `format:` key whose value is `https://specscore.md/<kind>-specification`. Only the leading frontmatter block is scanned, not the whole file.

func ExtractFile

func ExtractFile(path string, content []byte, lang model.Language) (model.ExtractionResult, error)

ExtractFile parses content as lang, extracts a file node (and, eventually, all symbols), and returns the result. The AST-walking logic for individual symbol kinds will be added in subsequent tasks; this skeleton always succeeds and returns at least the file node.

func ExtractGoRoutes

func ExtractGoRoutes(filePath string, content []byte, fileNodeID string) ([]model.Node, []model.UnresolvedReference)

ExtractGoRoutes extracts net/http HandleFunc/Handle route registrations from Go source, mirroring the goResolver.extract() in src/resolution/frameworks/go.ts.

This is called from ExtractFile after the main tree-sitter walk.

func IsFileLevelOnly

func IsFileLevelOnly(lang model.Language) bool

IsFileLevelOnly reports whether lang is tracked at the file-record level only — stored in the files table with zero symbol nodes. Mirrors isFileLevelOnlyLanguage() in src/extraction/grammars.ts.

func IsGeneratedFile

func IsGeneratedFile(filePath string) bool

IsGeneratedFile reports whether filePath looks like a tool-generated source file, based on its filename. Path-only — does not read content.

Types

This section is empty.

Jump to

Keyboard shortcuts

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