rawsql-ts 0.11.33-beta → 0.11.34-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.js +19 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +43 -35
- package/dist/esm/index.min.js.map +4 -4
- package/dist/esm/src/index.d.ts +21 -0
- package/dist/esm/src/index.js +19 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/tokenReaders/CommandTokenReader.js +5 -0
- package/dist/esm/src/tokenReaders/CommandTokenReader.js.map +1 -1
- package/dist/esm/src/transformers/CTEBuilder.js +2 -2
- package/dist/esm/src/transformers/CTEBuilder.js.map +1 -1
- package/dist/esm/src/utils/CursorContextAnalyzer.d.ts +70 -0
- package/dist/esm/src/utils/CursorContextAnalyzer.js +322 -0
- package/dist/esm/src/utils/CursorContextAnalyzer.js.map +1 -0
- package/dist/esm/src/utils/IntelliSenseApi.d.ts +114 -0
- package/dist/esm/src/utils/IntelliSenseApi.js +284 -0
- package/dist/esm/src/utils/IntelliSenseApi.js.map +1 -0
- package/dist/esm/src/utils/KeywordCache.d.ts +65 -0
- package/dist/esm/src/utils/KeywordCache.js +202 -0
- package/dist/esm/src/utils/KeywordCache.js.map +1 -0
- package/dist/esm/src/utils/MultiQuerySplitter.d.ts +131 -0
- package/dist/esm/src/utils/MultiQuerySplitter.js +287 -0
- package/dist/esm/src/utils/MultiQuerySplitter.js.map +1 -0
- package/dist/esm/src/utils/PositionAwareParser.d.ts +85 -0
- package/dist/esm/src/utils/PositionAwareParser.js +336 -0
- package/dist/esm/src/utils/PositionAwareParser.js.map +1 -0
- package/dist/esm/src/utils/ScopeResolver.d.ts +127 -0
- package/dist/esm/src/utils/ScopeResolver.js +268 -0
- package/dist/esm/src/utils/ScopeResolver.js.map +1 -0
- package/dist/esm/src/utils/TextPositionUtils.d.ts +62 -0
- package/dist/esm/src/utils/TextPositionUtils.js +124 -0
- package/dist/esm/src/utils/TextPositionUtils.js.map +1 -0
- package/dist/esm/tsconfig.browser.tsbuildinfo +1 -1
- package/dist/index.min.js +43 -35
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +21 -0
- package/dist/src/index.js +20 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/tokenReaders/CommandTokenReader.js +5 -0
- package/dist/src/tokenReaders/CommandTokenReader.js.map +1 -1
- package/dist/src/transformers/CTEBuilder.js +2 -2
- package/dist/src/transformers/CTEBuilder.js.map +1 -1
- package/dist/src/utils/CursorContextAnalyzer.d.ts +70 -0
- package/dist/src/utils/CursorContextAnalyzer.js +338 -0
- package/dist/src/utils/CursorContextAnalyzer.js.map +1 -0
- package/dist/src/utils/IntelliSenseApi.d.ts +114 -0
- package/dist/src/utils/IntelliSenseApi.js +292 -0
- package/dist/src/utils/IntelliSenseApi.js.map +1 -0
- package/dist/src/utils/KeywordCache.d.ts +65 -0
- package/dist/src/utils/KeywordCache.js +206 -0
- package/dist/src/utils/KeywordCache.js.map +1 -0
- package/dist/src/utils/MultiQuerySplitter.d.ts +131 -0
- package/dist/src/utils/MultiQuerySplitter.js +292 -0
- package/dist/src/utils/MultiQuerySplitter.js.map +1 -0
- package/dist/src/utils/PositionAwareParser.d.ts +85 -0
- package/dist/src/utils/PositionAwareParser.js +363 -0
- package/dist/src/utils/PositionAwareParser.js.map +1 -0
- package/dist/src/utils/ScopeResolver.d.ts +127 -0
- package/dist/src/utils/ScopeResolver.js +272 -0
- package/dist/src/utils/ScopeResolver.js.map +1 -0
- package/dist/src/utils/TextPositionUtils.d.ts +62 -0
- package/dist/src/utils/TextPositionUtils.js +128 -0
- package/dist/src/utils/TextPositionUtils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -0,0 +1,114 @@
|
|
1
|
+
import { IntelliSenseContext } from './CursorContextAnalyzer';
|
2
|
+
import { ScopeInfo } from './ScopeResolver';
|
3
|
+
import { ParseToPositionOptions, PositionParseResult } from './PositionAwareParser';
|
4
|
+
import { QueryCollection } from './MultiQuerySplitter';
|
5
|
+
import { LineColumn } from './LexemeCursor';
|
6
|
+
/**
|
7
|
+
* Convenience API for SQL IntelliSense integration
|
8
|
+
*
|
9
|
+
* Provides simplified, high-level functions that combine the functionality
|
10
|
+
* of the various position-aware parsing components for easy integration
|
11
|
+
* with Monaco Editor and other code editors.
|
12
|
+
*
|
13
|
+
* @example
|
14
|
+
* ```typescript
|
15
|
+
* import { parseToPosition, getCursorContext, resolveScope, splitQueries } from 'rawsql-ts';
|
16
|
+
*
|
17
|
+
* // Parse incomplete SQL with error recovery
|
18
|
+
* const sql = "SELECT u.name FROM users u WHERE u.";
|
19
|
+
* const parseResult = parseToPosition(sql, sql.length, { errorRecovery: true });
|
20
|
+
*
|
21
|
+
* // Get cursor context for completion suggestions
|
22
|
+
* const context = getCursorContext(sql, sql.length);
|
23
|
+
* console.log(context.isAfterDot); // true
|
24
|
+
* console.log(context.precedingIdentifier); // "u"
|
25
|
+
*
|
26
|
+
* // Get scope information for table/column completion
|
27
|
+
* const scope = resolveScope(sql, sql.length);
|
28
|
+
* console.log(scope.availableTables); // [{ name: 'users', alias: 'u' }]
|
29
|
+
*
|
30
|
+
* // Handle multi-query editor
|
31
|
+
* const multiSQL = "SELECT 1; SELECT 2;";
|
32
|
+
* const queries = splitQueries(multiSQL);
|
33
|
+
* const activeQuery = queries.getActive(12); // Get query at position
|
34
|
+
* ```
|
35
|
+
*/
|
36
|
+
/**
|
37
|
+
* Parse SQL up to cursor position with error recovery
|
38
|
+
*
|
39
|
+
* Combines position-aware parsing with error recovery to handle incomplete SQL
|
40
|
+
* that users are actively typing. Ideal for providing IntelliSense in editors.
|
41
|
+
*
|
42
|
+
* @param sql - SQL text to parse
|
43
|
+
* @param cursorPosition - Cursor position (character offset or line/column)
|
44
|
+
* @param options - Parsing options including error recovery settings
|
45
|
+
* @returns Parse result with position-specific information
|
46
|
+
*/
|
47
|
+
export declare function parseToPosition(sql: string, cursorPosition: number | LineColumn, options?: ParseToPositionOptions): PositionParseResult;
|
48
|
+
/**
|
49
|
+
* Analyze cursor context for IntelliSense completion suggestions
|
50
|
+
*
|
51
|
+
* Determines what type of completions should be offered at the cursor position
|
52
|
+
* based on SQL syntax context (SELECT clause, WHERE condition, etc.).
|
53
|
+
*
|
54
|
+
* @param sql - SQL text to analyze
|
55
|
+
* @param cursorPosition - Cursor position (character offset or line/column)
|
56
|
+
* @returns Cursor context information for completion logic
|
57
|
+
*/
|
58
|
+
export declare function getCursorContext(sql: string, cursorPosition: number | LineColumn): IntelliSenseContext;
|
59
|
+
/**
|
60
|
+
* Resolve scope information at cursor position
|
61
|
+
*
|
62
|
+
* Provides comprehensive information about available tables, CTEs, and columns
|
63
|
+
* at the specified cursor position for intelligent completion suggestions.
|
64
|
+
*
|
65
|
+
* @param sql - SQL text to analyze
|
66
|
+
* @param cursorPosition - Cursor position (character offset or line/column)
|
67
|
+
* @returns Complete scope information including available tables and columns
|
68
|
+
*/
|
69
|
+
export declare function resolveScope(sql: string, cursorPosition: number | LineColumn): ScopeInfo;
|
70
|
+
/**
|
71
|
+
* Split multi-query SQL text into individual queries
|
72
|
+
*
|
73
|
+
* Handles SQL editors that contain multiple statements separated by semicolons.
|
74
|
+
* Properly handles string literals and comments containing semicolons.
|
75
|
+
*
|
76
|
+
* @param sql - Multi-query SQL text
|
77
|
+
* @returns Collection of individual queries with position information
|
78
|
+
*/
|
79
|
+
export declare function splitQueries(sql: string): QueryCollection;
|
80
|
+
/**
|
81
|
+
* Get IntelliSense information for a cursor position in multi-query context
|
82
|
+
*
|
83
|
+
* Combines query splitting, context analysis, and scope resolution to provide
|
84
|
+
* complete IntelliSense information for a cursor position in multi-query SQL.
|
85
|
+
*
|
86
|
+
* @param sql - Multi-query SQL text
|
87
|
+
* @param cursorPosition - Cursor position
|
88
|
+
* @param options - Parsing options
|
89
|
+
* @returns Complete IntelliSense information or undefined if position is invalid
|
90
|
+
*/
|
91
|
+
export declare function getIntelliSenseInfo(sql: string, cursorPosition: number | LineColumn, options?: ParseToPositionOptions): {
|
92
|
+
context: IntelliSenseContext;
|
93
|
+
scope: ScopeInfo;
|
94
|
+
parseResult: PositionParseResult;
|
95
|
+
currentQuery: string;
|
96
|
+
relativePosition: number;
|
97
|
+
} | undefined;
|
98
|
+
/**
|
99
|
+
* Get completion suggestions based on cursor context and scope
|
100
|
+
*
|
101
|
+
* Uses the new IntelliSense interface to provide targeted completion suggestions.
|
102
|
+
* This function leverages the suggestion-based design to efficiently determine
|
103
|
+
* what completions should be offered.
|
104
|
+
*
|
105
|
+
* @param sql - SQL text
|
106
|
+
* @param cursorPosition - Cursor position
|
107
|
+
* @returns Array of completion suggestions with context information
|
108
|
+
*/
|
109
|
+
export declare function getCompletionSuggestions(sql: string, cursorPosition: number | LineColumn): Array<{
|
110
|
+
type: 'keyword' | 'table' | 'column' | 'cte' | 'function';
|
111
|
+
value: string;
|
112
|
+
detail?: string;
|
113
|
+
documentation?: string;
|
114
|
+
}>;
|
@@ -0,0 +1,292 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.parseToPosition = parseToPosition;
|
4
|
+
exports.getCursorContext = getCursorContext;
|
5
|
+
exports.resolveScope = resolveScope;
|
6
|
+
exports.splitQueries = splitQueries;
|
7
|
+
exports.getIntelliSenseInfo = getIntelliSenseInfo;
|
8
|
+
exports.getCompletionSuggestions = getCompletionSuggestions;
|
9
|
+
const CursorContextAnalyzer_1 = require("./CursorContextAnalyzer");
|
10
|
+
const ScopeResolver_1 = require("./ScopeResolver");
|
11
|
+
const PositionAwareParser_1 = require("./PositionAwareParser");
|
12
|
+
const MultiQuerySplitter_1 = require("./MultiQuerySplitter");
|
13
|
+
const TextPositionUtils_1 = require("./TextPositionUtils");
|
14
|
+
/**
|
15
|
+
* Convenience API for SQL IntelliSense integration
|
16
|
+
*
|
17
|
+
* Provides simplified, high-level functions that combine the functionality
|
18
|
+
* of the various position-aware parsing components for easy integration
|
19
|
+
* with Monaco Editor and other code editors.
|
20
|
+
*
|
21
|
+
* @example
|
22
|
+
* ```typescript
|
23
|
+
* import { parseToPosition, getCursorContext, resolveScope, splitQueries } from 'rawsql-ts';
|
24
|
+
*
|
25
|
+
* // Parse incomplete SQL with error recovery
|
26
|
+
* const sql = "SELECT u.name FROM users u WHERE u.";
|
27
|
+
* const parseResult = parseToPosition(sql, sql.length, { errorRecovery: true });
|
28
|
+
*
|
29
|
+
* // Get cursor context for completion suggestions
|
30
|
+
* const context = getCursorContext(sql, sql.length);
|
31
|
+
* console.log(context.isAfterDot); // true
|
32
|
+
* console.log(context.precedingIdentifier); // "u"
|
33
|
+
*
|
34
|
+
* // Get scope information for table/column completion
|
35
|
+
* const scope = resolveScope(sql, sql.length);
|
36
|
+
* console.log(scope.availableTables); // [{ name: 'users', alias: 'u' }]
|
37
|
+
*
|
38
|
+
* // Handle multi-query editor
|
39
|
+
* const multiSQL = "SELECT 1; SELECT 2;";
|
40
|
+
* const queries = splitQueries(multiSQL);
|
41
|
+
* const activeQuery = queries.getActive(12); // Get query at position
|
42
|
+
* ```
|
43
|
+
*/
|
44
|
+
/**
|
45
|
+
* Parse SQL up to cursor position with error recovery
|
46
|
+
*
|
47
|
+
* Combines position-aware parsing with error recovery to handle incomplete SQL
|
48
|
+
* that users are actively typing. Ideal for providing IntelliSense in editors.
|
49
|
+
*
|
50
|
+
* @param sql - SQL text to parse
|
51
|
+
* @param cursorPosition - Cursor position (character offset or line/column)
|
52
|
+
* @param options - Parsing options including error recovery settings
|
53
|
+
* @returns Parse result with position-specific information
|
54
|
+
*/
|
55
|
+
function parseToPosition(sql, cursorPosition, options = {}) {
|
56
|
+
return PositionAwareParser_1.PositionAwareParser.parseToPosition(sql, cursorPosition, options);
|
57
|
+
}
|
58
|
+
/**
|
59
|
+
* Analyze cursor context for IntelliSense completion suggestions
|
60
|
+
*
|
61
|
+
* Determines what type of completions should be offered at the cursor position
|
62
|
+
* based on SQL syntax context (SELECT clause, WHERE condition, etc.).
|
63
|
+
*
|
64
|
+
* @param sql - SQL text to analyze
|
65
|
+
* @param cursorPosition - Cursor position (character offset or line/column)
|
66
|
+
* @returns Cursor context information for completion logic
|
67
|
+
*/
|
68
|
+
function getCursorContext(sql, cursorPosition) {
|
69
|
+
if (typeof cursorPosition === 'number') {
|
70
|
+
return CursorContextAnalyzer_1.CursorContextAnalyzer.analyzeIntelliSense(sql, cursorPosition);
|
71
|
+
}
|
72
|
+
else {
|
73
|
+
return CursorContextAnalyzer_1.CursorContextAnalyzer.analyzeIntelliSenseAt(sql, cursorPosition);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
/**
|
77
|
+
* Resolve scope information at cursor position
|
78
|
+
*
|
79
|
+
* Provides comprehensive information about available tables, CTEs, and columns
|
80
|
+
* at the specified cursor position for intelligent completion suggestions.
|
81
|
+
*
|
82
|
+
* @param sql - SQL text to analyze
|
83
|
+
* @param cursorPosition - Cursor position (character offset or line/column)
|
84
|
+
* @returns Complete scope information including available tables and columns
|
85
|
+
*/
|
86
|
+
function resolveScope(sql, cursorPosition) {
|
87
|
+
if (typeof cursorPosition === 'number') {
|
88
|
+
return ScopeResolver_1.ScopeResolver.resolve(sql, cursorPosition);
|
89
|
+
}
|
90
|
+
else {
|
91
|
+
return ScopeResolver_1.ScopeResolver.resolveAt(sql, cursorPosition);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
/**
|
95
|
+
* Split multi-query SQL text into individual queries
|
96
|
+
*
|
97
|
+
* Handles SQL editors that contain multiple statements separated by semicolons.
|
98
|
+
* Properly handles string literals and comments containing semicolons.
|
99
|
+
*
|
100
|
+
* @param sql - Multi-query SQL text
|
101
|
+
* @returns Collection of individual queries with position information
|
102
|
+
*/
|
103
|
+
function splitQueries(sql) {
|
104
|
+
return MultiQuerySplitter_1.MultiQuerySplitter.split(sql);
|
105
|
+
}
|
106
|
+
/**
|
107
|
+
* Get IntelliSense information for a cursor position in multi-query context
|
108
|
+
*
|
109
|
+
* Combines query splitting, context analysis, and scope resolution to provide
|
110
|
+
* complete IntelliSense information for a cursor position in multi-query SQL.
|
111
|
+
*
|
112
|
+
* @param sql - Multi-query SQL text
|
113
|
+
* @param cursorPosition - Cursor position
|
114
|
+
* @param options - Parsing options
|
115
|
+
* @returns Complete IntelliSense information or undefined if position is invalid
|
116
|
+
*/
|
117
|
+
function getIntelliSenseInfo(sql, cursorPosition, options = {}) {
|
118
|
+
const charPos = typeof cursorPosition === 'number'
|
119
|
+
? cursorPosition
|
120
|
+
: TextPositionUtils_1.TextPositionUtils.lineColumnToCharOffset(sql, cursorPosition);
|
121
|
+
if (charPos === -1) {
|
122
|
+
return undefined;
|
123
|
+
}
|
124
|
+
// Split queries and find the active one
|
125
|
+
const queries = splitQueries(sql);
|
126
|
+
const activeQuery = queries.getActive(charPos);
|
127
|
+
if (!activeQuery) {
|
128
|
+
return undefined;
|
129
|
+
}
|
130
|
+
// Calculate relative position within the active query
|
131
|
+
const relativePosition = charPos - activeQuery.start;
|
132
|
+
const querySQL = activeQuery.sql;
|
133
|
+
// Get IntelliSense information for the active query
|
134
|
+
const context = getCursorContext(querySQL, relativePosition);
|
135
|
+
const scope = resolveScope(querySQL, relativePosition);
|
136
|
+
const parseResult = parseToPosition(querySQL, relativePosition, options);
|
137
|
+
return {
|
138
|
+
context,
|
139
|
+
scope,
|
140
|
+
parseResult,
|
141
|
+
currentQuery: querySQL,
|
142
|
+
relativePosition
|
143
|
+
};
|
144
|
+
}
|
145
|
+
/**
|
146
|
+
* Get completion suggestions based on cursor context and scope
|
147
|
+
*
|
148
|
+
* Uses the new IntelliSense interface to provide targeted completion suggestions.
|
149
|
+
* This function leverages the suggestion-based design to efficiently determine
|
150
|
+
* what completions should be offered.
|
151
|
+
*
|
152
|
+
* @param sql - SQL text
|
153
|
+
* @param cursorPosition - Cursor position
|
154
|
+
* @returns Array of completion suggestions with context information
|
155
|
+
*/
|
156
|
+
function getCompletionSuggestions(sql, cursorPosition) {
|
157
|
+
const charPos = typeof cursorPosition === 'number'
|
158
|
+
? cursorPosition
|
159
|
+
: TextPositionUtils_1.TextPositionUtils.lineColumnToCharOffset(sql, cursorPosition);
|
160
|
+
if (charPos === -1) {
|
161
|
+
return [];
|
162
|
+
}
|
163
|
+
const intelliSenseContext = CursorContextAnalyzer_1.CursorContextAnalyzer.analyzeIntelliSense(sql, charPos);
|
164
|
+
const scope = resolveScope(sql, cursorPosition);
|
165
|
+
const suggestions = [];
|
166
|
+
// Add keyword suggestions
|
167
|
+
if (intelliSenseContext.suggestKeywords) {
|
168
|
+
// Add required keywords if specified
|
169
|
+
if (intelliSenseContext.requiredKeywords) {
|
170
|
+
intelliSenseContext.requiredKeywords.forEach(keyword => {
|
171
|
+
suggestions.push({
|
172
|
+
type: 'keyword',
|
173
|
+
value: keyword,
|
174
|
+
detail: `Required keyword: ${keyword}`
|
175
|
+
});
|
176
|
+
});
|
177
|
+
}
|
178
|
+
else {
|
179
|
+
// Add general contextual keywords based on token context
|
180
|
+
const generalKeywords = getGeneralKeywords(intelliSenseContext);
|
181
|
+
generalKeywords.forEach(keyword => {
|
182
|
+
suggestions.push({
|
183
|
+
type: 'keyword',
|
184
|
+
value: keyword.value,
|
185
|
+
detail: keyword.detail
|
186
|
+
});
|
187
|
+
});
|
188
|
+
}
|
189
|
+
}
|
190
|
+
// Add table suggestions
|
191
|
+
if (intelliSenseContext.suggestTables) {
|
192
|
+
scope.availableTables.forEach(table => {
|
193
|
+
suggestions.push({
|
194
|
+
type: 'table',
|
195
|
+
value: table.alias || table.name,
|
196
|
+
detail: `Table: ${table.fullName}`,
|
197
|
+
documentation: `Available table${table.alias ? ` (alias: ${table.alias})` : ''}`
|
198
|
+
});
|
199
|
+
});
|
200
|
+
// Add CTE suggestions
|
201
|
+
scope.availableCTEs.forEach(cte => {
|
202
|
+
suggestions.push({
|
203
|
+
type: 'cte',
|
204
|
+
value: cte.name,
|
205
|
+
detail: `CTE: ${cte.name}`,
|
206
|
+
documentation: `Common Table Expression${cte.columns ? ` with columns: ${cte.columns.join(', ')}` : ''}`
|
207
|
+
});
|
208
|
+
});
|
209
|
+
}
|
210
|
+
// Add column suggestions
|
211
|
+
if (intelliSenseContext.suggestColumns) {
|
212
|
+
if (intelliSenseContext.tableScope) {
|
213
|
+
// Specific table/alias column completion
|
214
|
+
const columns = scope.visibleColumns.filter(col => col.tableName === intelliSenseContext.tableScope ||
|
215
|
+
col.tableAlias === intelliSenseContext.tableScope);
|
216
|
+
columns.forEach(col => {
|
217
|
+
suggestions.push({
|
218
|
+
type: 'column',
|
219
|
+
value: col.name,
|
220
|
+
detail: `Column: ${col.fullReference}`,
|
221
|
+
documentation: `Column from ${col.tableName}${col.type ? ` (${col.type})` : ''}`
|
222
|
+
});
|
223
|
+
});
|
224
|
+
}
|
225
|
+
else {
|
226
|
+
// General column completion
|
227
|
+
scope.visibleColumns.forEach(col => {
|
228
|
+
suggestions.push({
|
229
|
+
type: 'column',
|
230
|
+
value: col.name === '*' ? '*' : `${col.tableAlias || col.tableName}.${col.name}`,
|
231
|
+
detail: `Column: ${col.fullReference}`,
|
232
|
+
documentation: `Column from ${col.tableName}`
|
233
|
+
});
|
234
|
+
});
|
235
|
+
}
|
236
|
+
}
|
237
|
+
return suggestions;
|
238
|
+
}
|
239
|
+
/**
|
240
|
+
* Get general keyword suggestions based on IntelliSense context
|
241
|
+
*/
|
242
|
+
function getGeneralKeywords(context) {
|
243
|
+
var _a, _b, _c, _d;
|
244
|
+
// Determine context from token information
|
245
|
+
const prevToken = (_b = (_a = context.previousToken) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
246
|
+
const currentToken = (_d = (_c = context.currentToken) === null || _c === void 0 ? void 0 : _c.value) === null || _d === void 0 ? void 0 : _d.toLowerCase();
|
247
|
+
// SELECT context - aggregate functions and keywords
|
248
|
+
if (prevToken === "select" || currentToken === "select") {
|
249
|
+
return [
|
250
|
+
{ value: "DISTINCT", detail: "Remove duplicate rows" },
|
251
|
+
{ value: "COUNT", detail: "Aggregate function" },
|
252
|
+
{ value: "SUM", detail: "Aggregate function" },
|
253
|
+
{ value: "AVG", detail: "Aggregate function" },
|
254
|
+
{ value: "MAX", detail: "Aggregate function" },
|
255
|
+
{ value: "MIN", detail: "Aggregate function" }
|
256
|
+
];
|
257
|
+
}
|
258
|
+
// FROM context - JOIN options and clauses
|
259
|
+
if (prevToken === "from" || currentToken === "from") {
|
260
|
+
return [
|
261
|
+
{ value: "JOIN", detail: "Inner join tables" },
|
262
|
+
{ value: "LEFT JOIN", detail: "Left outer join" },
|
263
|
+
{ value: "RIGHT JOIN", detail: "Right outer join" },
|
264
|
+
{ value: "FULL JOIN", detail: "Full outer join" },
|
265
|
+
{ value: "WHERE", detail: "Filter conditions" },
|
266
|
+
{ value: "GROUP BY", detail: "Group results" },
|
267
|
+
{ value: "ORDER BY", detail: "Sort results" }
|
268
|
+
];
|
269
|
+
}
|
270
|
+
// WHERE/HAVING context - logical operators
|
271
|
+
if (["where", "having", "on"].includes(prevToken || "") || ["where", "having", "on"].includes(currentToken || "")) {
|
272
|
+
return [
|
273
|
+
{ value: "AND", detail: "Logical AND operator" },
|
274
|
+
{ value: "OR", detail: "Logical OR operator" },
|
275
|
+
{ value: "NOT", detail: "Logical NOT operator" },
|
276
|
+
{ value: "IN", detail: "Match any value in list" },
|
277
|
+
{ value: "LIKE", detail: "Pattern matching" },
|
278
|
+
{ value: "BETWEEN", detail: "Range comparison" }
|
279
|
+
];
|
280
|
+
}
|
281
|
+
// Default context - general SQL keywords
|
282
|
+
return [
|
283
|
+
{ value: "SELECT", detail: "Query data" },
|
284
|
+
{ value: "FROM", detail: "Specify table" },
|
285
|
+
{ value: "WHERE", detail: "Filter conditions" },
|
286
|
+
{ value: "JOIN", detail: "Join tables" },
|
287
|
+
{ value: "GROUP BY", detail: "Group results" },
|
288
|
+
{ value: "ORDER BY", detail: "Sort results" },
|
289
|
+
{ value: "LIMIT", detail: "Limit results" }
|
290
|
+
];
|
291
|
+
}
|
292
|
+
//# sourceMappingURL=IntelliSenseApi.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"IntelliSenseApi.js","sourceRoot":"","sources":["../../../src/utils/IntelliSenseApi.ts"],"names":[],"mappings":";;AAiDA,0CAMC;AAYD,4CASC;AAYD,oCASC;AAWD,oCAEC;AAaD,kDA2CC;AAaD,4DAwGC;AA3RD,mEAAqF;AACrF,mDAA2D;AAC3D,+DAAyG;AACzG,6DAA2E;AAE3E,2DAAwD;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH;;;;;;;;;;GAUG;AACH,SAAgB,eAAe,CAC3B,GAAW,EACX,cAAmC,EACnC,UAAkC,EAAE;IAEpC,OAAO,yCAAmB,CAAC,eAAe,CAAC,GAAG,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;AAC7E,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,gBAAgB,CAC5B,GAAW,EACX,cAAmC;IAEnC,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,6CAAqB,CAAC,mBAAmB,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IAC1E,CAAC;SAAM,CAAC;QACJ,OAAO,6CAAqB,CAAC,qBAAqB,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IAC5E,CAAC;AACL,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,YAAY,CACxB,GAAW,EACX,cAAmC;IAEnC,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,6BAAa,CAAC,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IACtD,CAAC;SAAM,CAAC;QACJ,OAAO,6BAAa,CAAC,SAAS,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,YAAY,CAAC,GAAW;IACpC,OAAO,uCAAkB,CAAC,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,EAAE,SAAS,EAAE,MAAM,EAAE,kBAAkB,EAAE;SACnD,CAAC;IACN,CAAC;IAED,yCAAyC;IACzC,OAAO;QACH,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE;QACzC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE;QAC1C,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE;QAC/C,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE;QACxC,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE;QAC9C,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE;QAC7C,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE;KAC9C,CAAC;AACN,CAAC"}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
/**
|
2
|
+
* Utility for caching keyword relationships for fast access
|
3
|
+
* Dynamically builds keyword relationships from existing joinkeywordParser
|
4
|
+
*
|
5
|
+
* SOURCE DICTIONARIES (single source of truth):
|
6
|
+
* - JOIN patterns: /src/tokenReaders/CommandTokenReader.ts (joinTrie, lines 10-29)
|
7
|
+
* - Command patterns: /src/tokenReaders/CommandTokenReader.ts (keywordTrie, lines 30-118)
|
8
|
+
*
|
9
|
+
* MIGRATION NOTE:
|
10
|
+
* If keywords are added/modified in CommandTokenReader.ts, update the
|
11
|
+
* extractCommandPatternsFromTrie() method to reflect those changes.
|
12
|
+
* JOIN patterns are automatically extracted via joinkeywordParser.
|
13
|
+
*/
|
14
|
+
export declare class KeywordCache {
|
15
|
+
private static joinSuggestionCache;
|
16
|
+
private static commandSuggestionCache;
|
17
|
+
private static initialized;
|
18
|
+
/**
|
19
|
+
* Initialize JOIN-related keyword suggestions
|
20
|
+
* Dynamically generated based on information extracted from joinkeywordParser
|
21
|
+
*/
|
22
|
+
private static initialize;
|
23
|
+
/**
|
24
|
+
* Get next suggestions for the specified keyword
|
25
|
+
* Example: "left" → ["join", "outer", "outer join"]
|
26
|
+
*/
|
27
|
+
static getJoinSuggestions(keyword: string): string[];
|
28
|
+
/**
|
29
|
+
* Check if a keyword is a valid JOIN keyword
|
30
|
+
* Uses existing joinkeywordParser as the primary resource
|
31
|
+
*/
|
32
|
+
static isValidJoinKeyword(keyword: string): boolean;
|
33
|
+
/**
|
34
|
+
* Generate suggestions based on partial keyword input
|
35
|
+
* Example: "le" → find keywords starting with "left"
|
36
|
+
*/
|
37
|
+
static getPartialSuggestions(partialKeyword: string): string[];
|
38
|
+
/**
|
39
|
+
* Get all JOIN keywords
|
40
|
+
*/
|
41
|
+
static getAllJoinKeywords(): string[];
|
42
|
+
/**
|
43
|
+
* Initialize command keyword patterns
|
44
|
+
* Dynamically extracted from commandKeywordTrie
|
45
|
+
*/
|
46
|
+
private static initializeCommandKeywords;
|
47
|
+
/**
|
48
|
+
* Extract multi-word patterns from commandKeywordTrie
|
49
|
+
* Uses known patterns since direct extraction from trie structure is difficult
|
50
|
+
*
|
51
|
+
* SOURCE: /src/tokenReaders/CommandTokenReader.ts keywordTrie (lines 30-118)
|
52
|
+
* MIGRATION: When updating, copy multi-word patterns from the source trie
|
53
|
+
*/
|
54
|
+
private static extractCommandPatternsFromTrie;
|
55
|
+
/**
|
56
|
+
* Get next command suggestions for the specified keyword
|
57
|
+
* Example: "group" → ["by"]
|
58
|
+
*/
|
59
|
+
static getCommandSuggestions(keyword: string): string[];
|
60
|
+
/**
|
61
|
+
* Force cache re-initialization
|
62
|
+
* Used for testing or when keyword definitions have changed
|
63
|
+
*/
|
64
|
+
static reset(): void;
|
65
|
+
}
|