/** * Position-based CST node lookup. * * Given a cursor position (line, column), finds the deepest CST node * and token at that position. This is the foundation for all LSP features * that need context at the cursor: hover, go-to-definition, completion, * signature help, rename, references. */ import { SyntaxNode } from '../syntaxNode.js'; import { Token } from '../token.js'; import { Trivia } from '../trivia.js'; export interface NodeAtPosition { /** The deepest SyntaxNode containing the position. */ node: SyntaxNode; /** The specific token at the position, if any. */ token: Token | undefined; /** The chain of ancestor nodes from root to the deepest node. */ ancestors: SyntaxNode[]; /** * The trivia piece (comment/whitespace) containing the position, if the * position falls inside a token's leading trivia rather than the token * itself — e.g. the cursor sitting inside a `' @import ...` comment. */ trivia: Trivia | undefined; } /** * Finds the deepest CST node at the given line and column. * * @param root - The root SourceFile node. * @param line - 0-based line number. * @param column - 0-based column (character offset within line). * @returns The node, token, and ancestor chain at the position, or null if not found. */ export declare function findNodeAtPosition(root: SyntaxNode, line: number, column: number): NodeAtPosition | null; /** * Finds the token at the given line and column by scanning all tokens. * Simpler than findNodeAtPosition — just returns the token, no ancestors. */ export declare function findTokenAtPosition(root: SyntaxNode, line: number, column: number): Token | undefined; /** * Gets the identifier word at the given position in a line of text. * Returns the word and its start/end columns, or null if not on an identifier. * * This replaces the regex-based `getWord` / `getWordInfo` in textUtils. */ export declare function getWordAtPosition(line: string, column: number): { word: string; start: number; end: number; } | null; /** * Escapes special regex characters in a string. * Shared utility used by linter rules and LSP providers. */ export declare function escapeRegex(str: string): string; export interface PositionIndex { /** Every token in the tree, in document order. */ readonly tokens: readonly Token[]; /** tokens[lineStarts[L]] is the first token on line L or later (sparse lines fall through to the next line that has one). */ readonly lineStarts: readonly number[]; } /** Builds a `PositionIndex` for `root`. Call once per parse and reuse across lookups. */ export declare function buildPositionIndex(root: SyntaxNode): PositionIndex; /** * Indexed equivalent of `findTokenAtPosition` — O(tokens on that line) * instead of O(n) once `index` is built. */ export declare function findTokenAtPositionIndexed(index: PositionIndex, line: number, column: number): Token | undefined; /** * Indexed equivalent of `findNodeAtPosition`. Ancestor chains are recovered * by walking `Token.parent` upward (O(depth)) rather than a fresh tree walk * — see `Token.parent`'s doc comment for why that's available at all. * Falls back to the token before/after the given line for trivia (comment) * hits, matching `findNodeAtPosition`'s leading/trailing trivia check. */ export declare function findNodeAtPositionIndexed(index: PositionIndex, line: number, column: number): NodeAtPosition | null; export interface SymbolIndex { /** Every named function/sub declaration in the file, keyed by lowercased name. Last declaration wins on a duplicate name, same as re-declaring a variable. */ readonly functions: ReadonlyMap; } /** * Builds a name → `FunctionDeclaration` node index for `root` in a single * pass. Lets a caller resolve "the function named X" in O(1) instead of a * fresh tree walk per lookup (what `getSymbolInfo` and `buildCallGraph` * currently each do on their own). Reuse across many lookups against the * same parse. */ export declare function buildSymbolIndex(root: SyntaxNode): SymbolIndex; //# sourceMappingURL=position.d.ts.map