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

Fixes bug splitting the statements into commands #346

Merged
merged 5 commits into from
Feb 6, 2025
Merged

Conversation

ncordon
Copy link
Collaborator

@ncordon ncordon commented Feb 4, 2025

What

When splitting the commands, we try to parse the input as cypher or console commands, etc. If all of that fails, we default to taking the full query if a cypher statement could not be parsed, but we were taking a stop token that could possibly be null. This PR just defaults to taking the full stream when that token is null:

    // stop here could be null
    const statement = inputstream.getText(start.start, stop.stop);
    return { type: 'cypher', statement, start: start, stop: stop };

Why

Because we were blowing up in multiline comments (where the parsing tree would be empty):

failure

Copy link

changeset-bot bot commented Feb 4, 2025

🦋 Changeset detected

Latest commit: 5ccba29

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

@anderson4j anderson4j left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, but would we not get the same issue with unfinished strings/escaped sequences? (If so, we might as well add tests for these too)

And if my summary of the issue (see comment) is correct, would we encounter it for single line comments?

@@ -610,8 +610,9 @@ function parseToCommand(

return { type: 'parse-error', start, stop };
}
const statement = inputstream.getText(start.start, stop.stop);
return { type: 'cypher', statement, start: start, stop: stop };
const stopToken = stop ?? tokens.at(-1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Double checking my understanding - I would explain like:
"When ANTLR can't finish the parsing (but can tokenize) because a comment/string/escaped sequence is unfinished we get here with stop===null"

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 problem if we just a comment is that's not passed to the parser, so the CST is empty, therefore because the parser expects something, it errors and cannot find a stop. Strings and backticked elements are not on the hidden channel, so they are passed to the parser

Copy link
Collaborator

@anderson4j anderson4j left a comment

Choose a reason for hiding this comment

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

aha, your response jogged my memory - comments are removed just like blank space when tokenizing, so what would be the stop-token when parsing to command doesnt exist

Think changeset-message is off then, the issue is not with "non-finished multiline comments" (that's more like the bug in the other PR right) but rather "queries ending in a comment"

approving so you can merge once that's adjusted

@ncordon ncordon merged commit b988d3b into main Feb 6, 2025
4 checks passed
@ncordon ncordon deleted the commands-split-bug branch February 6, 2025 14:40
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