-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Shuffle a bit bundles to have more async
- Loading branch information
Showing
8 changed files
with
136 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { RecognitionException } from 'antlr4ts'; | ||
import { esql_parser } from '../../antlr/esql_parser'; | ||
import { getPosition } from './ast_position_utils'; | ||
|
||
const symbolsLookup: Record<number, string> = Object.entries(esql_parser) | ||
.filter(([k, v]) => typeof v === 'number' && !/RULE_/.test(k) && k.toUpperCase() === k) | ||
.reduce((memo, [k, v]: [string, number]) => { | ||
memo[v] = k; | ||
return memo; | ||
}, {} as Record<number, string>); | ||
|
||
export function getExpectedSymbols(expectedTokens: RecognitionException['expectedTokens']) { | ||
const tokenIds = expectedTokens?.toIntegerList().toArray() || []; | ||
const list = []; | ||
for (const tokenId of tokenIds) { | ||
if (tokenId in symbolsLookup) { | ||
list.push(symbolsLookup[tokenId]); | ||
} else if (tokenId === -1) { | ||
list.push('<EOF>'); | ||
} | ||
} | ||
return list; | ||
} | ||
|
||
export function createError(exception: RecognitionException) { | ||
const token = exception.getOffendingToken(); | ||
if (token) { | ||
const expectedSymbols = getExpectedSymbols(exception.expectedTokens); | ||
if ( | ||
['ASTERISK', 'UNQUOTED_IDENTIFIER', 'QUOTED_IDENTIFIER'].every( | ||
(s, i) => expectedSymbols[i] === s | ||
) | ||
) { | ||
return { | ||
type: 'error' as const, | ||
text: `Unknown column ${token.text}`, | ||
location: getPosition(token), | ||
}; | ||
} | ||
} | ||
return { | ||
type: 'error' as const, | ||
text: token | ||
? `SyntaxError: expected {${getExpectedSymbols(exception.expectedTokens).join( | ||
', ' | ||
)}} but found "${token.text}"` | ||
: '', | ||
location: getPosition(token), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/kbn-monaco/src/esql/lib/ast/ast_position_utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { Token } from 'antlr4ts'; | ||
|
||
export function getPosition(token: Token | undefined, lastToken?: Token | undefined) { | ||
if (!token || token.startIndex < 0) { | ||
return { min: 0, max: 0 }; | ||
} | ||
const endFirstToken = | ||
token.stopIndex > -1 ? Math.max(token.stopIndex + 1, token.startIndex) : undefined; | ||
const endLastToken = lastToken?.stopIndex; | ||
return { | ||
min: token.startIndex, | ||
max: endLastToken ?? endFirstToken ?? Infinity, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { validateAst } from './validation/validation'; | ||
export { suggest, getHoverItem, getSignatureHelp } from './autocomplete/autocomplete'; | ||
export { AstListener } from './ast_factory'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters