dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19k stars 4.03k forks source link

Reference highlighting doesn't work for some types from constructor expression #74803

Open Peter-Juhasz opened 2 months ago

Peter-Juhasz commented 2 months ago

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:

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.

Rekkonnect commented 1 day ago

I cannot reproduce this in 17.12.0 P3

Peter-Juhasz commented 1 day ago

It is still broken for me (in 17.12 P3):

https://github.com/user-attachments/assets/4b4af81e-cb79-4246-b273-cdf5807bb2bb

Rekkonnect commented 1 day ago

Your FailedStatus seems to be in another file, right? That could also be it.

Peter-Juhasz commented 1 day ago

Yes, and you nailed it! Once I move them to the same file, it finds the references both ways.

Rekkonnect commented 7 hours ago

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?