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

Include source generators in TryGetMethodDescriptorAsync #51686

Merged
merged 3 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/EditorFeatures/CSharpTest/CodeLens/CSharpCodeLensTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,5 +350,36 @@ private void Test()
</Workspace>";
await RunReferenceTest(input);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeLens)]
[WorkItem(51633, "https://github.com/dotnet/roslyn/issues/51633")]
public async Task TestMethodRefSourceGeneratedDocument()
{
const string input = @"<Workspace>
<Project Language=""C#"" CommonReferences=""true"" AssemblyName=""Proj1"">
<Document FilePath=""Program.cs""><![CDATA[
namespace ConsoleSample
{
class Program
{
{|1:public Program()
{
}|}
}
}]]>
</Document>
<DocumentFromSourceGenerator><![CDATA[
namespace ConsoleSample
{
internal partial class Program
{
public static CreateProgram() => new Program();
}
}]]>
</DocumentFromSourceGenerator>
</Project>
</Workspace>";
await RunMethodReferenceTest(input);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,12 @@ private static ISymbol GetEnclosingMethod(SemanticModel semanticModel, Location

private static async Task<ReferenceMethodDescriptor> TryGetMethodDescriptorAsync(Location commonLocation, Solution solution, CancellationToken cancellationToken)
{
var doc = solution.GetDocument(commonLocation.SourceTree);
if (doc == null)
var document = solution.GetDocument(commonLocation.SourceTree);
if (document == null)
{
return null;
}

var document = solution.GetDocument(doc.Id);
Copy link
Member

Choose a reason for hiding this comment

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

I am terrified to wonder how this code ever happened in the first place.

var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var fullName = GetEnclosingMethod(semanticModel, commonLocation, cancellationToken)?.ToDisplayString(MethodDisplayFormat);

Expand Down