dt-sql-parser 4.1.0-beta.1 → 4.1.0-beta.2
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.
|
@@ -110,6 +110,12 @@ export declare abstract class BasicSQL<L extends Lexer = Lexer, PRC extends Pars
|
|
|
110
110
|
* @param input source string
|
|
111
111
|
*/
|
|
112
112
|
splitSQLByStatement(input: string): TextSlice[] | null;
|
|
113
|
+
/**
|
|
114
|
+
* Get the smaller range of input
|
|
115
|
+
* @param input string
|
|
116
|
+
* @param caretTokenIndex tokenIndex of caretPosition
|
|
117
|
+
* @returns inputSlice: string, caretTokenIndex: number, allTokens: Token[]
|
|
118
|
+
*/
|
|
113
119
|
private splitInputBySeparator;
|
|
114
120
|
/**
|
|
115
121
|
* Get suggestions of syntax and token at caretPosition
|
|
@@ -149,9 +149,15 @@ export class BasicSQL {
|
|
|
149
149
|
.filter(Boolean);
|
|
150
150
|
return res;
|
|
151
151
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Get the smaller range of input
|
|
154
|
+
* @param input string
|
|
155
|
+
* @param caretTokenIndex tokenIndex of caretPosition
|
|
156
|
+
* @returns inputSlice: string, caretTokenIndex: number, allTokens: Token[]
|
|
157
|
+
*/
|
|
158
|
+
splitInputBySeparator(input, caretTokenIndex) {
|
|
159
|
+
var _a, _b, _c;
|
|
160
|
+
const allTokens = this.getAllTokens(input);
|
|
155
161
|
/**
|
|
156
162
|
* set startToken
|
|
157
163
|
*/
|
|
@@ -180,7 +186,20 @@ export class BasicSQL {
|
|
|
180
186
|
if (stopToken === null) {
|
|
181
187
|
stopToken = allTokens[allTokens.length - 1];
|
|
182
188
|
}
|
|
183
|
-
|
|
189
|
+
let startIndex = (_a = startToken === null || startToken === void 0 ? void 0 : startToken.start) !== null && _a !== void 0 ? _a : 0;
|
|
190
|
+
let stopIndex = (_b = (stopToken === null || stopToken === void 0 ? void 0 : stopToken.stop) + 1) !== null && _b !== void 0 ? _b : input.length;
|
|
191
|
+
/**
|
|
192
|
+
* Save offset of the tokenIndex in the range of input
|
|
193
|
+
* compared to the tokenIndex in the whole input
|
|
194
|
+
*/
|
|
195
|
+
const tokenIndexOffset = (_c = startToken === null || startToken === void 0 ? void 0 : startToken.tokenIndex) !== null && _c !== void 0 ? _c : 0;
|
|
196
|
+
const _caretTokenIndex = caretTokenIndex - tokenIndexOffset;
|
|
197
|
+
/**
|
|
198
|
+
* Get the smaller range of _input
|
|
199
|
+
*/
|
|
200
|
+
const _input = input.slice(startIndex, stopIndex);
|
|
201
|
+
const _allTokens = this.getAllTokens(_input);
|
|
202
|
+
return { inputSlice: _input, caretTokenIndex: _caretTokenIndex, allTokens: _allTokens };
|
|
184
203
|
}
|
|
185
204
|
/**
|
|
186
205
|
* Get suggestions of syntax and token at caretPosition
|
|
@@ -189,13 +208,14 @@ export class BasicSQL {
|
|
|
189
208
|
* @returns suggestion
|
|
190
209
|
*/
|
|
191
210
|
getSuggestionAtCaretPosition(input, caretPosition) {
|
|
192
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j
|
|
211
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
193
212
|
const splitListener = this.splitListener;
|
|
194
|
-
|
|
213
|
+
let inputSlice = input;
|
|
214
|
+
this.parseWithCache(inputSlice);
|
|
195
215
|
if (!this._parseTree)
|
|
196
216
|
return null;
|
|
197
217
|
let sqlParserIns = this._parser;
|
|
198
|
-
let allTokens = this.getAllTokens(
|
|
218
|
+
let allTokens = this.getAllTokens(inputSlice);
|
|
199
219
|
let caretTokenIndex = findCaretTokenIndex(caretPosition, allTokens);
|
|
200
220
|
let c3Context = this._parseTree;
|
|
201
221
|
let tokenIndexOffset = 0;
|
|
@@ -241,37 +261,28 @@ export class BasicSQL {
|
|
|
241
261
|
}
|
|
242
262
|
// A boundary consisting of the index of the input.
|
|
243
263
|
let startIndex = (_e = (_d = startStatement === null || startStatement === void 0 ? void 0 : startStatement.start) === null || _d === void 0 ? void 0 : _d.start) !== null && _e !== void 0 ? _e : 0;
|
|
244
|
-
let stopIndex = (_g = (_f = stopStatement === null || stopStatement === void 0 ? void 0 : stopStatement.stop) === null || _f === void 0 ? void 0 : _f.stop) !== null && _g !== void 0 ? _g :
|
|
264
|
+
let stopIndex = (_g = (_f = stopStatement === null || stopStatement === void 0 ? void 0 : stopStatement.stop) === null || _f === void 0 ? void 0 : _f.stop) !== null && _g !== void 0 ? _g : inputSlice.length - 1;
|
|
245
265
|
/**
|
|
246
266
|
* Save offset of the tokenIndex in the range of input
|
|
247
267
|
* compared to the tokenIndex in the whole input
|
|
248
268
|
*/
|
|
249
269
|
tokenIndexOffset = (_j = (_h = startStatement === null || startStatement === void 0 ? void 0 : startStatement.start) === null || _h === void 0 ? void 0 : _h.tokenIndex) !== null && _j !== void 0 ? _j : 0;
|
|
250
270
|
caretTokenIndex = caretTokenIndex - tokenIndexOffset;
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
*/
|
|
267
|
-
tokenIndexOffset = (_m = startToken === null || startToken === void 0 ? void 0 : startToken.tokenIndex) !== null && _m !== void 0 ? _m : 0;
|
|
268
|
-
caretTokenIndex = caretTokenIndex - tokenIndexOffset;
|
|
269
|
-
/**
|
|
270
|
-
* Get the smaller range of inputSlice
|
|
271
|
-
*/
|
|
272
|
-
inputSlice = inputSlice.slice(startIndex, stopIndex);
|
|
273
|
-
allTokens = this.getAllTokens(inputSlice);
|
|
274
|
-
}
|
|
271
|
+
inputSlice = inputSlice.slice(startIndex, stopIndex);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Split the inputSlice by separator to get the smaller range of inputSlice.
|
|
275
|
+
*/
|
|
276
|
+
if (inputSlice.includes(SEPARATOR)) {
|
|
277
|
+
const { inputSlice: _input, caretTokenIndex: _caretTokenIndex, allTokens: _allTokens, } = this.splitInputBySeparator(inputSlice, caretTokenIndex);
|
|
278
|
+
caretTokenIndex = _caretTokenIndex;
|
|
279
|
+
inputSlice = _input;
|
|
280
|
+
allTokens = _allTokens;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Reparse the input fragment, and c3 will collect candidates in the newly generated parseTree when input changed.
|
|
284
|
+
*/
|
|
285
|
+
if (inputSlice !== input) {
|
|
275
286
|
const lexer = this.createLexer(inputSlice);
|
|
276
287
|
lexer.removeErrorListeners();
|
|
277
288
|
const tokenStream = new CommonTokenStream(lexer);
|