Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL Autocomplete: Support schema in table identifiers #43

Merged
merged 9 commits into from
Aug 16, 2022
Merged

Conversation

sunker
Copy link
Contributor

@sunker sunker commented Jul 22, 2022

Most SQL languages support prefixing the table name with a schema name. For example select * from dbo.products. This allows more sophisticated autocompletion. Currently, when a schema is specified the autocompletion engine doesn't take it into account. This is breaking suggestions for columns and causing other problems where the position detection is lost.

This PR adds support for rich autocompletion in the case a schema is provided in the query. To enable this, I had to change the signature for the tables and the columns api in the completion item provider so that it no longer only passes the table name, but also the schema. This is a breaking change that needs to be handled in for example the big query data source.

schema-support

Next step could be to add an api for loading schemas so that they can be suggested too.

@sunker sunker requested review from dprokop, kevinwcyu, sarahzinger and scottlepp and removed request for dprokop and kevinwcyu July 22, 2022 11:46
Comment on lines 109 to 124
{
id: StatementPosition.AfterSchema,
name: StatementPosition.AfterSchema,
resolve: (currentToken, previousKeyword, previousNonWhiteSpace, previousIsSlash) => {
// depending on weather the schema was the last token in the query or not, current token might be whitespace or dot. if whitespace, just use the previous token
if (currentToken?.isWhiteSpace() && currentToken?.next) {
currentToken = currentToken?.previous;
previousNonWhiteSpace = currentToken?.getPreviousNonWhiteSpaceToken();
}
return Boolean(
currentToken?.isIdentifier() &&
currentToken?.value.endsWith('.') &&
previousNonWhiteSpace?.value.toLowerCase() === FROM
);
},
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the BigQuey pov, where you query like SELECT * from 'project.dataset.id', this will cause the after schema suggestions to kick in.

@zoltanbedi zoltanbedi self-requested a review July 27, 2022 13:55
@sunker
Copy link
Contributor Author

sunker commented Aug 15, 2022

@dprokop @zoltanbedi back from vaction now. :) Made some changes so that this will work also with bigquery. See proposed changes in the bigquery plugin here

Copy link
Member

@zoltanbedi zoltanbedi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

sunker and others added 2 commits August 16, 2022 12:25
@sunker sunker merged commit be3795e into main Aug 16, 2022
SandersAaronD pushed a commit that referenced this pull request Jan 10, 2024
SQL Autocomplete: Support schema in table identifiers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants