/** * SMI-1309: Incremental Parsing Support * * Edit tracking utilities for multi-language AST analysis. * Enables efficient incremental parsing by detecting minimal * edit regions between old and new content. * * @see docs/internal/architecture/multi-language-analysis.md * @module analysis/incremental */ /** * Position in source code (row/column) * * Matches tree-sitter Point interface for compatibility. */ export interface Point { /** Zero-based line number */ row: number; /** Zero-based column offset (byte offset within line) */ column: number; } /** * File edit information for incremental parsing * * Contains all information needed by tree-sitter's * incremental parsing API to update an existing tree. */ export interface FileEdit { /** Byte offset where the edit starts */ startIndex: number; /** Byte offset where the old content ends */ oldEndIndex: number; /** Byte offset where the new content ends */ newEndIndex: number; /** Position (row/column) where edit starts */ startPosition: Point; /** Position where old content ended */ oldEndPosition: Point; /** Position where new content ends */ newEndPosition: Point; } /** * Simple edit diff result * * Represents the minimal change between two strings. */ export interface EditDiff { /** Index where the change starts */ changeStart: number; /** Index where old content ends (exclusive) */ changeEnd: number; /** New text that replaces [changeStart, changeEnd) */ newText: string; } /** * Calculate file edit from content diff * * Converts a simple diff into the format required by * tree-sitter's incremental parsing API. * * @param oldContent - Original file content * @param newContent - Updated file content * @param changeStart - Start index of the change * @param changeEnd - End index in old content * @param newText - Replacement text * @returns FileEdit structure for tree-sitter * * @example * ```typescript * const edit = calculateEdit( * 'hello world', * 'hello there world', * 6, // after 'hello ' * 6, // no text removed * 'there ' // inserted text * ) * tree.edit(edit) * ``` */ export declare function calculateEdit(oldContent: string, newContent: string, changeStart: number, changeEnd: number, newText: string): FileEdit; /** * Convert byte index to row/column position * * Scans through content counting newlines to determine * the row and column for a given byte offset. * * @param content - File content to scan * @param index - Byte offset to convert * @returns Position with row and column (both zero-based) * * @example * ```typescript * const pos = indexToPosition('hello\nworld', 8) * // pos = { row: 1, column: 2 } (the 'r' in 'world') * ``` */ export declare function indexToPosition(content: string, index: number): Point; /** * Convert row/column position to byte index * * Scans through content to find the byte offset for * a given row and column position. * * @param content - File content to scan * @param position - Position to convert * @returns Byte offset, or content length if position is past end * * @example * ```typescript * const index = positionToIndex('hello\nworld', { row: 1, column: 2 }) * // index = 8 (the 'r' in 'world') * ``` */ export declare function positionToIndex(content: string, position: Point): number; /** * Find the minimal edit between two strings * * Uses a simple prefix/suffix matching algorithm to find * the smallest region that changed between old and new content. * Returns null if contents are identical. * * @param oldContent - Original string * @param newContent - Modified string * @returns EditDiff describing the change, or null if identical * * @example * ```typescript * const diff = findMinimalEdit('hello world', 'hello there world') * // diff = { changeStart: 6, changeEnd: 6, newText: 'there ' } * * const same = findMinimalEdit('hello', 'hello') * // same = null * ``` */ export declare function findMinimalEdit(oldContent: string, newContent: string): EditDiff | null; /** * Merge multiple edits into a single encompassing edit * * Useful when multiple small edits occur and need to be * applied as a single incremental update. * * Note: This is a simplistic merge that finds the bounding * region. It may over-invalidate if edits are far apart. * * @param edits - Array of edits to merge * @returns Single merged edit, or null if array is empty * * @example * ```typescript * const merged = batchEdits([ * { changeStart: 0, changeEnd: 5, newText: 'HELLO' }, * { changeStart: 10, changeEnd: 15, newText: 'WORLD' } * ]) * // merged encompasses both edit regions * ``` */ export declare function batchEdits(edits: EditDiff[]): EditDiff | null; /** * Check if an edit is a simple insertion (no deletion) * * @param edit - Edit to check * @returns True if edit only inserts text */ export declare function isInsertion(edit: EditDiff): boolean; /** * Check if an edit is a simple deletion (no insertion) * * @param edit - Edit to check * @returns True if edit only deletes text */ export declare function isDeletion(edit: EditDiff): boolean; /** * Check if an edit is a replacement (both deletion and insertion) * * @param edit - Edit to check * @returns True if edit replaces text */ export declare function isReplacement(edit: EditDiff): boolean; /** * Calculate the size delta of an edit * * @param edit - Edit to analyze * @returns Positive for growth, negative for shrinkage, zero for same size */ export declare function editSizeDelta(edit: EditDiff): number; //# sourceMappingURL=incremental.d.ts.map