roslyn
roslyn copied to clipboard
Reference highlighting doesn't work for some types from constructor expression
Version Used: 17.12.0 P1
Steps to Reproduce:
Look at how highlighting of references of FinishedStatus doesn't work if I select the symbol in a constructor expression, while it works if I select the type in a declaration expression:
https://github.com/user-attachments/assets/738ce980-7380-46a2-96d9-7c75476b840d
[JsonPolymorphic]
[JsonDerivedType(typeof(FinishedStatus), "Jobs.Finished")]
public abstract record class JobStatusUpdate(DateTimeOffset Timestamp);
public record class FinishedStatus(DateTimeOffset Timestamp) : JobStatusUpdate(Timestamp);
Unfortunately, I could not narrow down the context in which it doesn't work. But it never picks up this type (or any of its siblings - inherited from JobStatusUpdate) in any file in the whole solution.
Notes:
- Code compiles successfully
- Go To Definition and Find All References work fine
Diagnostic Id: N/A
Expected Behavior: It finds and highlights references from all starting points.
Actual Behavior: It does not highlight references from a constructor expression.
I cannot reproduce this in 17.12.0 P3
It is still broken for me (in 17.12 P3):
https://github.com/user-attachments/assets/4b4af81e-cb79-4246-b273-cdf5807bb2bb
Your FailedStatus seems to be in another file, right? That could also be it.
Yes, and you nailed it! Once I move them to the same file, it finds the references both ways.
I tried to reproduce this in both 17.11, 17.12 P3 and the current main (7d58a7f), but could not see this happen to me. Wrote the exact code you show in the videos, added a partial Extensions class with 2 partial declarations in separate files, used the constructor in multiple files and it still works; the identifiers are properly highlighted, find all references finds all the constructors and go to definition also works.
This is a very strange case. Perhaps try restarting VS, using another VS color theme? Maybe post some more code to provide critical context that could be missing?
I cannot repro this either. Please support a repro project if you are still seeing this.
I can still do in a large project:
https://github.com/user-attachments/assets/cbd732e9-14c6-4521-9868-22c94fe4c287
But unfortunately, if I copy the same files in the same structure into a small console app, it works fine. So, my guess is it may be related to some timing/cancellation issues, perhaps it finishes quickly in a small project, but takes more time in a large project to calculate the references and gets cancelled meanwhile?
I've seen other issues (Go to definition, Quick info, ..) were closed by fixing an issue related to cancellation (thank you, I appreciate the effort!), maybe this one has the same root cause, or already fixed by those changes.
I confirm the above; I've also seen this here and there on larger projects and slower machines, while it always seems to work fine in other cases, including tests
Does this repro for you on 17.13 builds?
Yes, I'm on VS 17.13.0 Preview 1.0, .NET 9.0.100 (and Intel i9-13900K with 64 GB RAM).
Total number of files: 979
| Extension | Files | Lines |
|---|---|---|
| .cs | 607 | 105985 |
| .razor | 135 | 24155 |
| .cshtml | 1 | 50 |
@CyrusNajmabadi has #76097 fixed this?