Skip to content

gravity-ui/websql-autocomplete

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebSQL autocomplete

ci_badge npm_package_version_badge last_commit_badge license_badge

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:

How everything works

  1. ANTLR4 grammar and lexer for different {dialect} are defined in src/autocomplete/databases/{dialect}/grammar directories.
  2. Actual parsers and lexers for different {dialect} are generated into src/autocomplete/databases/{dialect}/generated directories.
  3. Dialect specific code, which is required for the core logic to work, is put in src/autocomplete/databases/{dialect}/{dialect}-autocomplete.ts files.
  4. The core logic is inside src/autocomplete/shared/autocomplete.ts file. It uses dialect specific helpers to generate autocomplete suggestions based on current cursor position.

How to add a new dialect

  1. Add new dialect files to src/autocomplete/databases/{$dialect}
  2. Add new dialect to the typesVersions, exports variables in package.json
  3. Add new dialect to the databases array 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