/** * SMI-1309: Incremental Parser Coordinator * * Coordinates incremental parsing across language adapters. * Uses tree caching to enable fast re-parsing when only * small portions of files change. * * Performance target: < 100ms for incremental parse * * @see docs/internal/architecture/multi-language-analysis.md * @module analysis/incremental-parser */ import { TreeCache, type TreeCacheStats } from './tree-cache.js'; import { type FileEdit } from './incremental.js'; import type { ParseResult } from './types.js'; import type { LanguageAdapter } from './adapters/base.js'; /** * Result of an incremental parse operation */ export interface IncrementalParseResult { /** The parse result (imports, exports, functions) */ result: ParseResult; /** True if incremental parsing was used */ wasIncremental: boolean; /** Parse duration in milliseconds */ durationMs: number; /** True if result came from cache */ wasCached: boolean; } /** * Options for IncrementalParser */ export interface IncrementalParserOptions { /** Maximum trees to cache (default: 100) */ maxTrees?: number; /** Enable content caching for unchanged files */ cacheContent?: boolean; } /** * Statistics for incremental parser */ export interface IncrementalParserStats { /** Tree cache statistics */ treeCache: TreeCacheStats; /** Number of files with cached content */ contentCacheSize: number; /** Total incremental parses performed */ incrementalParses: number; /** Total full parses performed */ fullParses: number; /** Average incremental parse time in ms */ avgIncrementalTimeMs: number; /** Average full parse time in ms */ avgFullTimeMs: number; } /** * Incremental parsing coordinator * * Manages tree caching and content tracking to enable efficient * incremental parsing when files change. * * Flow: * 1. Check if content unchanged (return cached result) * 2. Check if previous tree exists for incremental parse * 3. Calculate edit between old and new content * 4. Apply edit to tree and re-parse incrementally * 5. Cache new tree for future updates * * @example * ```typescript * const parser = new IncrementalParser({ maxTrees: 50 }) * const adapter = new TypeScriptAdapter() * * // First parse (full) * const result1 = parser.parse('src/main.ts', content1, adapter) * console.log(result1.wasIncremental) // false * * // Second parse with small change (incremental) * const result2 = parser.parse('src/main.ts', content2, adapter) * console.log(result2.wasIncremental) // true * console.log(result2.durationMs) // < 100ms * * // Cleanup * parser.dispose() * ``` */ export declare class IncrementalParser { private readonly treeCache; private readonly contentCache; private readonly cacheContent; private incrementalParses; private fullParses; private totalIncrementalTime; private totalFullTime; constructor(options?: IncrementalParserOptions); /** * Parse file, using incremental parsing if possible * * Automatically determines whether to use incremental or * full parsing based on cached state. * * @param filePath - Path to the file * @param content - Current file content * @param adapter - Language adapter for parsing * @returns Parse result with metadata */ parse(filePath: string, content: string, adapter: LanguageAdapter): IncrementalParseResult; /** * Parse file with explicit edit information * * Use this when edit information is already available * (e.g., from an editor's change event). * * @param filePath - Path to the file * @param content - Current file content * @param adapter - Language adapter * @param edit - Edit information * @returns Parse result with metadata */ parseWithEdit(filePath: string, content: string, adapter: LanguageAdapter, edit: FileEdit): IncrementalParseResult; /** * Invalidate cache for file(s) * * Call this when files are deleted or externally modified. * * @param filePaths - Path or paths to invalidate */ invalidate(filePaths: string | string[]): void; /** * Invalidate files matching a pattern * * @param pattern - Regex to match file paths * @returns Number of entries invalidated */ invalidatePattern(pattern: RegExp): number; /** * Check if a file is cached * * @param filePath - Path to check * @returns True if content and/or tree is cached */ isCached(filePath: string): boolean; /** * Get cache statistics */ getStats(): IncrementalParserStats; /** * Reset statistics */ resetStats(): void; /** * Clear all caches */ clear(): void; /** * Dispose of all resources * * Call this when the parser is no longer needed. */ dispose(): void; /** * Get the underlying tree cache (for advanced use) */ getTreeCache(): TreeCache; /** * Perform incremental parse */ private doIncrementalParse; /** * Perform full parse */ private doFullParse; /** * Record incremental parse statistics */ private recordIncremental; /** * Record full parse statistics */ private recordFull; /** * Hash content for cache validation */ private hashContent; } //# sourceMappingURL=incremental-parser.d.ts.map