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

fix issue where database name was not completed when creating alias #218

Merged
merged 8 commits into from
Jun 28, 2024

Conversation

OskarDamkjaer
Copy link
Collaborator

The database name wasn't completed in the CREATE ALIAS foo FOR DATABASE statement as it was caught in the logic for not suggesting old names when creating new ones. I'm uncertain if there's a more sustainable way to catch this without updating the grammar

Copy link

changeset-bot bot commented May 23, 2024

🦋 Changeset detected

Latest commit: 9775ac5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@neo4j-cypher/language-support Patch
@neo4j-cypher/language-server Patch
@neo4j-cypher/react-codemirror-playground Patch
@neo4j-cypher/react-codemirror Patch
@neo4j-cypher/schema-poller Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Collaborator

@ncordon ncordon left a comment

Choose a reason for hiding this comment

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

I'm afraid this would not work in case we have more extra spaces because of that tokenIndex:

CREATE ALIAS fo      for DATABASE 

so it's better to push these changes down the grammar.

@OskarDamkjaer
Copy link
Collaborator Author

@ncordon ah of course, I was wrongly thinking the whitespace was not included in the token numbers. We could just check that the last token is DATABASE if we want to do a band-aid solution. Let's hear with the ANTLR grammar folks what they think of doing the grammar changes first perhaps?

@ncordon ncordon force-pushed the missing_db_name_completion branch from 245b807 to 8360dc6 Compare June 26, 2024 07:33
@ncordon ncordon requested review from ncordon and removed request for ncordon June 26, 2024 09:11
Comment on lines +1605 to +1610
aliasName:
symbolicAliasNameOrParameter;

databaseName:
symbolicAliasNameOrParameter;

Copy link
Collaborator

Choose a reason for hiding this comment

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

These are the real changes to the grammar, the rest are just bringing it up to date

Comment on lines +1605 to +1609
aliasName:
symbolicAliasNameOrParameter;

databaseName:
symbolicAliasNameOrParameter;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The change I was expecting was to separate into:

createAliasOrDatabaseName: 
    symbolicAliasNameOrParameter;

ReferenceAliasorDatabaseName:
    symbolicAliasNameOrParameter;

Because then we could use ReferenceAliasorDatabaseName instead of RULE_symbolicAliasName in the preferredRules and wouldn't have to check the tree if it's a rule that creates or references an alias/database. It could still be worth splitting database & aliases as well and this change also solves the problem, so I'm fine doing it this way if you prefer

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I agree that would be nicer for us but it could make it more difficult to enforce for engineers working in the database because it obfuscates the grammar a step further.

I'm happy to keep evolving the grammar, but we should make it gradually because pushing any change is a pain in the monorepo. Out of curiosity I completely tried to split database completions from alias completions here: 245b807 and it was super painful, so I decided to revert it 😬

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

alright, good to hear it was considered!

Comment on lines 635 to 638
// For `CREATE ALIAS $1 FOR DATABASE $2`
// Should not suggest $1 but should suggest for $2
// Ideally the grammar would separate declaring and referencing database names
// relying on the startTokenIndex is brittle as it will change as the grammar changes
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This comment is a little out of date, how about something like this instead

Suggested change
// For `CREATE ALIAS $1 FOR DATABASE $2`
// Should not suggest $1 but should suggest for $2
// Ideally the grammar would separate declaring and referencing database names
// relying on the startTokenIndex is brittle as it will change as the grammar changes
// For `CREATE ALIAS $1 FOR DATABASE $2`
// Should not suggest $1 but should suggest for $2
// so we return base suggestions if we're at the `aliasName` rule


test('Correctly completes database name even in a create alias statement including extra of spaces', () => {
testCompletions({
query: 'CREATE ALIAS foo FOR DATABASE ',
Copy link
Collaborator

Choose a reason for hiding this comment

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

I've added this extra test, which was the problematic bit in the previous solution

@@ -617,22 +617,29 @@ function completeAliasName({
}

// parameters are valid values in all cases of symbolicAliasName
const baseSuggestions = parameterCompletions(
const parameterSuggestions = parameterCompletions(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think renaming this makes the code read clearer because you know at any point what baseSuggestions contain

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

makes sense 👍

@OskarDamkjaer
Copy link
Collaborator Author

Looking nice! Do we want a changeset for this?

@ncordon ncordon merged commit 3661e9d into main Jun 28, 2024
4 checks passed
@ncordon ncordon deleted the missing_db_name_completion branch June 28, 2024 13:28
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.

None yet

2 participants