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

Fix Peek Definition for Razor files #59528

Merged
merged 1 commit into from
Feb 14, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void FindResults(string relationshipName, IPeekResultCollection resultCol

foreach (var declaration in sourceLocations)
{
var declarationLocation = declaration.GetLineSpan();
var declarationLocation = declaration.GetMappedLineSpan();

var entityOfInterestSpan = PeekHelpers.GetEntityOfInterestSpan(symbol, workspace, declaration, cancellationToken);
resultCollection.Add(PeekHelpers.CreateDocumentPeekResult(declarationLocation.Path, declarationLocation.Span, entityOfInterestSpan, _peekableItem.PeekResultFactory));
Expand Down
2 changes: 1 addition & 1 deletion src/EditorFeatures/Core.Wpf/Peek/PeekHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ internal static LinePositionSpan GetEntityOfInterestSpan(ISymbol symbol, Workspa
break;
}

return identifierLocation.SourceTree.GetLocation(node.Span).GetLineSpan().Span;
return identifierLocation.SourceTree.GetLocation(node.Span).GetMappedLineSpan().Span;
}
}
}
39 changes: 39 additions & 0 deletions src/EditorFeatures/Test2/Peek/PeekTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,45 @@ End Module

End Sub

<WpfFact, WorkItem(820363, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/820363"), Trait(Traits.Feature, Traits.Features.Peek)>
Public Sub TestFileMapping()
Using workspace = CreateTestWorkspace(<Workspace>
<Project Language="C#" CommonReferences="true">
<Document><![CDATA[
public class D
{
public void M()
{
new Component().$$M();
}
}
]]></Document>
<Document FilePath="Test.razor"><![CDATA[
@code
{
public void {|Identifier:M|}()
{
}
}
]]></Document>
<Document FilePath="Test.razor.g.cs"><![CDATA[
public class Component
{
#line 4 "Test.razor"
public void M()
{
}
}
]]></Document>
</Project>
</Workspace>)
Dim result = GetPeekResultCollection(workspace)

Assert.Equal(1, result.Items.Count)
result.AssertNavigatesToIdentifier(0, "Identifier")
End Using
End Sub

Private Shared Function CreateTestWorkspace(element As XElement) As TestWorkspace
Return TestWorkspace.Create(element, composition:=EditorTestCompositions.EditorFeaturesWpf)
End Function
Expand Down