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

Adapts procedure registry to depend on the cypher version #331

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
18 changes: 17 additions & 1 deletion packages/language-server/src/lintWorker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import { lintCypherQuery } from '@neo4j-cypher/language-support';
import {
DbSchema,
lintCypherQuery as _lintCypherQuery,
_internalFeatureFlags,
} from '@neo4j-cypher/language-support';
import workerpool from 'workerpool';

function lintCypherQuery(
query: string,
dbSchema: DbSchema,
featureFlags: { cypher25?: boolean } = {},
) {
// We allow to override the consoleCommands feature flag
if (featureFlags.cypher25 !== undefined) {
_internalFeatureFlags.cypher25 = featureFlags.cypher25;
}
Comment on lines +17 to +19
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We need to pass the feature flags to the lint worker because the _internalFeatureFlags variable from the outside lives in another thread

return _lintCypherQuery(query, dbSchema);
}

workerpool.worker({ lintCypherQuery });

type LinterArgs = Parameters<typeof lintCypherQuery>;
Expand Down
7 changes: 6 additions & 1 deletion packages/language-server/src/linting.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { _internalFeatureFlags } from '@neo4j-cypher/language-support';
import { Neo4jSchemaPoller } from '@neo4j-cypher/schema-poller';
import debounce from 'lodash.debounce';
import { join } from 'path';
Expand Down Expand Up @@ -31,7 +32,11 @@ async function rawLintDocument(
}

const proxyWorker = (await pool.proxy()) as unknown as LintWorker;
lastSemanticJob = proxyWorker.lintCypherQuery(query, dbSchema);
lastSemanticJob = proxyWorker.lintCypherQuery(
query,
dbSchema,
_internalFeatureFlags,
);
const result = await lastSemanticJob;

sendDiagnostics(result);
Expand Down
9 changes: 8 additions & 1 deletion packages/language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ import {

import { TextDocument } from 'vscode-languageserver-textdocument';

import { syntaxColouringLegend } from '@neo4j-cypher/language-support';
import {
syntaxColouringLegend,
_internalFeatureFlags,
} from '@neo4j-cypher/language-support';
import { Neo4jSchemaPoller } from '@neo4j-cypher/schema-poller';
import { doAutoCompletion } from './autocompletion';
import { cleanupWorkers, lintDocument } from './linting';
import { doSignatureHelp } from './signatureHelp';
import { applySyntaxColouringForDocument } from './syntaxColouring';
import { Neo4jSettings } from './types';

if (process.env.CYPHER_25 === 'true') {
_internalFeatureFlags.cypher25 = true;
}
Comment on lines +26 to +28
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 is so we can set the feature flag in the language server from the vscode extension


const connection = createConnection(ProposedFeatures.all);

// Create a simple text document manager.
Expand Down
2 changes: 2 additions & 0 deletions packages/language-support/src/featureFlags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
interface FeatureFlags {
consoleCommands: boolean;
cypher25: boolean;
}

export const _internalFeatureFlags: FeatureFlags = {
Expand All @@ -11,4 +12,5 @@ export const _internalFeatureFlags: FeatureFlags = {
it's own cache and preference on if console commands are enabled or not.
*/
consoleCommands: false,
cypher25: false,
};
2 changes: 2 additions & 0 deletions packages/schema-poller/src/metadataPoller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
DbSchema,
Neo4jFunction,
Neo4jProcedure,
_internalFeatureFlags,
} from '@neo4j-cypher/language-support';
import { EventEmitter } from 'events';
import { Neo4jConnection } from './neo4jConnection.js';
Expand Down Expand Up @@ -100,6 +101,7 @@ export class MetadataPoller {
private readonly events: EventEmitter,
) {
const isNewerNeo4j =
_internalFeatureFlags.cypher25 ||
databases.find((db) => db.defaultLanguage !== undefined) !== undefined;

this.databases = new QueryPoller({
Expand Down
1 change: 1 addition & 0 deletions packages/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export async function activate(context: ExtensionContext) {
debug: {
module: debugServer,
transport: TransportKind.ipc,
options: { env: { CYPHER_25: 'true' } },
Comment on lines 30 to +33
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 only affects the server version we use in the tests, not the production one. So we'll have CYPHER_25 support enabled there by default.

},
};
// Options to control the language client
Expand Down
35 changes: 35 additions & 0 deletions packages/vscode-extension/tests/specs/api/syntaxValidation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,39 @@ suite('Syntax validation spec', () => {
password,
);
});

test('Errors and warnings are version Cypher version dependant', async () => {
// We open a file that is not saved on disk
// and change the language manually to Cypher
await newUntitledFileWithContent(`
CYPHER 5 CALL apoc.create.uuids(5);
CYPHER 25 CALL apoc.create.uuids(5)
`);
const editor = vscode.window.activeTextEditor;
await vscode.languages.setTextDocumentLanguage(editor.document, 'cypher');

// We need to wait here because diagnostics are eventually
// consistent i.e. they don't show up immediately
await testSyntaxValidation({
textFile: undefined,
expected: [
new vscode.Diagnostic(
new vscode.Range(
new vscode.Position(1, 20),
new vscode.Position(1, 37),
),
"Procedure apoc.create.uuids is deprecated. Alternative: Neo4j's randomUUID() function can be used as a replacement, for example: `UNWIND range(0,$count) AS row RETURN row, randomUUID() AS uuid`",
vscode.DiagnosticSeverity.Warning,
),
new vscode.Diagnostic(
new vscode.Range(
new vscode.Position(2, 21),
new vscode.Position(2, 38),
),
"Procedure apoc.create.uuids is not present in the database. Make sure you didn't misspell it or that it is available when you run this statement in your application",
vscode.DiagnosticSeverity.Error,
),
],
});
});
});