-
Notifications
You must be signed in to change notification settings - Fork 43
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
AstVisitor rework #149
AstVisitor rework #149
Conversation
Is this all synchronous code? Synchronous code that writes streams should be deprecated and replaced with async code, just like what was done with System.Text.Json. Certainly we should not be writing new synchronous code here in 2021. And even more certainly if we are replacing the visitor api, it should be a new async api. This is a good candidate for using ValueTask, however, to eliminate allocations when writing to a string builder or other non-async stream. Or for any other non-async needs of the visitor api. |
|
Nevermind, I can change all signatures to |
src/Directory.Build.props
Outdated
@@ -19,7 +19,7 @@ | |||
<!-- https://github.com/clairernovotny/DeterministicBuilds --> | |||
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">True</ContinuousIntegrationBuild> | |||
<EnableNETAnalyzers>true</EnableNETAnalyzers> | |||
<NoWarn>$(NoWarn);1591</NoWarn> <!--TODO: temporary solution, remove--> | |||
<NoWarn>$(NoWarn);1591;IDE1006</NoWarn> <!--TODO: temporary solution, remove--> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Async
suffix rule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering why you decided to have the Visit methods not end in Async?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Year or two ago I would do so, yes. I know about all those recommendations and styles. I control several hundred repos at work unifiing code style/design and this have always been one of the permanent questions. My intuition suggests me that if the API is initially designed as (completely) asynchronous, then it makes no sense to append Async
everywhere. It only creates additional noise. By the way, I remove that suppression from dir.props, see .editorconfig file.
@@ -142,7 +143,7 @@ namespace GraphQLParser.AST | |||
public System.Collections.Generic.List<GraphQLParser.AST.GraphQLDirective>? Directives { get; set; } | |||
public override GraphQLParser.AST.ASTNodeKind Kind { get; } | |||
public GraphQLParser.AST.GraphQLSelectionSet? SelectionSet { get; set; } | |||
public GraphQLParser.AST.GraphQLNamedType? TypeCondition { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see http://spec.graphql.org/October2021/#sec-Inline-Fragments and http://spec.graphql.org/October2021/#FragmentDefinition - TypeCondition node should be added
@@ -1149,6 +1144,7 @@ private GraphQLVariableDefinition ParseVariableDefinition() | |||
|
|||
def.Type = ParseType(); | |||
def.DefaultValue = Skip(TokenKind.EQUALS) ? ParseValueLiteral(true) : null; | |||
def.Directives = ParseDirectives(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VariableDefinition may have directives
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great! Here's a few comments, mostly about escaping strings and adding some cancellation token support.
{ | ||
await Visit(stringValue.Comment, context); | ||
await context.Writer.WriteAsync('\"'); | ||
await Write(context, stringValue.Value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs escaping of various characters; please add test.
Optional: detect if the string is multi-line, and can be formatted as a blockstring without loss of data, and if both are true, print it that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and can be formatted as a blockstring without loss of data
Example ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took test data from lexer tests. This is your test with 30 cases. I changed some values. Honestly, work with escape symbols is very tired. I would like to finish with this PR and go on. I could be mistaken somewhere, further use will show. We will add tests. Or you can add additional test cases yourself where you think right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree to finish the PR and go on. The API will not change if we improve these methods in a later PR, either to fix an issue or enhance performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK to wait 1-2-3 days for your review. At least until I start a new branch working on type extensions. I am 80% sure that I have errors in formatting/edge cases.
} | ||
|
||
/// <inheritdoc/> | ||
public override async ValueTask VisitDescription(GraphQLDescription description, TContext context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all strings can be written in the blockstring format. For example, a string that starts with a newline. This method should ideally check to be sure the input string can be formatted as a blockstring without loss of information, and if not, be formatted as a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and if not, be formatted as a string.
One-line string? Or are you talking about change description node into comment ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #149 (comment)
Please show an example here or add a test case yourself. I'm a little confused with all this escaping stuff.
case '\r': | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: with this logic, description strings encoded with CRLF will result in strings being encoded as LF after being decoded. I suggest adding a comment within the method that this change may take place -- or better yet, encode strings containing CRs as strings instead of blockstrings. Tests should be added either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strings instead of blockstrings
I'm still confused about string vs blockstring, can you give an example?
By the way I want to rewrite both methods for comment and description node. Now I added the Slice
call to get around the problem:
CS4012 Parameters or locals of type 'ReadOnlySpan<char>' cannot be declared in async methods or async lambda expressions.
In addition, I do not really like this char-by-char transmission. At first I wrote a method that finds the chain of non-\r\n
chars and writes those spans into writer, but it was rather complicated so I swiched to char-by-char.
By the way, should we be adding |
Of course. |
add cancellation support add comments
@Shane32 I have left to solve the issues with strings/blockstrings encoding. I'll do it tomorrow or in the coming days. |
What is done for now:
|
@Shane32 Waiting for examples. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only major issue I see is that string values are not escaped. You already wrote code within VisitDescription to encode strings; just copy or reuse the code block and it should be fine. I can do a detailed review of the encoding for strings and blockstrings at a later time and add another PR if I see any other suggestions. Ok?
ping @Shane32 , any suggestions/comments/test cases? |
Not at this time. |
Codecov Report
@@ Coverage Diff @@
## master #149 +/- ##
==========================================
- Coverage 91.91% 89.61% -2.31%
==========================================
Files 50 55 +5
Lines 2498 3263 +765
Branches 278 333 +55
==========================================
+ Hits 2296 2924 +628
- Misses 180 300 +120
- Partials 22 39 +17
Continue to review full report at Codecov.
|
fixes #11 , supersedes #20
Visitors API was completely rewritten, optimized, tested.