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

Console command support (:use, :params, :clear, history) #165

Merged
merged 31 commits into from
Feb 7, 2024

Conversation

OskarDamkjaer
Copy link
Collaborator

@OskarDamkjaer OskarDamkjaer commented Jan 18, 2024

I introduce a new grammar that extends the CypherParser with more client side commands like :param x => 23 and :use foo. It can be toggled on/off, and I've added proper errors, completions, highlighting for the client side commands. See the new test cases for a fuller picture

This PR also fixes semantic analysis for multi-statement queries, like RETURN a; RETURN b; since I had to split the string into parts to avoid sending the client commands regardless.

@OskarDamkjaer OskarDamkjaer mentioned this pull request Jan 18, 2024
@OskarDamkjaer OskarDamkjaer marked this pull request as ready for review January 22, 2024 11:32
@OskarDamkjaer OskarDamkjaer requested a review from ncordon January 22, 2024 11:32
@OskarDamkjaer OskarDamkjaer assigned ncordon and unassigned ncordon Jan 24, 2024
@@ -47,7 +47,7 @@
"vscode-languageserver-types": "^3.17.3"
},
"scripts": {
"gen-parser": "antlr4 -Dlanguage=TypeScript -visitor src/antlr-grammar/CypherParser.g4 src/antlr-grammar/CypherLexer.g4 -o src/generated-parser/ -Xexact-output-dir",
"gen-parser": "antlr4 -Dlanguage=TypeScript -visitor src/antlr-grammar/CommandLexer.g4 src/antlr-grammar/CommandParser.g4 -o src/generated-parser/ -Xexact-output-dir",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a nitpick but could we find another name for the files? CypherCmdParser?

Copy link
Collaborator Author

@OskarDamkjaer OskarDamkjaer Jan 29, 2024

Choose a reason for hiding this comment

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

Yea, also not super happy about the name. Let's go with CypherCmdParser unless we think of a better name


historyCmd: HISTORY;

useCmd: useCompletionRule symbolicAliasName?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Right now this rule is different from the USE one in the database:

useClause:
   USE (GRAPH expression | expression);

I suppose that's expected and we want to change that useClause instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes! But also because the semantics are different. USE in the database allows USE graph.byName('myComposite.myConstituent') which we don't allow in :use

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 also allow running it without passing an argument, which switches you to the default database

[CompletionItemKind.Event]: 'Event',
// we're missuing the enum here as there is no Console command in the item kind list
// deceide which one we want to use - for vscode we can't control the icon
[CompletionItemKind.Event]: 'Console',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Didn't know where to leave the comment, but there's something not working correctly here, certain things after the :param disappear when writing them or it just places the cursor incorrectly:

bug.mov

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's related to the issue you see in the vscode with parameters as well. Thanks for finding it, I'll give it a look and see what I can do

@@ -169,21 +175,30 @@ export function validateSyntax(
const parsingResult = parserWrapper.parse(wholeFileText);
diagnostics = parsingResult.diagnostics;

// semantic anaylsis doesn't handle multi statements
// we break the file into statements and run semantic analysis on each
// then mapp the postions back to the original file
Copy link
Collaborator

Choose a reason for hiding this comment

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

*Typo: map

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I updated/rephrased the comment all together

Copy link
Collaborator

@ncordon ncordon left a comment

Choose a reason for hiding this comment

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

I also find a bit strange that in VSCode we give you an error saying you need to complete with a console command, not help you in the auto-completion but then error saying you cannot use these type of commands here.

I think it would make more sense to show the error you cannot use console commands here, but still give you the auto-completion:

Either that or show the error when you've just opened :

Copy link
Collaborator

@ncordon ncordon left a comment

Choose a reason for hiding this comment

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

Also another bug, but this blows up VSCode, not sure if related to the PR:

@OskarDamkjaer
Copy link
Collaborator Author

@ncordon the odd behavior you saw in vsocde/codemirror was caused by the parseToCommands crashing on parse errors. I fixed the errors and added a few tests.

Is it fine to leave in the issue of the error message suggesting a keyword on : for now and re-visit it if it comes up again?

Copy link
Collaborator

@ncordon ncordon left a comment

Choose a reason for hiding this comment

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

I think it's still not working correctly and there are a few details to polish.

When I am on VSCode, I get the error on :PARAM, but the moment I write something else, that error disappears and I get no auto-completions for normal cypher keywords:

And:

Copy link
Collaborator

@ncordon ncordon left a comment

Choose a reason for hiding this comment

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

After discussing with Oskar we agreed on improving the error message in the case :PARAM MATCH (n) to still show you cannot use console commands in VSCode.

Good work 💃 !

@OskarDamkjaer OskarDamkjaer changed the title Console commands basic implementation Console command support (:use, :params, :clear) Feb 7, 2024
@OskarDamkjaer OskarDamkjaer changed the title Console command support (:use, :params, :clear) Console command support (:use, :params, :clear, history) Feb 7, 2024
@OskarDamkjaer OskarDamkjaer merged commit 8cc77c6 into main Feb 7, 2024
4 checks passed
@OskarDamkjaer OskarDamkjaer deleted the relevant_client_cmds branch February 7, 2024 10:10
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