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

Corrects a bug with an empty query in VSCode #172

Merged
merged 2 commits into from
Feb 7, 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
1 change: 1 addition & 0 deletions packages/language-server/src/linting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async function rawLintDocument(

const query = document.getText();
if (query.length === 0) {
sendDiagnostics([]);
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MATCH (n) RETURN m
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import * as assert from 'assert';
import * as vscode from 'vscode';
import { eventually, getDocumentUri, openDocument } from '../helpers';

type InclusionTestArgs = {
textFile: string;
expected: vscode.Diagnostic[];
};

export async function testSyntaxValidation({
textFile,
expected,
}: InclusionTestArgs) {
await eventually(
() =>
new Promise((resolve, reject) => {
const docUri = getDocumentUri(textFile);
const diagnostics: vscode.Diagnostic[] =
vscode.languages.getDiagnostics(docUri);

try {
// We need to test diagnostics one by one
// because the ones returned by VSCode contain
// more information we don't care about in the tests
assert.equal(diagnostics.length, expected.length);
diagnostics.forEach((diagnostic, i) => {
const expectedDiagnostic = expected[i];
assert.equal(diagnostic.message, expectedDiagnostic.message);
assert.deepEqual(diagnostic.range, expectedDiagnostic.range);
assert.equal(diagnostic.severity, expectedDiagnostic.severity);
});
resolve();
} catch (e) {
reject();
}
}),
);
}

suite('Syntax validation spec', () => {
test('Correctly validates empty cypher statement', async () => {
const textFile = 'syntax-validation.cypher';
const docUri = getDocumentUri(textFile);

await openDocument(docUri);

const editor = vscode.window.activeTextEditor;

await editor.edit((editBuilder) =>
editBuilder.replace(
// Select the whole file
new vscode.Range(
new vscode.Position(0, 0),
new vscode.Position(100, 0),
),
'MATCH (n)',
),
);

// We need to wait here because diagnostics are eventually
// consistent i.e. they don't show up immediately
await testSyntaxValidation({
textFile: 'syntax-validation.cypher',
expected: [
new vscode.Diagnostic(
new vscode.Range(
new vscode.Position(0, 0),
new vscode.Position(0, 9),
),
'Query cannot conclude with MATCH (must be a RETURN clause, an update clause, a unit subquery call, or a procedure call with no YIELD)',
vscode.DiagnosticSeverity.Error,
),
],
});

await editor.edit((editBuilder) =>
editBuilder.replace(
// Select the whole file
new vscode.Range(
new vscode.Position(0, 0),
new vscode.Position(100, 0),
),
'',
),
);

await testSyntaxValidation({
textFile: 'syntax-validation.cypher',
expected: [],
});
});
});
Loading