dotnet / roslyn-analyzers

MIT License
1.58k stars 464 forks source link

Avoid direct descriptor comparison, so the fix can be shown #7296

Closed DoctorKrolic closed 5 months ago

DoctorKrolic commented 5 months ago

Fixes: https://github.com/dotnet/roslyn-analyzers/issues/4539

It turned out that despite DiagnosticDescriptor class is fully equatable, it isn't safe to compare instances in a codefix due to localized strings. For whatever reason all localizable strings in diagnostic.Descriptor are fixed strings while singleton descriptor instances in tha analyzer contain localizable resource strings, so the comparison could never succeed and thus fixes were not shown. I guess, this might be due to serialization-deserialization between devenv and roslyn OOP. To avoid that I made it so that diagnostics are now identified via Rule property, which is correctly passed between analyzer and a codefix provider. I've made a local setup where I verified, that this actually resolves the problem and the fix is finally shown. I don't really like the proposed fix, but that is a story for another PR)

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 96.47%. Comparing base (b07c100) to head (aba7cf1). Report is 2 commits behind head on main.

:exclamation: Current head aba7cf1 differs from pull request most recent head 37a5a32. Consider uploading reports for the commit 37a5a32 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #7296 +/- ## ========================================== - Coverage 96.48% 96.47% -0.01% ========================================== Files 1443 1443 Lines 345394 345395 +1 Branches 11364 11364 ========================================== - Hits 333240 333237 -3 - Misses 9275 9278 +3 - Partials 2879 2880 +1 ```
DoctorKrolic commented 5 months ago

Seems like CI is stuck