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

Added hint when using function as procedure and vice versa #322

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

anderson4j
Copy link
Collaborator

Will yield errors like:
CALL abs(-50) YIELD * -> Procedure abs is not present in the database. Did you mean to call the function abs? Only procedures can be called inside a CALL clause.
and
RETURN apoc.create.uuids(50) -> Function apoc.create.uuids is not present in the database. Did you mean to call the procedure apoc.create.uuids? Procedures must be called inside a CALL clause.

Instead of the regular "Procedure/Function is not present in the database"-messages.

@anderson4j anderson4j added the auto completion Issues related to the auto-completion label Jan 8, 2025
@anderson4j anderson4j requested a review from ncordon January 8, 2025 14:08
Copy link

changeset-bot bot commented Jan 8, 2025

🦋 Changeset detected

Latest commit: f1883b4

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

parsedProcedure.rawText,
parsedProcedure,
DiagnosticSeverity.Error,
`Procedure ${parsedProcedure.name} is not present in the database. Did you mean to call the function ${parsedProcedure.name}? Only procedures can be called inside a CALL clause.`,
Copy link
Collaborator

@ncordon ncordon Jan 10, 2025

Choose a reason for hiding this comment

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

It would be better if the error was actionable IMHO:

${parsedProcedure.name} is a function, not a procedure. Did you mean to use the function ${parsedProcedure.name} with a RETURN instead of a CALL clause?

Comment on lines +92 to +95
let existsAsProcedure = false;
if (procedureSchema) {
existsAsProcedure = Boolean(procedureSchema[parsedFunction.name]);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be rewritten as:

const existsAsProcedure = procedureSchema && Boolean(procedureSchema[parsedFunction.name]);

Comment on lines 118 to 126
if (
caseInsensitiveFunctionInDatabase &&
caseInsensitiveFunctionInDatabase.isBuiltIn
functionExistsWithExactName ||
(caseInsensitiveFunctionInDatabase &&
caseInsensitiveFunctionInDatabase.isBuiltIn)
) {
return undefined;
return true;
} else {
return false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need the if:

return functionExistsWithExactName ||
    (caseInsensitiveFunctionInDatabase &&
      caseInsensitiveFunctionInDatabase.isBuiltIn)

@@ -74,6 +74,42 @@ describe('Functions semantic validation spec', () => {
]);
});

test('Syntax validation error on function used as procedure returns helpful message', () => {
const query = `CALL abs(-50) YIELD *`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd be good to add a test to check we are matching case insensitive functions:

CALL ABS(-1)

@@ -59,6 +59,42 @@ meaning that it expects at least 3 arguments of types NODE, STRING, ANY
]);
});

test('Syntax validation error on procedure used as function returns helpful message', () => {
const query = `RETURN apoc.create.uuids(50)`;
Copy link
Collaborator

@ncordon ncordon Jan 10, 2025

Choose a reason for hiding this comment

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

Conversely, we should add a test to check

RETURN APOC.create.uuids(50)

would just say the function is not in the database, but not that the procedure is (because procedures are case sensitive)

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