Skip to content
This repository was archived by the owner on Sep 26, 2024. It is now read-only.

Use Roslyn to parse type names #45

Closed
wants to merge 1 commit into from

Conversation

javiercn
Copy link
Member

@javiercn javiercn commented Jan 25, 2022

Contributes to dotnet/aspnetcore#38879

The exception source seems to be coming from a place where we split a full type name into its type name and namespace. Instead of using our own "dubious" parsing logic, rely on the roslyn APIs to do the parsing.

This entailed adding a new method to TypeNameFeature and flowing that to the type that performs this operation.

@javiercn javiercn force-pushed the javiercn/stop-parsing-typenames-manually branch from 2cd0e18 to 4edff18 Compare January 25, 2022 14:59
@javiercn javiercn marked this pull request as ready for review January 25, 2022 15:20
@javiercn javiercn requested a review from a team as a code owner January 25, 2022 15:20
{ "Foo", true, "", "Foo"},
{ "SomeProject.Foo", true, "SomeProject", "Foo"},
{ "SomeProject.Foo<Bar>", true, "SomeProject", "Foo<Bar>"},
{ "SomeProject.Foo<Bar.Baz>", true, "SomeProject", "Foo<Bar.Baz>"},
{ "SomeProject.Foo<Bar.Baz>>", true, "", "SomeProject.Foo<Bar.Baz>>"},
{ "SomeProject.Foo<Bar.Baz>>", true, "SomeProject", "Foo<Bar.Baz>>"},
Copy link
Member

Choose a reason for hiding this comment

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

This is weird. Is it testing for a syntax error? Do we care about what the parsing output would be in that case?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we care about these cases. I'm not sure they represent "real" scenarios and the logic for parsing is "dubious" at the very least, so now we at least we don't do our own parsing.

Copy link
Member

Choose a reason for hiding this comment

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

OK, fair enough

{
case GenericNameSyntax genericNameSyntax:
typeName = genericNameSyntax.ToFullString();
typeNamespace = "";
Copy link
Member

Choose a reason for hiding this comment

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

When does this happen? Getting an empty namespace is pretty strange. But looking at the test cases, I didn't spot one where the namespace actually came back as empty (at least, when type was fully qualified).

Copy link
Member Author

@javiercn javiercn Jan 25, 2022

Choose a reason for hiding this comment

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

IEnumerable<Hello>

Copy link
Member Author

Choose a reason for hiding this comment

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

I might add some additional test cases, I didn't want to invest more time on it before validating the approach E2E with the tests. I also need to check with tooling folks if there's any drawback WRT to tooling scenarios (which I don't think there is)

Copy link
Member

Choose a reason for hiding this comment

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

I edited my comment before I saw your reply, but possibly after you posted your reply.

at least, when type was fully qualified

OK, so I guess it's more that "namespace is only given when the syntax is QualifiedNameSyntax" in which case cool.

@javiercn
Copy link
Member Author

There's a follow-up PR to get rid of more "in-house" type parsing in favor of leveraging roslyn APIs following the same approach employed here.

Copy link
Member

@SteveSandersonMS SteveSandersonMS left a comment

Choose a reason for hiding this comment

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

Looks good!

Copy link
Contributor

@pranavkm pranavkm left a comment

Choose a reason for hiding this comment

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

Nice! My only concern is that we'd updated the previous implementation to use StringSegments since this API featured at the top of allocations which this would now undo.

@javiercn
Copy link
Member Author

@pranavkm that was one of my concerns too, maybe we can talk about it more in depth. I was focusing on correctness first and avoiding our whacky parsing, but we can probably make it more efficient.

@pranavkm
Copy link
Contributor

pranavkm commented Feb 4, 2022

@javiercn can we merge this?

Copy link
Contributor

@TanayParikh TanayParikh left a comment

Choose a reason for hiding this comment

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

:shipit:

@javiercn
Copy link
Member Author

javiercn commented Feb 8, 2022

@pranavkm can we hold on until we get to the root cause of what's happening on the original issue?

@TanayParikh and me looked at this yesterday, and while we think this change is an improvement, we think that the root cause of the issue is that somehow we end up with an invalid StringSegment where the buffer is null but the length is not 0.
We are waiting for more info on some dumps that are available to get confirmation and then we'll get this in after we confirm

@javiercn
Copy link
Member Author

Closing since ca1728b supersedes this.

@javiercn javiercn closed this Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants