Skip to content

Commit

Permalink
Allow source link, embedded or decompiled source in Peek Definition (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwengier authored May 23, 2022
1 parent a51b65c commit 038b1a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/EditorFeatures/Core.Wpf/Peek/DefinitionPeekableItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public void FindResults(string relationshipName, IPeekResultCollection resultCol
{
// It's a symbol from metadata, so we want to go produce it from metadata
var options = _peekableItem._globalOptions.GetMetadataAsSourceOptions(project.LanguageServices);
var declarationFile = _peekableItem._metadataAsSourceFileService.GetGeneratedFileAsync(project, symbol, signaturesOnly: true, options, cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken);
var peekDisplayInfo = new PeekResultDisplayInfo(declarationFile.DocumentTitle, declarationFile.DocumentTitle, declarationFile.DocumentTitle, declarationFile.DocumentTitle);
var declarationFile = _peekableItem._metadataAsSourceFileService.GetGeneratedFileAsync(project, symbol, signaturesOnly: false, options, cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken);
var peekDisplayInfo = new PeekResultDisplayInfo(declarationFile.DocumentTitle, declarationFile.DocumentTooltip, declarationFile.DocumentTitle, declarationFile.DocumentTooltip);
var identifierSpan = declarationFile.IdentifierLocation.GetLineSpan().Span;
var entityOfInterestSpan = PeekHelpers.GetEntityOfInterestSpan(symbol, workspace, declarationFile.IdentifierLocation, cancellationToken);
resultCollection.Add(PeekHelpers.CreateDocumentPeekResult(declarationFile.FilePath, identifierSpan, entityOfInterestSpan, peekDisplayInfo, _peekableItem.PeekResultFactory, isReadOnly: true));
Expand Down
17 changes: 12 additions & 5 deletions src/EditorFeatures/Test2/Peek/PeekTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Peek
Dim result = GetPeekResultCollection(workspace)

Assert.Equal(1, result.Items.Count)
Assert.Equal($"String [{FeaturesResources.from_metadata}]", result(0).DisplayInfo.Label)
Assert.Equal($"String [{FeaturesResources.from_metadata}]", result(0).DisplayInfo.Title)
Assert.Equal($"String [{FeaturesResources.Decompiled}]", result(0).DisplayInfo.Label)
Assert.Equal($"String [{FeaturesResources.Decompiled}]", result(0).DisplayInfo.Title)
Assert.True(result.GetRemainingIdentifierLineTextOnDisk(index:=0).StartsWith("String", StringComparison.Ordinal))
End Using
End Sub
Expand Down Expand Up @@ -98,9 +98,8 @@ End Class
Dim result = GetPeekResultCollection(workspace)

Assert.Equal(1, result.Items.Count)
Assert.Equal($"SerializableAttribute [{FeaturesResources.from_metadata}]", result(0).DisplayInfo.Label)
Assert.Equal($"SerializableAttribute [{FeaturesResources.from_metadata}]", result(0).DisplayInfo.Title)
Assert.True(result.GetRemainingIdentifierLineTextOnDisk(index:=0).StartsWith("New()", StringComparison.Ordinal)) ' Navigates to constructor
Assert.Equal($"SerializableAttribute [{FeaturesResources.Decompiled}]", result(0).DisplayInfo.Label)
Assert.Equal($"SerializableAttribute [{FeaturesResources.Decompiled}]", result(0).DisplayInfo.Title)
End Using
End Sub

Expand Down Expand Up @@ -387,6 +386,14 @@ public class Component
Throw New NotImplementedException()
End Function

Friend Function GetText() As String
Dim documentResult = DirectCast(Items(0), IDocumentPeekResult)
Dim textBufferService = _workspace.GetService(Of ITextBufferFactoryService)
Dim buffer = textBufferService.CreateTextBuffer(New StreamReader(documentResult.FilePath), textBufferService.InertContentType)

Return buffer.CurrentSnapshot.GetText()
End Function

''' <summary>
''' Returns the text of the identifier line, starting at the identifier and ending at end of the line.
''' </summary>
Expand Down

0 comments on commit 038b1a9

Please sign in to comment.