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

Support '::' casts in autocomplete grammar #3

Merged
merged 6 commits into from
Nov 7, 2024
Merged

Conversation

jkillian
Copy link

@jkillian jkillian commented Nov 6, 2024

Updates the autocomplete grammar so that it understands cast expressions of the type some_col::type. This prevents autocomplete from occasionally breaking as reported by users when using the above syntax.

Left some comments inline about the change to clarify the intentions.

cc @chrisvlopez

Comment on lines 49 to 54
it.skip('testing', () => {
assertLocations({
beforeCursor: 'select boo::INT, bar::int from customers; ',
expectedLocations: []
});
});
Copy link
Author

Choose a reason for hiding this comment

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

Just a nice test to quickly see what the parser is returning, obviously can be deleted before merging

},
{
"namePrefix": "should suggest columns for order by after a cast in a join",
"beforeCursor": "select * from a join b on a.a = b.b::date order by ",
Copy link
Author

@jkillian jkillian Nov 7, 2024

Choose a reason for hiding this comment

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

Added this test as a direct test of issues users were reporting, it failed before this PR and passes now which is great.

One downside still though, if your casted type doesn't match one of the below types defined in PrimitiveType, then things still don't work. I wish something like the below would still work correctly also, not sure the right way to accomplish it though::

select * from a join b on a.a = b.b::dte order by 

@@ -36,16 +36,20 @@
'ASC' { return 'ASC'; }
'BETWEEN' { this.begin('between'); return 'BETWEEN'; }
'BIGINT' { return 'BIGINT'; }
'BINARY' { return 'BINARY'; }
Copy link
Author

Choose a reason for hiding this comment

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

Had to manually specify all the possible types here otherwise they weren't treated in a case-sensitive manner. (This file starts with %options case-insensitive flex so I think that's what makes it work if listed here)

Comment on lines +49 to +54
it.skip('useful for testing', () => {
assertLocations({
beforeCursor: 'select * from a join b on a.a = b.b::date order by ',
expectedLocations: []
});
});
Copy link
Author

Choose a reason for hiding this comment

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

Changing the skip to only is a really easy way to test out changes to the parser while you're working on things so going to leave this in as a utility if it isn't too irksome

@@ -3927,6 +3927,70 @@
"lowerCase": false
}
},
{
Copy link
Author

Choose a reason for hiding this comment

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

Next three tests are similar to the ones above for CAST(foo AS type) expressions

Comment on lines +939 to +943
: ValueExpression '::' AnyCursor
{
parser.suggestKeywords(parser.getTypeKeywords());
$$ = { types: [ 'T' ] };
}
Copy link
Author

Choose a reason for hiding this comment

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

AnyCursor
 : 'CURSOR'
 | 'PARTIAL_CURSOR'
 ;

The above is the definition of AnyCursor, I'm not really sure when to use it vs regular 'CURSOR' vs 'PARTIAL_CURSOR'.

Comment on lines +944 to +948
| ValueExpression_EDIT '::' PrimitiveTypeOrError
{
parser.addColRefIfExists($1);
$$ = { types: [ $3.toUpperCase() ] }
}
Copy link
Author

Choose a reason for hiding this comment

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

Was hoping this clause would fix the issue with invalid types like my_col::dte, but it didn't 😢

@jkillian jkillian marked this pull request as ready for review November 7, 2024 15:45
@jkillian jkillian requested a review from dylanscott November 7, 2024 15:45
Copy link
Collaborator

@dylanscott dylanscott left a comment

Choose a reason for hiding this comment

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

very nice! I bet this will make a big difference 🤞

@jkillian jkillian merged commit c157205 into master Nov 7, 2024
1 check passed
@jkillian jkillian deleted the jk_support_casts branch November 7, 2024 16:07
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.

2 participants