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

Splits parsing of statements #171

Merged
merged 9 commits into from
Feb 28, 2024
Merged

Splits parsing of statements #171

merged 9 commits into from
Feb 28, 2024

Conversation

ncordon
Copy link
Collaborator

@ncordon ncordon commented Feb 6, 2024

What

Parses a query with independent statements.

Why

Because we want to have independent statements for the collected variables, which get offered in auto-completions, but also to avoid destroying and recreating the parsing several times on every keystroke.

@ncordon ncordon added the work-in-progress Work in progress, don't review label Feb 6, 2024
@ncordon ncordon force-pushed the independent-st-parsing branch from f1ab795 to 71299a7 Compare February 6, 2024 11:23
@ncordon ncordon force-pushed the independent-st-parsing branch from 71299a7 to be38e8c Compare February 6, 2024 16:40
}
}

export function findCaret(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just moves and reshapes this from the signature help, hopefully it can be reused for the auto-completion

Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like there should be a good way to find where the cursor is in the tree without having to go looking for it, but I've not found anything either, a bit dissapointing

@ncordon ncordon force-pushed the independent-st-parsing branch from f25383d to 02586b0 Compare February 13, 2024 09:29
@ncordon ncordon assigned ncordon and OskarDamkjaer and unassigned ncordon Feb 13, 2024
@ncordon ncordon removed the work-in-progress Work in progress, don't review label Feb 13, 2024
Copy link
Collaborator

@OskarDamkjaer OskarDamkjaer left a comment

Choose a reason for hiding this comment

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

Nice work! I've mostly left some questions to understand the changes better 👍

@@ -85,15 +84,14 @@ function warnOnUndeclaredLabels(

type FixSemanticPositionsArgs = {
semanticElements: SemanticAnalysisElement[];
cmd: ParsedCypherCmd;
parseResult: EnrichedParsingResult;
parseResult: StatementParsing;
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 nit, but I think we could find a better name for StatementParsing since it doesn't sound like the result of an operation to me. Perhaps something like ParsedStatements, PartialParseResult or StatementParseResult ?

});
/**
* Assumes the provided query has no parse errors
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we do the parse here anyway, why assume that there are no parse errors when we can just check cachedParse.diagnostics?

export function signatureHelp(
fullQuery: string,
dbSchema: DbSchema,
caretPosition: number,
): SignatureHelp {
let result: SignatureHelp = emptyResult;

// TODO Is this check needed
Copy link
Collaborator

Choose a reason for hiding this comment

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

are you leaving this for the next pr as well?

expectParsedCommands(':history;', [{ type: 'history' }]);
expectParsedCommands(':history;', [
{ type: 'history' },
{ type: 'parse-error' },
Copy link
Collaborator

Choose a reason for hiding this comment

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

My gut feeling is that this should not give a parse error here. To me it makes sense that empty string on it's own should be a parse error, but empty string as the last statement in a list should not be considered a statement at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It should be considered a statement cause I do need the auto-completion to pick up that we are in a new statement to suggest new things.

I've changed this for { statement: ''", type: "cypher"}


const anySyntacticError =
statements.filter((statement) => statement.diagnostics.length !== 0)
.length > 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

For convenience it could be interesting to have something aggregating helper functions on the top level parse result?

const parse = parserWrapper.parse(query);
if(parse.getAllDiagnostics().length > 0) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wouldn't that be creating extra objects (cause we need to concatenate possibly a few arrays from the internal statements)?

Not sure there's a logical view for arrays in Typescript or a similar concept

@ncordon ncordon merged commit 2ed0598 into main Feb 28, 2024
4 checks passed
@ncordon ncordon deleted the independent-st-parsing branch February 28, 2024 11:53
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