Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jcouv
Copy link
Member

@jcouv jcouv commented Dec 16, 2025

Closes #81710

The problem in #81710 turns out to be a problem with GetSymbolInfo. GetSymbolInfo should succeed in finding the extension member not only when given the E.extension(...).Member syntax but also just the Member portion of that syntax.
FindReferences in the IDE makes use of that, as it starts by identifying a symbol of interest, then syntactically tracks all the occurrences of the symbol's name, then queries the semantic model for each instance (see FindReferencesInTokens) to check which instances actually refer to the given symbol.

@jcouv jcouv self-assigned this Dec 16, 2025
@jcouv jcouv added Area-Compilers Feature - Extension Everything The extension everything feature labels Dec 16, 2025
@jcouv jcouv force-pushed the extension-cref branch 2 times, most recently from c6f029a to df2e0f0 Compare December 16, 2025 20:42
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81710"]
public void Cref_68()
{
var src = """
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi Dec 16, 2025

Choose a reason for hiding this comment

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

raw string? #Resolved

Copy link
Member

Choose a reason for hiding this comment

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

(indented raw string, rather).

Copy link
Member Author

Choose a reason for hiding this comment

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

The formatting is intentional

@jcouv jcouv marked this pull request as ready for review December 17, 2025 00:07
@jcouv jcouv requested review from a team as code owners December 17, 2025 00:07

<WpfTheory, CombinatorialData>
<WorkItem("https://github.com/dotnet/roslyn/issues/81710")>
Public Async Function FindReferences_ExtensionBlockMethod_Cref(kind As TestKind, host As TestHost) As Task
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi Dec 17, 2025

Choose a reason for hiding this comment

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

nice. i'm glad this just fell out. #Resolved

var m = ((NameMemberCrefSyntax)extensionCref.Member).Name;
Assert.Equal("M", m.ToString());
AssertEx.Equal("E.extension(int).M(string)", model.GetSymbolInfo(m).Symbol.ToDisplayString());
}
Copy link
Member

@jjonescz jjonescz Dec 17, 2025

Choose a reason for hiding this comment

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

Consider asserting those found symbols are the same (reference equals) between themselves and also with the E.M symbol found outside the doc comment. #ByDesign

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I don't think there's a requirement that the symbols from semantic model be reference equal. Definitions should be reference equal, but that's not about the semantic model and here we're not dealing with definitions in this test anyways.

<Workspace>
<Project Language="C#" CommonReferences="true" LanguageVersion="Preview">
<Document>
/// &lt;see cref="E.extension(int).[|M|]()"/>
Copy link
Member

@jjonescz jjonescz Dec 17, 2025

Choose a reason for hiding this comment

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

Consider wrapping the code in <![CDATA[]]> instead of xml-encoding parts of it. #ByDesign

Copy link
Member Author

Choose a reason for hiding this comment

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

I leaned towards this encoding

AssertEx.Equal("E.extension(int).M(string)", model.GetSymbolInfo(extensionCref).Symbol.ToDisplayString());
var m = ((NameMemberCrefSyntax)extensionCref.Member).Name;
Assert.Equal("M", m.ToString());
AssertEx.Equal("E.extension(int).M(string)", model.GetSymbolInfo(m).Symbol.ToDisplayString());
Copy link
Contributor

@AlekseyTs AlekseyTs Dec 17, 2025

Choose a reason for hiding this comment

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

m

Consider also testing for extensionCref.Member #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. That uncovered another problem

public void Cref_68()
{
var src = """
/// <see cref="E.extension(int).M(string)"/>
Copy link
Contributor

@AlekseyTs AlekseyTs Dec 17, 2025

Choose a reason for hiding this comment

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

E

Consider testing with additional qualifications (more dotted parts) #Closed


<WpfTheory, CombinatorialData>
<WorkItem("https://github.com/dotnet/roslyn/issues/81710")>
Public Async Function FindReferences_ExtensionBlockMethod_Cref(kind As TestKind, host As TestHost) As Task
Copy link
Contributor

@AlekseyTs AlekseyTs Dec 17, 2025

Choose a reason for hiding this comment

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

FindReferences_ExtensionBlockMethod_Cref

Consider covering all scenarios covered in added compiler test(s)

Copy link
Contributor

Choose a reason for hiding this comment

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

Consider covering all scenarios covered in added compiler test(s)

This thread was resolved, but I do not see any changes made in response. Since these are not compiler tests, I am going to sign off, but I will reactivate the thread in case you resolved it by mistake.

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 3)

@jcouv jcouv requested review from AlekseyTs and jjonescz December 17, 2025 19:01
Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 5)

@jcouv jcouv merged commit bf35fe5 into dotnet:main Dec 18, 2025
29 checks passed
@jcouv jcouv deleted the extension-cref branch December 18, 2025 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FindAllReferences does not track extension members in CREF

4 participants