Similar to a search engine, the suggestions come from several weighted sources:
The core autocomplete logic has three components:
In addition to the core logic, there are other UI behaviors for autocomplete:
The user-facing component is AceAutocomplete.ce.vue
, which handles autocomplete-related mouse events and key bindings, computes the autocomplete suggestions from the editor text, and renders the autocomplete suggestions list component. It also handles insertion points.
There are two types of autocomplete suggestions. Query snippets are user-defined shortcuts that we can simply fetch from the network API, which is done by QuerySnippetsAutocompleter
. All other suggestions require parsing the query text and are handled by SqlAutocompleter
.
sqlStatementsParser
parses the entire text to determine what the statements are, what their locations and lengths are, and whether they are a USE database
statement.AceLocationHandler
decides which is the current statement and passes that to SqlAutocompleter
.SqlAutocompleter
contains an instance of an AutocompleteParser
and a SyntaxAutocompleter
. It uses the statements parse results to tell the autocomplete parser what to parse.sqlUtils
.Unit tests cover most of the major steps of autocomplete.
QuerySnippetsAutocompleter.test
tests the query snippets handling.sqlStatementsParser.test
tests that the statements are correctly parsed by the sqlStatementsParser
.AceLocationHandler.test
tests that the statements parse results are correctly processed to get the active statement and the USE database
pertinent to it.SqlAutocompleter.test
makes sure SqlAutocompleter
correctly delegates the right text to the autocomplete parser.dbsqlAutocompleteParser.test
verifies the autocomplete parse results.SyntaxAutocompleter.test
verifies that the correct suggestions are generated from the parse results.sqlUtils.test
checks that suggestion filtering and sorting are correct.insertionPoints.test
tests insertion-point-related util functions.There is currently no coverage for the logic in AceAutocomplete.ce.vue
.
There is also a RemoteAutocompleter
which allows the wrapper component to specify its own autocompleter, by passing it into the languageApi
prop. In addition, the component also surfaces the monaco.languages
reference, but it is recommended to use languageApi
instead so the component can include its own handling.
WIP
ML or heuristic based.
WIP