-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add in a json parser so that the IDE can provide services around json editing. #24110
Add in a json parser so that the IDE can provide services around json editing. #24110
Conversation
Tagging @dotnet/roslyn-ide @Pilchie |
@CyrusNajmabadi Should we wait until the regex one is resolved prior to looking at this one? This PR is quite, quite large. |
That woudl be my recommendation :)
It's a mere 46k lines. If you do 2k lines an hour, you can finish it by tomorrow! |
Can we just keep you in various airports? 😆 |
Tomorrow LaGuardia! |
c06a692
to
682762e
Compare
ImmutableArray<JsonTrivia> trailingTrivia, ImmutableArray<EmbeddedDiagnostic> diagnostics) | ||
=> CreateToken(kind, leadingTrivia, virtualChars, trailingTrivia, diagnostics, value: null); | ||
|
||
public static JsonToken CreateToken(JsonKind kind, |
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 method is only used once (on line 20). Inline?
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.
done. #resolved.
|
||
internal static class JsonHelpers | ||
{ | ||
public static JsonToken CreateToken(JsonKind kind, ImmutableArray<JsonTrivia> leadingTrivia, ImmutableArray<VirtualChar> virtualChars, ImmutableArray<JsonTrivia> trailingTrivia) |
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.
Nit: maybe break this line
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.
done. #resolved.
Could you retarget to the feature branch? |
{ | ||
internal enum JsonKind | ||
{ | ||
None, |
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.
Is this used? If not, maybe None = 0
or 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.
i like this as it makes it easy to test if a token is default.
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.
Should it be None = 0
then?
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.
Sure. i can do that.
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.
#resolved.
Text = text; | ||
} | ||
|
||
public VirtualChar CurrentChar => Position < Text.Length ? Text[Position] : new VirtualChar((char)0, default); |
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.
Nit: name span: default
?
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.
done. #resolved.
|
||
public VirtualChar CurrentChar => Position < Text.Length ? Text[Position] : new VirtualChar((char)0, default); | ||
|
||
public ImmutableArray<VirtualChar> GetSubPattern(int start, int end) |
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.
end
is generally Position
. Consider adding an overload where end is implicit.
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.
done. #resolved.
case '\'': case '"': | ||
return ScanString(); | ||
|
||
//case '-': case '.': |
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.
Why is this commented out?
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.
Added comment explaining why we do not explicitly lex out numbers here, but instead let the parser take control. #resolved.
private (ImmutableArray<VirtualChar>, JsonKind, EmbeddedDiagnostic?) ScanString() | ||
{ | ||
var start = Position; | ||
var startChar = this.CurrentChar.Char; |
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.
Perhaps rename openChar
?
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.
done. #resolved.
return (chars, JsonKind.StringToken, diagnostic); | ||
} | ||
|
||
private EmbeddedDiagnostic? ScanEscape(int stringStart, int escapeStart) |
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.
ScanEscape
could use a comment since unlike other scan methods, it doesn't return tokens or nodes, it just advances the position.
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.
done. #Resolved
return (GetSubPattern(start, Position), JsonKind.TextToken, null); | ||
} | ||
|
||
private (ImmutableArray<VirtualChar>, JsonKind, EmbeddedDiagnostic?)? TryScanText( |
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 method seems unused
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.
indeed. removed. #resolved.
var chars = GetSubPattern(start, Position); | ||
if (Position == start + 2) | ||
{ | ||
var diagnostics = ImmutableArray.Create(new EmbeddedDiagnostic( |
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.
What if //
are the last two characters in the file?
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.
then you get an unterminated comment diagnostic. This matches json.net. You can see a test for that here: https://github.com/dotnet/roslyn/pull/25521/files#diff-d0475d1c64e0a4bb26665ae88ff3cf24R158
Will add a comment explaining this is intentional.
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.
added comment. #resolved.
GetTextSpan(start, Position)))); | ||
} | ||
|
||
public TextSpan GetTextSpan(int startInclusive, int endExclusive) |
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 method seems to only be used once. private?
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.
made privat.e #resolved
840fa0c
to
61f91ca
Compare
@sharwell @jinujoseph How would you like to proceed on this? |
1 similar comment
@sharwell @jinujoseph How would you like to proceed on this? |
Unfortunately, This feature is currently not in the top priority for us to pursue, so this is on hold at this moment. Following up to see if we can get merge this to feature branch |
@CyrusNajmabadi as discussed closing this PR for now. |
Followup to #23984
So JFK has busted pipes. So i've been in airport limbo :-( On a good note, it gave me some time to expand on my previous Regex PR. Now, on top of Regex support in the IDE we also support JSON strings.
This also expands the previous interaction model with built in json detection for string tokens. i.e., if we see:
Then we'll offer:
This then helps users see how they can add a comment that lights-up IDE features for these types of strings. Note: i don't do this for regexes because of a concern about too many false positives. Once the comment is added things like up like so:
Of course, squiggles and braces are supported, on top of just colors:
Also, if you're using JToken/JObject/JArray, then you don't need to provide the comment (similar to how
new Regex(pattern)
is automatically detected:Things to note: