SQL table column autocompletion based on context


I am developing an SQL editor, I used the current lang-sql package and it works great.

One problem I faced was how we could add column name hints based on the selected table.

Assume we have two tables, users and sales(both are provided in schema)

select name from users;

in current version, when we provide defaultTable as users it will globally autocomplete the column names(name in this case)

but if we do a query like

select total from sales;

we are still getting auto-completion for the users table as it was set to default, not columns related to sales

is there a possibility to change the column auto-completion based on context?

No, that’s not something the package does at the moment.

if we want to do something like that would you provide some guideline about how to do it? for example does it requires a LSP?

That would work, I guess. The @codemirror/lang-sql parser isn’t really precise enough to do this kind of thing at the moment.