ast

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KindName

func KindName(k SymbolKind) string

KindName returns the human-readable string for a SymbolKind.

Types

type AstStats

type AstStats struct {
	FilesIndexed int
	TotalSymbols int
	ByLanguage   map[string]int
	ByKind       map[string]int
}

AstStats holds index statistics.

type FileSymbolsArgs

type FileSymbolsArgs struct {
	File string `json:"file" jsonschema:"File path relative to project root (e.g. src/auth/auth.service.ts)"`
}

FileSymbolsArgs defines the input parameters for codeindex_ast_file_symbols.

type FindUsagesArgs

type FindUsagesArgs struct {
	Symbol string `json:"symbol" jsonschema:"Exact symbol name to search for"`
	Kind   string `json:"kind,omitempty" jsonschema:"Optional: kind of the symbol being searched (class, interface, enum, function, method)"`
}

FindUsagesArgs defines the input parameters for codeindex_ast_find_usages.

type GetImportsArgs

type GetImportsArgs struct {
	File string `json:"file" jsonschema:"File path relative to project root"`
}

GetImportsArgs defines the input parameters for codeindex_ast_get_imports.

type GoExtractor

type GoExtractor struct{}

GoExtractor extracts symbols from Go source files using go/parser. No CGo required — uses the Go standard library only.

func (*GoExtractor) Extensions

func (e *GoExtractor) Extensions() []string

func (*GoExtractor) ExtractSymbols

func (e *GoExtractor) ExtractSymbols(filePath string, source []byte) ([]*Symbol, []string, error)

ExtractSymbols parses a Go source file and returns all top-level symbols.

func (*GoExtractor) Language

func (e *GoExtractor) Language() string

type LanguageExtractor

type LanguageExtractor interface {
	// Extensions returns the file extensions this extractor handles (e.g. [".go"]).
	Extensions() []string
	// Language returns the canonical language name (e.g. "go", "typescript").
	Language() string
	// ExtractSymbols parses source bytes and returns all symbols and import paths found.
	ExtractSymbols(filePath string, source []byte) (symbols []*Symbol, imports []string, err error)
}

LanguageExtractor parses source files and extracts code symbols.

Two implementation families:

  • GoExtractor: uses go/parser from the standard library (no CGo)
  • TypeScriptExtractor, PythonExtractor, JavaScriptExtractor: use tree-sitter (CGo)

type Module

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

Module is the AST indexing module. It parses source files, maintains a SymbolTable, and registers 5 MCP tools with the codeindex_ast_ prefix. Module is nil-safe — all methods on a nil *Module are no-ops.

func NewModule

func NewModule(config ModuleConfig, logger *slog.Logger) *Module

NewModule creates a new AST module with the given configuration.

func (*Module) OnFileChanged

func (m *Module) OnFileChanged(relativePath string, content []byte)

OnFileChanged parses the file and updates the symbol table. content must be the already-read file bytes (no re-read inside this call). Safe to call on a nil *Module.

func (*Module) OnFileRemoved

func (m *Module) OnFileRemoved(relativePath string)

OnFileRemoved removes all symbols for a deleted or renamed file. Safe to call on a nil *Module.

func (*Module) RegisterTools

func (m *Module) RegisterTools(mcpServer *mcp.Server)

RegisterTools adds AST MCP tools to the server. Called from server/server.go:Setup when module is non-nil.

type ModuleConfig

type ModuleConfig struct {
	Languages        []string // enabled language names: ["go", "typescript", "python", "javascript"]
	MaxFileSizeBytes int64    // skip files larger than this
}

ModuleConfig holds configuration for the AST module.

type SearchSymbolsArgs

type SearchSymbolsArgs struct {
	Query    string `json:"query" jsonschema:"Symbol name or partial name (case-insensitive substring match)"`
	Kind     string `` /* 156-byte string literal not displayed */
	Language string `json:"language,omitempty" jsonschema:"Optional: filter by language (go, typescript, python, javascript)"`
	Limit    int    `json:"limit,omitempty" jsonschema:"Max results (default: 20, max: 100)"`
}

SearchSymbolsArgs defines the input parameters for codeindex_ast_search_symbols.

type StatsArgs

type StatsArgs struct{}

StatsArgs defines the input parameters for codeindex_ast_stats (none required).

type Symbol

type Symbol struct {
	Name       string
	Kind       SymbolKind
	File       string // relative path with forward slashes
	Line       int    // 1-indexed start line
	EndLine    int    // 1-indexed end line
	Column     int    // 0-indexed start column
	Language   string // "go", "typescript", "python", "javascript"
	Parent     string // containing class/struct name, empty if top-level
	Signature  string // e.g. "func Foo(x int) error"
	Visibility string // "public" or "private"
	DocComment string // doc comment above the symbol
}

Symbol represents a code symbol extracted from a source file.

type SymbolKind

type SymbolKind int

SymbolKind classifies a code symbol.

const (
	SymbolClass     SymbolKind = iota
	SymbolInterface SymbolKind = iota
	SymbolEnum      SymbolKind = iota
	SymbolFunction  SymbolKind = iota
	SymbolMethod    SymbolKind = iota
	SymbolField     SymbolKind = iota
	SymbolVariable  SymbolKind = iota
	SymbolConstant  SymbolKind = iota
	SymbolImport    SymbolKind = iota
	SymbolTypeAlias SymbolKind = iota
)

func KindFromString

func KindFromString(s string) (SymbolKind, bool)

KindFromString parses a kind name string into a SymbolKind. Returns (kind, true) on success, (0, false) if unknown.

type SymbolTable

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

SymbolTable is the in-memory AST index. Thread-safe via sync.RWMutex. No allSymbols flat list — iterate byFile values for full scans.

func NewSymbolTable

func NewSymbolTable() *SymbolTable

NewSymbolTable creates an empty SymbolTable.

func (*SymbolTable) GetByFile

func (t *SymbolTable) GetByFile(path string) []*Symbol

GetByFile returns all symbols in a file. Acquires read lock.

func (*SymbolTable) GetImports

func (t *SymbolTable) GetImports(path string) []string

GetImports returns the import paths of a file. Acquires read lock.

func (*SymbolTable) RemoveFile

func (t *SymbolTable) RemoveFile(path string)

RemoveFile removes all symbols for a deleted or renamed file. Acquires write lock.

func (*SymbolTable) SearchByName

func (t *SymbolTable) SearchByName(query string, kind *SymbolKind, language string, limit int) []*Symbol

SearchByName returns symbols whose name contains query (case-insensitive substring). Optional kind and language filters. Acquires read lock.

func (*SymbolTable) Stats

func (t *SymbolTable) Stats() AstStats

Stats returns index statistics. Acquires read lock.

func (*SymbolTable) UpdateFile

func (t *SymbolTable) UpdateFile(path string, symbols []*Symbol, fileImports []string)

UpdateFile atomically replaces all symbols for a file. Removes old entries, inserts new ones. Acquires write lock.

Jump to

Keyboard shortcuts

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