@gravity-ui/websql-autocomplete
v13.14.0
Published
A library that provides autocompletion and errors highlighting for various database dialects
Readme
WebSQL autocomplete
A tool that provides autocompletion for various sql dialects.
Autocomplete theory
In order to parse any language, you need a lexer (tokenizer) and a parser (ast builder)
Resources to research:
- The ANTLR Mega Tutorial: https://tomassetti.me/antlr-mega-tutorial/
- Code Completion with ANTLR4-c3: https://tomassetti.me/code-completion-with-antlr4-c3/
How everything works
- ANTLR4 grammar and lexer for different
{dialect}are defined insrc/autocomplete/databases/{dialect}/grammardirectories. - Actual parsers and lexers for different
{dialect}are generated intosrc/autocomplete/databases/{dialect}/generateddirectories. - Dialect specific code, which is required for the core logic to work, is put in
src/autocomplete/databases/{dialect}/{dialect}-autocomplete.tsfiles. - The core logic is inside
src/autocomplete/shared/autocomplete.tsfile. It uses dialect specific helpers to generate autocomplete suggestions based on current cursor position.
How to add a new dialect
- Add new dialect files to src/autocomplete/databases/{$dialect}
- Add new dialect to the
typesVersions,exportsvariables in package.json - Add new dialect to the
databasesarray in build.js
Main scripts
npm run generate- Generate parsers and lexers (Java has to be installed on your system for this to work)npm run test- Run tests
