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

[sourcegen] use GetText() instead of opening files from disk #4128

Merged
merged 1 commit into from
Jan 13, 2022

Conversation

jonathanpeppers
Copy link
Member

Description of Change

The source generator was doing:

using (var reader = File.OpenText(projItem.AdditionalText.Path))

The problem with this, is you don't actually have to hit Ctrl+S in
Visual Studio to save the files. This is potentially loading stale
files on disk.

Instead we can use:

projItem.AdditionalText.GetText().ToString();

And this will give us the string contents of the file from the
in-memory Roslyn state.

This might solve some of the weird issues in the IDE such as #4098.

However, I'm still able to reproduce #4098 after making this change.

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)
  • Targets a single property for a single control (or intertwined few properties)
  • Adds the property to the appropriate interface
  • Avoids any changes not essential to the handler property
  • Adds the mapping to the PropertyMapper in the handler
  • Adds the mapping method to the WinUI, Android, iOS, and Standard aspects of the handler
  • Implements the actual property updates (usually in extension methods in the Platform section of Core)
  • Tags ported renderer methods with [PortHandler]
  • Adds an example of the property to the sample project (MainPage)
  • Adds the property to the stub class
  • Implements basic property tests in DeviceTests

Does this PR touch anything that might affect accessibility?

No

The source generator was doing:

    using (var reader = File.OpenText(projItem.AdditionalText.Path))

The problem with this, is you don't actually have to hit Ctrl+S in
Visual Studio to save the files. This is potentially loading stale
files on disk.

Instead we can use:

    projItem.AdditionalText.GetText().ToString();

And this will give us the string contents of the file from the
in-memory Roslyn state.

This might solve some of the weird issues in the IDE such as:

dotnet#4098

However, I'm still able to reproduce dotnet#4098 after making this change.
@jonathanpeppers
Copy link
Member Author

jonathanpeppers commented Jan 13, 2022

The diff is easier to read with ?w=1 or:

image

@Redth Redth merged commit 33e6652 into dotnet:main Jan 13, 2022
@jonathanpeppers jonathanpeppers deleted the sourcegenerator-fixes branch January 13, 2022 21:27
@github-actions github-actions bot locked and limited conversation to collaborators Dec 21, 2023
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.

None yet

2 participants