Bytebase, a DevSecOps solution for databases, has built an autocomplete framework for its SQL Editor that supports different SQL dialects and offers extensibility and strong completion capabilities.
An ANTLR4-based parser processes user input and generates a parse tree or abstract syntax tree representing the syntactic structure of the input according to the grammar.
Autocomplete follows a syntax-agnostic, core-based approach that leverages an automaton created from syntax rules, allowing predictions that are syntax-agnostic and extensible.
The approach includes a core that identifies terminal symbols (keywords) and grammar rules of interest (identifiers), and post-processing that converts candidate rules to corresponding strings and return them to the user.
Bytebase SQL Editor supports common autocomplete scenarios relative to table names, column names, and function names.
The ANTLR4-based autocomplete core is implemented in Golang and used in five different SQL dialects: Oracle, SQL Server, PostgreSQL, MySQL, and DynamoDB.
The Bytebase SQL Editor is open-source, and developers can visit the Bytebase console to interact with the database from the SQL Editor and embed the SQL Editor into their internal web portal.
The ANTLR4 code that serves as the basis for the SQL Editor is also open-sourced, with Bytebase having identified areas of improvement in the ANTLR4 Golang runtime.
Future articles will look more closely at ANTLR4-based autocomplete core implementation, syntax-specific processing, and how to integrate it with LSP to provide a complete and robust SQL autocomplete.
Bytebase's tech stack choice is Golang for the ANTLR4-based autocomplete core, and it has ensured cross-SQL dialect support while reducing development and maintenance costs significantly, allowing a small team to maintain autocomplete functionalities for multiple dialects.