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 with preparser options making semantic errors not show up correctly #295

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions packages/language-support/src/parserWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,16 @@ function parseToCommand(
if (stmt) {
const { start, stop } = stmt;

const cypherStmt = stmt.preparsedStatement();
const cypherStmt = stmt.preparsedStatement()?.statement();
if (cypherStmt) {
// we get the original text input to preserve whitespace
// stripping the preparser part of it
const inputstream = start.getInputStream();
const statement = inputstream.getText(start.start, stop.stop);
const stmtStart = cypherStmt.start;
const stmtStop = cypherStmt.stop;
const statement = inputstream.getText(stmtStart.start, stmtStop.stop);

return { type: 'cypher', statement, start, stop };
return { type: 'cypher', statement, start: stmtStart, stop: stmtStop };
}

if (isEmptyStatement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,51 @@ describe('Semantic validation spec', () => {
]);
});

test('Semantic errors work when we also have preparser options', () => {
const query = `EXPLAIN MATCH (n);
PROFILE MATCH (m) RETURN n`;

expect(getDiagnosticsForQuery({ query })).toEqual([
{
message:
'Query cannot conclude with MATCH (must be a RETURN clause, a FINISH clause, an update clause, a unit subquery call, or a procedure call with no YIELD).',
offsets: {
end: 17,
start: 8,
},
range: {
end: {
character: 17,
line: 0,
},
start: {
character: 8,
line: 0,
},
},
severity: 1,
},
{
message: 'Variable `n` not defined',
offsets: {
end: 64,
start: 63,
},
range: {
end: {
character: 45,
line: 1,
},
start: {
character: 44,
line: 1,
},
},
severity: 1,
},
]);
});

test('Surfaces notifications correctly', () => {
const query = `
MATCH (shadowed)
Expand Down