Skip to content

Commit

Permalink
Revert "Go To Implementation show metadata results (dotnet#59100)" (d…
Browse files Browse the repository at this point in the history
…otnet#59376)

This reverts commit e37f01d.
  • Loading branch information
RikkiGibson authored Feb 9, 2022
1 parent 11a5dfe commit f087088
Show file tree
Hide file tree
Showing 34 changed files with 93 additions and 507 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private static async Task<ImmutableArray<ISymbol>> FindSourceImplementationsAsyn

foreach (var linkedSymbol in linkedSymbols)
{
var implementations = await FindImplementationsWorkerAsync(
var implementations = await FindSourceImplementationsWorkerAsync(
solution, linkedSymbol, cancellationToken).ConfigureAwait(false);
foreach (var implementation in implementations)
{
Expand All @@ -125,34 +125,35 @@ static bool AddedAllLocations(ISymbol implementation, HashSet<(string filePath,
{
foreach (var location in implementation.Locations)
{
if (location.IsInSource && !seenLocations.Add((location.SourceTree.FilePath, location.SourceSpan)))
Contract.ThrowIfFalse(location.IsInSource);
if (!seenLocations.Add((location.SourceTree.FilePath, location.SourceSpan)))
return false;
}

return true;
}
}

private static async Task<ImmutableArray<ISymbol>> FindImplementationsWorkerAsync(
private static async Task<ImmutableArray<ISymbol>> FindSourceImplementationsWorkerAsync(
Solution solution, ISymbol symbol, CancellationToken cancellationToken)
{
var implementations = await FindSourceAndMetadataImplementationsAsync(solution, symbol, cancellationToken).ConfigureAwait(false);
var result = new HashSet<ISymbol>(implementations.Select(s => s.OriginalDefinition));
var sourceImplementations = new HashSet<ISymbol>(implementations.Where(s => s.IsFromSource()).Select(s => s.OriginalDefinition));

// For members, if we've found overrides of the original symbol, then filter out any abstract
// members these inherit from. The user has asked for literal implementations, and in the case
// of an override, including the abstract as well isn't helpful.
var overrides = result.Where(s => s.IsOverride).ToImmutableArray();
var overrides = sourceImplementations.Where(s => s.IsOverride).ToImmutableArray();
foreach (var ov in overrides)
{
for (var overridden = ov.GetOverriddenMember(); overridden != null; overridden = overridden.GetOverriddenMember())
{
if (overridden.IsAbstract)
result.Remove(overridden.OriginalDefinition);
sourceImplementations.Remove(overridden.OriginalDefinition);
}
}

return result.ToImmutableArray();
return sourceImplementations.ToImmutableArray();
}

private static async Task<ImmutableArray<ISymbol>> FindSourceAndMetadataImplementationsAsync(
Expand Down
2 changes: 1 addition & 1 deletion src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Friend Class GoToHelpers
metadataDefinitions = {}
End If

AssertEx.Equal(metadataDefinitions, actualDefintionsWithoutSpans)
Assert.Equal(actualDefintionsWithoutSpans, metadataDefinitions)
End If
End Using
End Function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToImplementation
<[UseExportProvider]>
Public Class GoToImplementationTests

Private Shared Async Function TestAsync(workspaceDefinition As XElement, host As TestHost, Optional shouldSucceed As Boolean = True, Optional metadataDefinitions As String() = Nothing) As Task
Private Shared Async Function TestAsync(workspaceDefinition As XElement, host As TestHost, Optional shouldSucceed As Boolean = True) As Task
Await GoToHelpers.TestAsync(
workspaceDefinition,
host,
Async Function(document As Document, position As Integer, context As SimpleFindUsagesContext) As Task
Dim findUsagesService = document.GetLanguageService(Of IFindUsagesService)
Await findUsagesService.FindImplementationsAsync(context, document, position, CancellationToken.None).ConfigureAwait(False)
End Function,
shouldSucceed,
metadataDefinitions)
shouldSucceed)
End Function

<Theory, CombinatorialData, Trait(Traits.Feature, Traits.Features.GoToImplementation)>
Expand Down Expand Up @@ -405,7 +404,7 @@ class C : IDisposable
</Project>
</Workspace>

Await TestAsync(workspace, host, metadataDefinitions:={"mscorlib:ActivationContext.Dispose", "mscorlib:AsymmetricAlgorithm.Dispose", "mscorlib:AsyncFlowControl.Dispose", "mscorlib:BinaryReader.Dispose", "mscorlib:BinaryWriter.Dispose", "mscorlib:CancellationTokenRegistration.Dispose", "mscorlib:CancellationTokenSource.Dispose", "mscorlib:CharEnumerator.Dispose", "mscorlib:CountdownEvent.Dispose", "mscorlib:CriticalHandle.Dispose", "mscorlib:CryptoAPITransform.Dispose", "mscorlib:DeriveBytes.Dispose", "mscorlib:Enumerator.Dispose", "mscorlib:Enumerator.Dispose", "mscorlib:Enumerator.Dispose", "mscorlib:Enumerator.Dispose", "mscorlib:EventListener.Dispose", "mscorlib:EventSource.Dispose", "mscorlib:ExecutionContext.Dispose", "mscorlib:FromBase64Transform.Dispose", "mscorlib:HashAlgorithm.Dispose", "mscorlib:HostExecutionContext.Dispose", "mscorlib:IsolatedStorageFile.Dispose", "mscorlib:ManualResetEventSlim.Dispose", "mscorlib:MemoryFailPoint.Dispose", "mscorlib:RandomNumberGenerator.Dispose", "mscorlib:RegistryKey.Dispose", "mscorlib:ResourceReader.Dispose", "mscorlib:ResourceSet.Dispose", "mscorlib:ResourceWriter.Dispose", "mscorlib:RijndaelManagedTransform.Dispose", "mscorlib:SafeHandle.Dispose", "mscorlib:SecureString.Dispose", "mscorlib:SecurityContext.Dispose", "mscorlib:SemaphoreSlim.Dispose", "mscorlib:Stream.Dispose", "mscorlib:SymmetricAlgorithm.Dispose", "mscorlib:Task.Dispose", "mscorlib:TextReader.Dispose", "mscorlib:TextWriter.Dispose", "mscorlib:ThreadLocal.Dispose", "mscorlib:Timer.Dispose", "mscorlib:ToBase64Transform.Dispose", "mscorlib:UnmanagedMemoryAccessor.Dispose", "mscorlib:WaitHandle.Dispose", "mscorlib:WindowsIdentity.Dispose", "mscorlib:WindowsImpersonationContext.Dispose", "mscorlib:X509Certificate.Dispose", "System.Core:CngKey.Dispose", "System.Core:CounterSet.Dispose", "System.Core:CounterSetInstance.Dispose", "System.Core:CounterSetInstanceCounterDataSet.Dispose", "System.Core:ECDiffieHellmanPublicKey.Dispose", "System.Core:Enumerator.Dispose", "System.Core:EventLogConfiguration.Dispose", "System.Core:EventLogPropertySelector.Dispose", "System.Core:EventLogReader.Dispose", "System.Core:EventLogSession.Dispose", "System.Core:EventLogWatcher.Dispose", "System.Core:EventProvider.Dispose", "System.Core:EventRecord.Dispose", "System.Core:MemoryMappedFile.Dispose", "System.Core:ProviderMetadata.Dispose", "System.Core:ReaderWriterLockSlim.Dispose", "System:AlternateViewCollection.Dispose", "System:AttachmentBase.Dispose", "System:AttachmentCollection.Dispose", "System:Barrier.Dispose", "System:BlockingCollection.Dispose", "System:ClientWebSocket.Dispose", "System:Component.Dispose", "System:Container.Dispose", "System:Enumerator.Dispose", "System:Enumerator.Dispose", "System:Enumerator.Dispose", "System:Enumerator.Dispose", "System:Enumerator.Dispose", "System:Enumerator.Dispose", "System:Enumerator.Dispose", "System:EventHandlerList.Dispose", "System:License.Dispose", "System:LinkedResourceCollection.Dispose", "System:MailMessage.Dispose", "System:MarshalByValueComponent.Dispose", "System:ServiceContainer.Dispose", "System:SmtpClient.Dispose", "System:Socket.Dispose", "System:SocketAsyncEventArgs.Dispose", "System:TcpClient.Dispose", "System:TraceListener.Dispose", "System:UdpClient.Dispose", "System:WebResponse.Dispose", "System:X509Chain.Dispose", "System:X509Store.Dispose"})
Await TestAsync(workspace, host)
End Function

<Theory, CombinatorialData, Trait(Traits.Feature, Traits.Features.GoToImplementation)>
Expand Down
11 changes: 0 additions & 11 deletions src/Features/Core/Portable/FindUsages/DefinitionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

using System;
using System.Collections.Immutable;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.FindSymbols.Finders;
using Microsoft.CodeAnalysis.MetadataAsSource;
using Microsoft.CodeAnalysis.Tags;
using Roslyn.Utilities;

Expand Down Expand Up @@ -257,14 +254,6 @@ internal static DefinitionItem CreateMetadataDefinition(
.Add(MetadataSymbolOriginatingProjectIdGuid, projectId.Id.ToString())
.Add(MetadataSymbolOriginatingProjectIdDebugName, projectId.DebugName ?? "");

// Find the highest level containing type to show as the "file name". For metadata locations
// that come from embedded source or SourceLink this could be wrong, as there is no reason
// to assume a type is defined in a filename that matches, but its _way_ too expensive
// to try to find the right answer. For metadata-as-source locations though, it will be the same
// as the synthesized filename, so will make sense in the majority of cases.
var containingTypeName = MetadataAsSourceHelpers.GetTopLevelContainingNamedType(symbol).Name;
properties = properties.Add(AbstractReferenceFinder.ContainingTypeInfoPropertyName, containingTypeName);

var originationParts = GetOriginationParts(symbol);
return new DefaultDefinitionItem(
tags, displayParts, nameDisplayParts, originationParts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,28 +125,6 @@ class {|implementation:C|} : A { }";
AssertLocationsEqual(testLspServer.GetLocations("implementation"), results);
}

[Fact]
public async Task TestFindImplementationAsync_NoMetadataResults()
{
var markup = @"
using System;
class C : IDisposable
{
public void {|implementation:Dispose|}()
{
IDisposable d;
d.{|caret:|}Dispose();
}
}";
using var testLspServer = await CreateTestLspServerAsync(markup);

var results = await RunFindImplementationAsync(testLspServer, testLspServer.GetLocations("caret").Single());

// At the moment we only support source results here, so verify we haven't accidentally
// broken that without work to make sure they display nicely
AssertLocationsEqual(testLspServer.GetLocations("implementation"), results);
}

private static async Task<LSP.Location[]> RunFindImplementationAsync(TestLspServer testLspServer, LSP.Location caret)
{
return await testLspServer.ExecuteRequestAsync<LSP.TextDocumentPositionParams, LSP.Location[]>(LSP.Methods.TextDocumentImplementationName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Windows.Documents;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.FindSymbols.Finders;
using Microsoft.VisualStudio.Shell.TableManager;

namespace Microsoft.VisualStudio.LanguageServices.FindUsages
Expand All @@ -28,14 +27,8 @@ public MetadataDefinitionItemEntry(
{
switch (keyName)
{
case StandardTableKeyNames.ProjectName:
return DefinitionBucket.DefinitionItem.OriginationParts.JoinText();
case StandardTableKeyNames.DocumentName:
return DefinitionBucket.DefinitionItem.Properties[AbstractReferenceFinder.ContainingTypeInfoPropertyName];
case StandardTableKeyNames.Text:
return DefinitionBucket.DefinitionItem.DisplayParts.JoinText();
case StandardTableKeyNames.ItemOrigin:
return ItemOrigin.ExactMetadata;
}

return null;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit f087088

Please sign in to comment.