Support autocomplete for tables in a specific schema #4
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "wicked-will-byers"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR adds support for specifying schema alongside a table, like so:
Currently, this package doesn't show any autocomplete suggestions when you specify a schema, even if you pass a config like this:
It also supports a default
publicschema. However, it's specified as a SQL keyword in this package, so this PR needs to specifically handle this case as an exception from other schema names. SeeschemaBeforefunction for details. I extracted the code to parse a schema into a function to avoid code duplication and to make it cleaner.I also added the tests for various combinations for queries with and without quotes.
This looks good, on the whole. But if I add a test like this:
It completes both
other.usersandpublic.users.Good catch, will work on this on Monday.
Updated to support autocomplete of tables under a certain schema.
@ -27,2 +48,2 @@if (before && before.name == "Identifier" || before.name == "QuotedIdentifier")parent = stripQuotes(state.sliceDoc(before.from, before.to))if (before && isIdentifier(state, before)) {let table = stripQuotes(state.sliceDoc(before.from, before.to))I extracted this logic into
isIdentifierfunction, so that the samesourceContextfunction supports autocomplete of tables under a schema without any modification to it. It was also repeated in 3 places, so I think it made sense to extract it either way.This is used to create autocomplete for tables after user has typed a schema name, e.g.
public.u|would returnuserscompletion item.Renamed
columnstocompletions, because this variable can no longer hold columns frombyTable, but also tables frombySchema.I've merged this as
3bcac26b62and largely rewritten it in104322083bto make the nesting less ad-hoc and more reflected in the code structure (so that it also, for example, supports completing schema names).Pull request closed