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

Simplify getting SourceText in source generator #138

Merged
merged 1 commit into from May 25, 2022

Conversation

Neme12
Copy link
Contributor

@Neme12 Neme12 commented May 25, 2022

There's no reason to create a SyntaxTree first. The text will be reparsed anyway by Roslyn. This change avoids doing additional work in the source generator for no benefit. The best way to add a source from a CompilationUnitSyntax is to use compilationUnit.GetText(Encoding.UTF8). See dotnet/roslyn-analyzers#6017

I noticed this in dotnet/roslyn#122, which I found a link to in https://github.com/AArnott/CodeGeneration.Roslyn.

There's no reason to create a `SyntaxTree` first. The text will be reparsed anyway by Roslyn. This change avoid doing additional work in the source generator for no benefit. The recommended way to add a source from a `CompilationUnitSyntax` is to use `compilationUnit.GetText(Encoding.UTF8)`. See https://github.com/dotnet/roslyn/issues/61506
Copy link
Member

@amis92 amis92 left a comment

Choose a reason for hiding this comment

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

Thank you so much! This is indeed a good fix, I appreciate the time you took to fix, push and explain the change! :)

@amis92 amis92 merged commit d83b281 into WarHub:master May 25, 2022
@Neme12 Neme12 deleted the patch-1 branch May 25, 2022 17:59
@amis92 amis92 added this to the v0.14 milestone Oct 17, 2022
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.

None yet

2 participants