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

Adds backticks to dbNames/aliases if needed #310

Merged
merged 12 commits into from
Dec 19, 2024
Merged

Conversation

anderson4j
Copy link
Collaborator

@anderson4j anderson4j commented Dec 9, 2024

Before autocompletions for database names/aliases would be like:
Ex. database name = "matrix-db"
SHOW DATABASE ^ -> SHOW DATABASE matrix-db which can not be parsed

now we get
-> SHOW DATABASE `matrix-db`

Note: we might allow parameters to have escaped names too (my-param) in which case we should update their usages for db-name-suggestions too

Further possibility for stuff that might need backticks - constraints/indexes once we suggest for these.

@anderson4j anderson4j added the auto completion Issues related to the auto-completion label Dec 9, 2024
@anderson4j anderson4j requested a review from ncordon December 9, 2024 14:30
Copy link

changeset-bot bot commented Dec 9, 2024

🦋 Changeset detected

Latest commit: a011d66

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

Comment on lines 782 to 785
return parameterSuggestions.map((completionItem) => ({
label: completionItem.label,
kind: completionItem.kind,
}));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need these mappings to label and kind? This is not doing anything I think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Used to backtick if needed parameters too (so had insertText: backtickIfNeeded(...label) too), but they could not be added with backticks yet. Looks like I forgot to remove the whole thing.

Either way, since we're changing the parser-file for creating params, maybe we should just add backticks if needed here already, so once it's valid, we're good to go?

Comment on lines 804 to 807
return result.map((completionItem) => ({
label: completionItem.label,
kind: completionItem.kind,
}));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

Comment on lines 823 to 826
].map((completionItem) => ({
label: completionItem.label,
kind: completionItem.kind,
}));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

Comment on lines 30 to 32
test('Correctly completes database names/aliases with special symbols using backticks', () => {
const query = 'SHOW DATABASE ';
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test is unnecessary, you could just add the completions to the existing test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I split it on purpose so you would see that only this test failed if something purely related to backticks broke. You don't think there's any value to this?

],
});
});

test('Correctly completes database names and aliases in SHOW DATABASE', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's also a SHOW ALIAS test in this file which you should add the corresponding checks to

return parameterSuggestions.map((completionItem) => ({
label: completionItem.label,
kind: completionItem.kind,
insertText: backtickDbNameIfNeeded(completionItem.label),
Copy link
Collaborator

@ncordon ncordon Dec 12, 2024

Choose a reason for hiding this comment

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

Can a parameter include the ., otherwise this should be backtickIfNeeded, no? Same for some of the uses below

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah yeah, this is not valid

return undefined;
}
const namePart = e.slice(1);
if (e[0] == '$') {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should I even have this test, or just trust the backtickParam... -method to only be called with params?

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 it's okay to have double guards in case something goes wrong in the other part of the code.

@anderson4j
Copy link
Collaborator Author

anderson4j commented Dec 16, 2024

I think what is new from your last review is just the PR shifting to $param-Name backticks over $param-Name. The old comments are handled

@anderson4j anderson4j requested a review from ncordon December 16, 2024 08:44
Comment on lines 60 to 68
if (/[^\p{L}\p{N}_]/u.test(namePart) || /[^\p{L}_]/u.test(namePart[0])) {
return '$' + `\`${namePart}\``;
} else {
return undefined;
}
} else {
return backtickIfNeeded(e);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could refactor all this method to depend on the backtickIfNeeded as:

function backtickParamIfNeeded(e: string): string | undefined {
  if (e == null || e == '') {
    return undefined;
  }
  const namePart = e.slice(1);
  const backticked = backtickIfNeeded(namePart);
  if (backticked) {
    return '$' + backticked;
  } else {
    return undefined;
  }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like fixing comment 2 will actually mean I can get ahead of adding the $ and just use backtickIfNeeded from scratch

Comment on lines 735 to 739
return parameterSuggestions.map((completionItem) => ({
label: completionItem.label,
kind: completionItem.kind,
insertText: backtickParamIfNeeded(completionItem.label),
}));
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should move the insertText thing to where the parameterSuggestions are defined instead of repeating this in the code a few times

return {
label: `$${paramName}`,
kind: CompletionItemKind.Variable,
...(backtickedName != undefined
Copy link
Collaborator

@ncordon ncordon Dec 18, 2024

Choose a reason for hiding this comment

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

This comparison needs to be !== I think.

You can just do this instead

backtickedName ? { insertText: `$${backtickIfNeeded(paramName)}` } : {}

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.

Address my last comment please and ready to go 😄

@anderson4j anderson4j merged commit b0e419e into main Dec 19, 2024
4 checks passed
@anderson4j anderson4j deleted the backtickExtension branch December 19, 2024 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto completion Issues related to the auto-completion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants