UNPKG

rawsql-ts

Version:

[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.

71 lines (70 loc) 2.67 kB
import { Lexeme } from '../models/Lexeme'; import { LineColumn } from './LexemeCursor'; /** * IntelliSense context focused on what suggestions can be provided */ export interface IntelliSenseContext { /** Whether to suggest table names (can provide actual table list) */ suggestTables: boolean; /** Whether to suggest column names (can provide actual column list) */ suggestColumns: boolean; /** Whether to suggest SQL keywords (can provide keyword list) */ suggestKeywords: boolean; /** If suggesting columns, limit to this table's columns (for table.| syntax) */ tableScope?: string; /** If suggesting keywords, these specific keywords are required */ requiredKeywords?: string[]; /** Token at cursor position (if any) */ currentToken?: Lexeme; /** Token immediately before cursor position */ previousToken?: Lexeme; } export declare class CursorContextAnalyzer { /** * Cache for processed keyword patterns */ private static patternCache; /** * Process existing dictionaries into IntelliSense-friendly patterns * Single source of truth: existing CommandTokenReader dictionaries */ private static getKeywordPatterns; /** * Extract all keyword patterns from the existing dictionaries */ private static extractKeywordPatterns; /** * Check if a keyword exists in the command dictionaries using existing parsers */ private static isKeywordInDictionary; /** * Extract all keywords that require specific followup keywords */ private static extractRequiresKeywordPatterns; /** * Find all possible followup keywords for a given word using KeywordCache */ private static findPossibleFollowups; /** * Helper function to check if a token requires specific keywords */ private static requiresSpecificKeywords; /** * Analyze cursor position for IntelliSense suggestions * * Direct implementation that determines what suggestions can be provided * without legacy context conversion overhead. * * @param sql - SQL text to analyze * @param cursorPosition - Character position (0-based) * @returns IntelliSense context focused on what suggestions can be provided */ static analyzeIntelliSense(sql: string, cursorPosition: number): IntelliSenseContext; /** * Analyze cursor position for IntelliSense at line/column position */ static analyzeIntelliSenseAt(sql: string, position: LineColumn): IntelliSenseContext; private static isAfterDot; private static findPrecedingIdentifier; private static isIdentifier; }