Documentation
¶
Overview ¶
Package index implements ForgeADE Workspace Index (FWI): a lightweight indexing engine for editor features (go-to-definition, completion, outline) without depending on LSP or AI. It does no type checking or semantic analysis — those stay in the LSP domain.
Index ¶
- func Register(p Parser)
- type DepSym
- type Export
- type File
- type FuncReturn
- type Import
- type Index
- type Language
- type NewExpr
- type ParseResult
- type Parser
- type Scanner
- type Store
- func (s *Store) Build() error
- func (s *Store) BuildContext(ctx context.Context) error
- func (s *Store) Completion(prefix string, lang Language, path string) []Symbol
- func (s *Store) Definition(name string) []Symbol
- func (s *Store) Exports(file string) []Export
- func (s *Store) Find(name string) []Symbol
- func (s *Store) Imports(file string) []Import
- func (s *Store) LanguageStats() (filesByLang, symsByLang map[string]int)
- func (s *Store) Listen(bus *events.Bus) func()
- func (s *Store) Load() error
- func (s *Store) Members(instance, lang string) []Symbol
- func (s *Store) Outline(file string) []Symbol
- func (s *Store) Remove(path string) error
- func (s *Store) Root() string
- func (s *Store) Save() error
- func (s *Store) Search(query string) []Symbol
- func (s *Store) SnapshotDir() string
- func (s *Store) Symbols() []Symbol
- func (s *Store) Update(path string) error
- type Symbol
- type SymbolKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DepSym ¶
type DepSym struct {
Name string
Kind SymbolKind
Line int
}
DepSym is one exported name pulled from a dependency .d.ts.
type FuncReturn ¶
type FuncReturn struct {
Name string
Class string // return new Foo()
Keys []string // return { a, b }
Line int
}
FuncReturn records the shape a function returns: `return { ... }` or `return new Foo()` (RFC §7 functional-programming member completion).
type Import ¶
type Import struct {
FileID uint32
Path string // module path or relative path
Names []string
Line int
Column int
}
Import is one import/require statement in a file (RFC §5.3).
type Index ¶
type Index interface {
Build() error
Update(file string) error
Remove(file string) error
Symbols() []Symbol
Find(name string) []Symbol
Definition(name string) []Symbol
Completion(prefix string) []Symbol
}
Index is the public FWI API (RFC §18).
type Language ¶
type Language string
Language identifies a programming language (RFC §6).
const ( LangJavaScript Language = "javascript" LangTypeScript Language = "typescript" LangJSX Language = "jsx" LangTSX Language = "tsx" LangGo Language = "go" LangKotlin Language = "kotlin" LangSwift Language = "swift" LangPython Language = "python" LangJava Language = "java" LangDart Language = "dart" )
func DetectLanguage ¶
DetectLanguage maps a file path to a language, or "" if unsupported.
type NewExpr ¶
type NewExpr struct {
Name string // instance variable name
Class string // `new Foo()` or `: Foo` type annotation
Fn string // `foo()` call → look up foo's return shape
Keys []string // `{ a, b }` object literal keys (top level)
Sub map[string][]string // dotted subpath → keys, e.g. {"a":["b"], "a.b":["c"], "list[0]":["x"]}
Alias string // `x = otherVar` → follow otherVar's binding
Line int
}
NewExpr records what a `var x = ...` binding refers to, for member completion after `x.` (RFC §7). Only one of Class/Fn/Keys/Alias is set.
type ParseResult ¶
type ParseResult struct {
Symbols []Symbol
Imports []Import
Exports []Export
NewExprs []NewExpr // var bindings for member completion
FuncReturn []FuncReturn // function return shapes for member completion
Hash uint64
}
ParseResult is what a Parser produces for a single file. Only symbols are stored in the index; AST is not retained (RFC §5.3).
type Parser ¶
type Parser interface {
Language() Language
Parse(src []byte, file *File) (*ParseResult, error)
}
Parser extracts symbols, imports and exports from a single source file (RFC §5.3). Parsers must be stateless: Parse may be called concurrently. New languages plug in via Register without touching the core indexer.
type Scanner ¶
type Scanner struct {
// Root is the workspace directory to scan.
Root string
// Ignore adds extra directories (by base name) on top of defaults.
Ignore map[string]bool
}
Scanner walks a workspace and yields source files (RFC §5.1). It only produces a list of files; parsing happens elsewhere.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is an in-memory workspace index with optional snapshot persistence (RFC §10). It is safe for concurrent use.
func (*Store) Build ¶
Build performs a full scan-and-index of the workspace (RFC §5.1). Files are parsed by a worker pool sized to the CPU count (RFC §21).
func (*Store) BuildContext ¶
BuildContext performs a full scan-and-index of the workspace with cancellation support.
func (*Store) Completion ¶
func (*Store) Definition ¶
Definition returns the declaration sites for name (RFC §18).
func (*Store) LanguageStats ¶
LanguageStats groups indexed files and symbols by language.
func (*Store) Listen ¶
Listen subscribes the store to workspace file events so the index stays in sync without full rescans (RFC §5.2): CREATE/UPDATE → parse & replace, DELETE → remove. Returns an unsubscribe function.
func (*Store) Outline ¶
Outline returns the symbols declared in a single file, sorted by line (RFC §14).
func (*Store) Search ¶
Search returns symbols matching query using exact, prefix, camel-case and fuzzy matching, most precise first (RFC §15).
func (*Store) SnapshotDir ¶
SnapshotDir is where the index persists state (RFC §17) — globally under ~/.forge/index/<project> so no .workspace/ directory leaks into the workspace root. Legacy <root>/.workspace still loads via Load's fallback.
type Symbol ¶
type Symbol struct {
ID string
Name string
Kind SymbolKind
FileID uint32
File string
Line int
Column int
EndLine int
EndColumn int
Scope string // enclosing declaration name; empty at top level
Exported bool
Module string // non-empty = dependency export; import specifier e.g. "react"
}
Symbol is a single indexed declaration (RFC §7).
type SymbolKind ¶
type SymbolKind int
SymbolKind categorizes a symbol (RFC §7).
const ( Function SymbolKind = iota Class Interface Enum Struct TypeAlias Variable Constant Method Package )
func (SymbolKind) String ¶
func (k SymbolKind) String() string
String returns the stable lowercase name of the kind.