From 4904378f79e800939ff0698a4d81d02134f5aea4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Aug 2021 08:21:33 -0700 Subject: [PATCH 01/42] In progress --- .../FindBaseSymbolsCommandHandler.cs | 4 +- .../FindDerivedSymbolsCommandHandler.cs | 7 +-- .../FindExtensionMethodsCommandHandler.cs | 2 +- .../FindImplementingMembersCommandHandler.cs | 2 +- .../FindMemberOverloadsCommandHandler.cs | 5 +- .../AbstractGoToCommandHandler.cs | 2 +- .../VSTypeScriptFindUsagesService.cs | 12 +++-- ...UsagesService.DefinitionTrackingContext.cs | 8 +-- ...stractFindUsagesService.ProgressAdapter.cs | 12 +++-- ...ctFindUsagesService_FindImplementations.cs | 2 +- ...bstractFindUsagesService_FindReferences.cs | 4 +- .../Core/FindUsages/FindUsagesContext.cs | 4 +- .../FindUsages/SimpleFindUsagesContext.cs | 4 +- .../Core/GoToBase/AbstractGoToBaseService.cs | 4 +- .../AbstractGoToDefinitionService.cs | 2 +- .../GoToDefinition/GoToDefinitionHelpers.cs | 20 +------ .../Host/IStreamingFindReferencesPresenter.cs | 5 +- ...tionItem.DocumentLocationDefinitionItem.cs | 19 ++++--- .../Portable/FindUsages/DefinitionItem.cs | 4 +- .../Portable/FindUsages/IFindUsagesContext.cs | 4 +- .../FindUsages/IRemoteFindUsagesService.cs | 8 +-- .../FindUsages/SourceReferenceItem.cs | 4 +- .../CustomProtocol/FindUsagesLSPContext.cs | 12 +++-- .../References/FindImplementationsHandler.cs | 6 ++- ...bstractTableDataSourceFindUsagesContext.cs | 28 ++++++---- .../WithReferencesFindUsagesContext.cs | 53 ++++++++++++------- .../WithoutReferencesFindUsagesContext.cs | 13 +++-- .../Entries/DocumentSpanEntry.cs | 10 ++-- .../FindReferences/RoslynDefinitionBucket.cs | 4 +- .../IStreamingFindReferencesProgress.cs | 2 +- .../FindUsages/RemoteFindUsagesService.cs | 4 +- 31 files changed, 148 insertions(+), 122 deletions(-) diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs index 5e2185b61c07a..117f0df95255b 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs @@ -75,7 +75,7 @@ private async Task StreamingFindBaseSymbolsAsync( var relevantSymbol = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, cancellationToken).ConfigureAwait(false); var overriddenSymbol = relevantSymbol?.symbol.GetOverriddenMember(); - + var solution = document.Project.Solution; while (overriddenSymbol != null) { if (cancellationToken.IsCancellationRequested) @@ -84,7 +84,7 @@ private async Task StreamingFindBaseSymbolsAsync( } var definitionItem = overriddenSymbol.ToNonClassifiedDefinitionItem(document.Project.Solution, true); - await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); // try getting the next one overriddenSymbol = overriddenSymbol.GetOverriddenMember(); diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs index 6577d0200543a..3cf1359365123 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs @@ -100,13 +100,14 @@ private async Task FindDerivedSymbolsAsync( if (candidateSymbolProjectPair?.symbol == null) return; - var candidates = await GatherSymbolsAsync(candidateSymbolProjectPair.Value.symbol, - document.Project.Solution, cancellationToken).ConfigureAwait(false); + var solution = document.Project.Solution; + var candidates = await GatherSymbolsAsync( + candidateSymbolProjectPair.Value.symbol, solution, cancellationToken).ConfigureAwait(false); foreach (var candidate in candidates) { var definitionItem = candidate.ToNonClassifiedDefinitionItem(document.Project.Solution, true); - await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs index da6bc3658027a..5ea7bbd1830f4 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs @@ -116,7 +116,7 @@ private async Task FindExtensionMethodsAsync( var definitionItem = reducedMethod.ToNonClassifiedDefinitionItem(solution, true); - await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs index 7e8998cfff489..6c3ee273ca489 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs @@ -144,7 +144,7 @@ private static async Task InspectInterfaceAsync( continue; var definitionItem = impl.ToNonClassifiedDefinitionItem(project.Solution, true); - await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(project.Solution, definitionItem, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs index 9f28f81723d43..13c489a94204d 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs @@ -81,11 +81,12 @@ private async Task FindMemberOverloadsAsync( if (symbol == null || symbol.ContainingType == null) return; + var solution = document.Project.Solution; foreach (var curSymbol in symbol.ContainingType.GetMembers() .Where(m => m.Kind == symbol.Kind && m.Name == symbol.Name)) { - var definitionItem = curSymbol.ToNonClassifiedDefinitionItem(document.Project.Solution, true); - await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + var definitionItem = curSymbol.ToNonClassifiedDefinitionItem(solution, includeHiddenLocations: true); + await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); } } finally diff --git a/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs b/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs index 4ad732394b8dc..85ecef8ad836c 100644 --- a/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs +++ b/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs @@ -126,7 +126,7 @@ private void ExecuteCommand( return context.Message; await _streamingPresenter.TryNavigateToOrPresentItemsAsync( - _threadingContext, document.Project.Solution.Workspace, context.SearchTitle, context.GetDefinitions(), cancellationToken).ConfigureAwait(false); + _threadingContext, document.Project.Solution, context.SearchTitle, context.GetDefinitions(), cancellationToken).ConfigureAwait(false); return null; } } diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs index caa32af454098..5dfb35f773993 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs @@ -28,18 +28,20 @@ public VSTypeScriptFindUsagesService(IVSTypeScriptFindUsagesService underlyingSe } public Task FindReferencesAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _underlyingService.FindReferencesAsync(document, position, new VSTypeScriptFindUsagesContext(context), cancellationToken); + => _underlyingService.FindReferencesAsync(document, position, new VSTypeScriptFindUsagesContext(document.Project.Solution, context), cancellationToken); public Task FindImplementationsAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _underlyingService.FindImplementationsAsync(document, position, new VSTypeScriptFindUsagesContext(context), cancellationToken); + => _underlyingService.FindImplementationsAsync(document, position, new VSTypeScriptFindUsagesContext(document.Project.Solution, context), cancellationToken); private class VSTypeScriptFindUsagesContext : IVSTypeScriptFindUsagesContext { + private readonly Solution _solution; private readonly IFindUsagesContext _context; private readonly Dictionary _definitionItemMap = new(); - public VSTypeScriptFindUsagesContext(IFindUsagesContext context) + public VSTypeScriptFindUsagesContext(Solution solution, IFindUsagesContext context) { + _solution = solution; _context = context; } @@ -75,13 +77,13 @@ private DefinitionItem GetOrCreateDefinitionItem(VSTypeScriptDefinitionItem item public ValueTask OnDefinitionFoundAsync(VSTypeScriptDefinitionItem definition, CancellationToken cancellationToken) { var item = GetOrCreateDefinitionItem(definition); - return _context.OnDefinitionFoundAsync(item, cancellationToken); + return _context.OnDefinitionFoundAsync(_solution, item, cancellationToken); } public ValueTask OnReferenceFoundAsync(VSTypeScriptSourceReferenceItem reference, CancellationToken cancellationToken) { var item = GetOrCreateDefinitionItem(reference.Definition); - return _context.OnReferenceFoundAsync(new SourceReferenceItem(item, reference.SourceSpan, reference.SymbolUsageInfo), cancellationToken); + return _context.OnReferenceFoundAsync(_solution, new SourceReferenceItem(item, reference.SourceSpan, reference.SymbolUsageInfo), cancellationToken); } } diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs index dcb5d746d113d..8f542a09ab505 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs @@ -39,17 +39,17 @@ public ValueTask ReportMessageAsync(string message, CancellationToken cancellati public ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) => _underlyingContext.SetSearchTitleAsync(title, cancellationToken); - public ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) - => _underlyingContext.OnReferenceFoundAsync(reference, cancellationToken); + public ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) + => _underlyingContext.OnReferenceFoundAsync(solution, reference, cancellationToken); - public ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) + public ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) { lock (_gate) { _definitions.Add(definition); } - return _underlyingContext.OnDefinitionFoundAsync(definition, cancellationToken); + return _underlyingContext.OnDefinitionFoundAsync(solution, definition, cancellationToken); } public ImmutableArray GetDefinitions() diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs index 886564d876238..64bbf2defe753 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs @@ -42,8 +42,10 @@ public async ValueTask OnReferenceFoundAsync(Document document, TextSpan span, C { var documentSpan = await ClassifiedSpansAndHighlightSpanFactory.GetClassifiedDocumentSpanAsync( document, span, cancellationToken).ConfigureAwait(false); - await _context.OnReferenceFoundAsync(new SourceReferenceItem( - _definition, documentSpan, SymbolUsageInfo.None), cancellationToken).ConfigureAwait(false); + await _context.OnReferenceFoundAsync( + document.Project.Solution, + new SourceReferenceItem(_definition, documentSpan, SymbolUsageInfo.None), + cancellationToken).ConfigureAwait(false); } } @@ -84,7 +86,7 @@ public FindReferencesProgressAdapter( // Do nothing functions. The streaming far service doesn't care about // any of these. public ValueTask OnStartedAsync(CancellationToken cancellationToken) => default; - public ValueTask OnCompletedAsync(CancellationToken cancellationToken) => default; + public ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) => default; public ValueTask OnFindInDocumentStartedAsync(Document document, CancellationToken cancellationToken) => default; public ValueTask OnFindInDocumentCompletedAsync(Document document, CancellationToken cancellationToken) => default; @@ -115,7 +117,7 @@ private async ValueTask GetDefinitionItemAsync(SymbolGroup group public async ValueTask OnDefinitionFoundAsync(SymbolGroup group, CancellationToken cancellationToken) { var definitionItem = await GetDefinitionItemAsync(group, cancellationToken).ConfigureAwait(false); - await _context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + await _context.OnDefinitionFoundAsync(_solution, definitionItem, cancellationToken).ConfigureAwait(false); } public async ValueTask OnReferenceFoundAsync(SymbolGroup group, ISymbol definition, ReferenceLocation location, CancellationToken cancellationToken) @@ -126,7 +128,7 @@ public async ValueTask OnReferenceFoundAsync(SymbolGroup group, ISymbol definiti cancellationToken).ConfigureAwait(false); if (referenceItem != null) - await _context.OnReferenceFoundAsync(referenceItem, cancellationToken).ConfigureAwait(false); + await _context.OnReferenceFoundAsync(_solution, referenceItem, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindImplementations.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindImplementations.cs index 59e7fcf5ca57f..2e7ef087b12b9 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindImplementations.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindImplementations.cs @@ -86,7 +86,7 @@ await context.SetSearchTitleAsync( var definitionItem = await implementation.ToClassifiedDefinitionItemAsync( solution, isPrimary: true, includeHiddenLocations: false, FindReferencesSearchOptions.Default, cancellationToken).ConfigureAwait(false); - await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(project.Solution, definitionItem, cancellationToken).ConfigureAwait(false); } } diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs index a30d57c0f41f6..2354905c34231 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs @@ -42,7 +42,7 @@ await FindLiteralOrSymbolReferencesAsync( foreach (var definition in thirdPartyDefinitions) { // Don't need ConfigureAwait(true) here - await context.OnDefinitionFoundAsync(definition, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(document.Project.Solution, definition, cancellationToken).ConfigureAwait(false); } } @@ -225,7 +225,7 @@ private static async Task TryFindLiteralReferencesAsync( ImmutableArray.Create(TextTags.StringLiteral), ImmutableArray.Create(new TaggedText(TextTags.Text, searchTitle))); - await context.OnDefinitionFoundAsync(definition, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(document.Project.Solution, definition, cancellationToken).ConfigureAwait(false); var progressAdapter = new FindLiteralsProgressAdapter(context, definition); diff --git a/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs b/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs index a733a3d746aae..7328ed3f0721e 100644 --- a/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs +++ b/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs @@ -21,9 +21,9 @@ protected FindUsagesContext() public virtual ValueTask OnCompletedAsync(CancellationToken cancellationToken) => default; - public virtual ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) => default; + public virtual ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) => default; - public virtual ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) => default; + public virtual ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) => default; protected virtual ValueTask ReportProgressAsync(int current, int maximum, CancellationToken cancellationToken) => default; } diff --git a/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs b/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs index 6adc1175310ee..70708b1b8768b 100644 --- a/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs +++ b/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs @@ -60,7 +60,7 @@ public ImmutableArray GetReferences() } } - public override ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) + public override ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) { lock (_gate) { @@ -70,7 +70,7 @@ public override ValueTask OnDefinitionFoundAsync(DefinitionItem definition, Canc return default; } - public override ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) + public override ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) { lock (_gate) { diff --git a/src/EditorFeatures/Core/GoToBase/AbstractGoToBaseService.cs b/src/EditorFeatures/Core/GoToBase/AbstractGoToBaseService.cs index 060fd12c467c9..4cb8db56f2430 100644 --- a/src/EditorFeatures/Core/GoToBase/AbstractGoToBaseService.cs +++ b/src/EditorFeatures/Core/GoToBase/AbstractGoToBaseService.cs @@ -51,14 +51,14 @@ await context.SetSearchTitleAsync( var definitionItem = await sourceDefinition.ToClassifiedDefinitionItemAsync( solution, isPrimary: true, includeHiddenLocations: false, FindReferencesSearchOptions.Default, cancellationToken: cancellationToken).ConfigureAwait(false); - await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); found = true; } else if (baseSymbol.Locations.Any(l => l.IsInMetadata)) { var definitionItem = baseSymbol.ToNonClassifiedDefinitionItem( solution, includeHiddenLocations: true); - await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); found = true; } } diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs index 16553705d15fc..a5e4aaf90146f 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs @@ -121,7 +121,7 @@ private bool TryGoToAlternativeLocationIfAlreadyOnDefinition( return _threadingContext.JoinableTaskFactory.Run(() => _streamingPresenter.TryNavigateToOrPresentItemsAsync( - _threadingContext, solution.Workspace, title, definitions, cancellationToken)); + _threadingContext, solution, title, definitions, cancellationToken)); } private static bool IsThirdPartyNavigationAllowed(ISymbol symbolToNavigateTo, int caretPosition, Document document, CancellationToken cancellationToken) diff --git a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs index b8e4cbd407538..903949b9a59f8 100644 --- a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs +++ b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs @@ -111,7 +111,7 @@ public static bool TryGoToDefinition( return threadingContext.JoinableTaskFactory.Run( () => streamingPresenter.TryNavigateToOrPresentItemsAsync( - threadingContext, solution.Workspace, title, definitions, cancellationToken)); + threadingContext, solution, title, definitions, cancellationToken)); } public static bool TryGoToDefinition( @@ -127,23 +127,7 @@ public static bool TryGoToDefinition( return threadingContext.JoinableTaskFactory.Run(() => streamingPresenter.TryNavigateToOrPresentItemsAsync( - threadingContext, solution.Workspace, title, definitions, cancellationToken)); - } - - public static bool TryGoToDefinition( - ImmutableArray definitions, - Workspace workspace, - string title, - IThreadingContext threadingContext, - IStreamingFindUsagesPresenter streamingPresenter, - CancellationToken cancellationToken) - { - if (definitions.IsDefaultOrEmpty) - return false; - - return threadingContext.JoinableTaskFactory.Run(() => - streamingPresenter.TryNavigateToOrPresentItemsAsync( - threadingContext, workspace, title, definitions, cancellationToken)); + threadingContext, solution, title, definitions, cancellationToken)); } } } diff --git a/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs b/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs index a7d4ff2b18eff..c1123f6a26932 100644 --- a/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs +++ b/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs @@ -60,7 +60,7 @@ internal static class IStreamingFindUsagesPresenterExtensions public static async Task TryNavigateToOrPresentItemsAsync( this IStreamingFindUsagesPresenter presenter, IThreadingContext threadingContext, - Workspace workspace, + Solution solution, string title, ImmutableArray items, CancellationToken cancellationToken) @@ -68,6 +68,7 @@ public static async Task TryNavigateToOrPresentItemsAsync( // Can only navigate or present items on UI thread. await threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + var workspace = solution.Workspace; // Ignore any definitions that we can't navigate to. var definitions = items.WhereAsArray(d => d.CanNavigateTo(workspace, cancellationToken)); @@ -111,7 +112,7 @@ public static async Task TryNavigateToOrPresentItemsAsync( try { foreach (var definition in nonExternalItems) - await context.OnDefinitionFoundAsync(definition, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(solution, definition, cancellationToken).ConfigureAwait(false); } finally { diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs index 07276c513d2f8..1868c9086dfa9 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs @@ -37,34 +37,33 @@ public DefaultDefinitionItem( { } + private DocumentSpan? TryGetDocumentSpan(Workspace workspace) + { + var currentSolution = workspace.CurrentSolution; + var document = currentSolution.GetDocument(SourceSpans[0].DocumentId); + return document != null ? new DocumentSpan(document, SourceSpans[0].SourceSpan) : null; + } + public override bool CanNavigateTo(Workspace workspace, CancellationToken cancellationToken) { if (Properties.ContainsKey(NonNavigable)) - { return false; - } if (Properties.TryGetValue(MetadataSymbolKey, out var symbolKey)) - { return CanNavigateToMetadataSymbol(workspace, symbolKey); - } - return SourceSpans[0].CanNavigateTo(cancellationToken); + return TryGetDocumentSpan(workspace) is DocumentSpan span && span.CanNavigateTo(cancellationToken); } public override bool TryNavigateTo(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) { if (Properties.ContainsKey(NonNavigable)) - { return false; - } if (Properties.TryGetValue(MetadataSymbolKey, out var symbolKey)) - { return TryNavigateToMetadataSymbol(workspace, symbolKey); - } - return SourceSpans[0].TryNavigateTo(showInPreviewTab, activateTab, cancellationToken); + return TryGetDocumentSpan(workspace) is DocumentSpan span && span.TryNavigateTo(showInPreviewTab, activateTab, cancellationToken); } private bool CanNavigateToMetadataSymbol(Workspace workspace, string symbolKey) diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.cs index c12672789b0ea..35100b96a54f4 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.cs @@ -93,7 +93,7 @@ internal abstract partial class DefinitionItem /// Additional locations to present in the UI. A definition may have multiple locations /// for cases like partial types/members. /// - public ImmutableArray SourceSpans { get; } + public ImmutableArray SourceSpans { get; } /// /// Whether or not this definition should be presented if we never found any references to @@ -144,7 +144,7 @@ protected DefinitionItem( DisplayParts = displayParts; NameDisplayParts = nameDisplayParts.IsDefaultOrEmpty ? displayParts : nameDisplayParts; OriginationParts = originationParts.NullToEmpty(); - SourceSpans = sourceSpans.NullToEmpty(); + SourceSpans = sourceSpans.NullToEmpty().SelectAsArray(ss => SerializableDocumentSpan.Dehydrate(ss)); Properties = properties ?? ImmutableDictionary.Empty; DisplayableProperties = displayableProperties ?? ImmutableDictionary.Empty; DisplayIfNoReferences = displayIfNoReferences; diff --git a/src/Features/Core/Portable/FindUsages/IFindUsagesContext.cs b/src/Features/Core/Portable/FindUsages/IFindUsagesContext.cs index aa818a48152e9..40621c114592e 100644 --- a/src/Features/Core/Portable/FindUsages/IFindUsagesContext.cs +++ b/src/Features/Core/Portable/FindUsages/IFindUsagesContext.cs @@ -27,7 +27,7 @@ internal interface IFindUsagesContext /// ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken); - ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken); - ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken); + ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken); + ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken); } } diff --git a/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs b/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs index b0c65fdc25221..9ac4c51c74698 100644 --- a/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs +++ b/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs @@ -108,14 +108,14 @@ public async ValueTask OnDefinitionFoundAsync(SerializableDefinitionItem definit _idToDefinition.Add(id, rehydrated); } - await _context.OnDefinitionFoundAsync(rehydrated, cancellationToken).ConfigureAwait(false); + await _context.OnDefinitionFoundAsync(_solution, rehydrated, cancellationToken).ConfigureAwait(false); } public async ValueTask OnReferenceFoundAsync(SerializableSourceReferenceItem reference, CancellationToken cancellationToken) { var rehydrated = await reference.RehydrateAsync(_solution, GetDefinition(reference.DefinitionId), cancellationToken).ConfigureAwait(false); - await _context.OnReferenceFoundAsync(rehydrated, cancellationToken).ConfigureAwait(false); + await _context.OnReferenceFoundAsync(_solution, rehydrated, cancellationToken).ConfigureAwait(false); } private DefinitionItem GetDefinition(int definitionId) @@ -213,7 +213,7 @@ public static SerializableDefinitionItem Dehydrate(int id, DefinitionItem item) item.DisplayParts, item.NameDisplayParts, item.OriginationParts, - item.SourceSpans.SelectAsArray(ss => SerializableDocumentSpan.Dehydrate(ss)), + item.SourceSpans, item.Properties, item.DisplayableProperties, item.DisplayIfNoReferences); @@ -263,7 +263,7 @@ public SerializableSourceReferenceItem( public static SerializableSourceReferenceItem Dehydrate(int definitionId, SourceReferenceItem item) => new(definitionId, - SerializableDocumentSpan.Dehydrate(item.SourceSpan), + item.SourceSpan, item.SymbolUsageInfo, item.AdditionalProperties); diff --git a/src/Features/Core/Portable/FindUsages/SourceReferenceItem.cs b/src/Features/Core/Portable/FindUsages/SourceReferenceItem.cs index 98404758d1e2a..80a5c963f3a20 100644 --- a/src/Features/Core/Portable/FindUsages/SourceReferenceItem.cs +++ b/src/Features/Core/Portable/FindUsages/SourceReferenceItem.cs @@ -22,7 +22,7 @@ internal sealed class SourceReferenceItem /// /// The location of the source item. /// - public DocumentSpan SourceSpan { get; } + public SerializableDocumentSpan SourceSpan { get; } /// /// If this reference is a location where the definition is written to. @@ -50,7 +50,7 @@ private SourceReferenceItem( bool isWrittenTo) { Definition = definition; - SourceSpan = sourceSpan; + SourceSpan = SerializableDocumentSpan.Dehydrate(sourceSpan); SymbolUsageInfo = symbolUsageInfo; IsWrittenTo = isWrittenTo; AdditionalProperties = additionalProperties ?? ImmutableDictionary.Empty; diff --git a/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs b/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs index a2ba9520d8249..39ae31dd17281 100644 --- a/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs +++ b/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs @@ -17,6 +17,7 @@ using Microsoft.CodeAnalysis.FindUsages; using Microsoft.CodeAnalysis.MetadataAsSource; using Microsoft.CodeAnalysis.PooledObjects; +using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.Protocol; @@ -88,7 +89,7 @@ public FindUsagesLSPContext( public override async ValueTask OnCompletedAsync(CancellationToken cancellationToken) => await _workQueue.WaitUntilCurrentBatchCompletesAsync().ConfigureAwait(false); - public override async ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) + public override async ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) { using (await _semaphore.DisposableWaitAsync(cancellationToken).ConfigureAwait(false)) { @@ -123,7 +124,7 @@ public override async ValueTask OnDefinitionFoundAsync(DefinitionItem definition } } - public override async ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) + public override async ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) { using (await _semaphore.DisposableWaitAsync(cancellationToken).ConfigureAwait(false)) { @@ -132,9 +133,11 @@ public override async ValueTask OnReferenceFoundAsync(SourceReferenceItem refere if (!_definitionToId.TryGetValue(reference.Definition, out var definitionId)) return; + var document = solution.GetRequiredDocument(reference.SourceSpan.DocumentId); + // If this is reference to the same physical location we've already reported, just // filter this out. it will clutter the UI to show the same places. - if (!_referenceLocations.Add((reference.SourceSpan.Document.FilePath, reference.SourceSpan.SourceSpan))) + if (!_referenceLocations.Add((document.FilePath, reference.SourceSpan.SourceSpan))) return; // If the definition hasn't been reported yet, add it to our list of references to report. @@ -164,7 +167,7 @@ public override async ValueTask OnReferenceFoundAsync(SourceReferenceItem refere int? definitionId, Document document, int position, - DocumentSpan documentSpan, + SerializableDocumentSpan serializableDocumentSpan, ImmutableDictionary properties, IMetadataAsSourceFileService metadataAsSourceFileService, ClassifiedTextElement? definitionText, @@ -173,6 +176,7 @@ public override async ValueTask OnReferenceFoundAsync(SourceReferenceItem refere bool isWrittenTo, CancellationToken cancellationToken) { + var documentSpan = new DocumentSpan(document.Project.Solution.GetRequiredDocument(serializableDocumentSpan.DocumentId), serializableDocumentSpan.SourceSpan); var location = await ComputeLocationAsync(document, position, documentSpan, metadataAsSourceFileService, cancellationToken).ConfigureAwait(false); // Getting the text for the Text property. If we somehow can't compute the text, that means we're probably dealing with a metadata diff --git a/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs b/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs index 628ac7e85555d..77b2db4d17c9d 100644 --- a/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs @@ -46,18 +46,20 @@ public FindImplementationsHandler() var findUsagesContext = new SimpleFindUsagesContext(); await FindImplementationsAsync(findUsagesService, document, position, findUsagesContext, cancellationToken).ConfigureAwait(false); + var solution = document.Project.Solution; foreach (var definition in findUsagesContext.GetDefinitions()) { var text = definition.GetClassifiedText(); foreach (var sourceSpan in definition.SourceSpans) { + var span = new DocumentSpan(solution.GetRequiredDocument(sourceSpan.DocumentId), sourceSpan.SourceSpan); if (context.ClientCapabilities?.HasVisualStudioLspCapability() == true) { - locations.AddIfNotNull(await ProtocolConversions.DocumentSpanToLocationWithTextAsync(sourceSpan, text, cancellationToken).ConfigureAwait(false)); + locations.AddIfNotNull(await ProtocolConversions.DocumentSpanToLocationWithTextAsync(span, text, cancellationToken).ConfigureAwait(false)); } else { - locations.AddIfNotNull(await ProtocolConversions.DocumentSpanToLocationAsync(sourceSpan, cancellationToken).ConfigureAwait(false)); + locations.AddIfNotNull(await ProtocolConversions.DocumentSpanToLocationAsync(span, cancellationToken).ConfigureAwait(false)); } } } diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs index 7a9fcfc453ff0..6a0594f173cd0 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs @@ -17,6 +17,7 @@ using Microsoft.CodeAnalysis.FindUsages; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.PooledObjects; +using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.Shell.FindAllReferences; using Microsoft.VisualStudio.Shell.TableControl; @@ -311,27 +312,30 @@ public sealed override async ValueTask OnCompletedAsync(CancellationToken cancel protected abstract Task OnCompletedAsyncWorkerAsync(CancellationToken cancellationToken); - public sealed override ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) + public sealed override ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) { lock (Gate) { Definitions.Add(definition); } - return OnDefinitionFoundWorkerAsync(definition, cancellationToken); + return OnDefinitionFoundWorkerAsync(solution, definition, cancellationToken); } - protected abstract ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem definition, CancellationToken cancellationToken); + protected abstract ValueTask OnDefinitionFoundWorkerAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken); protected async Task TryCreateDocumentSpanEntryAsync( + Solution solution, RoslynDefinitionBucket definitionBucket, - DocumentSpan documentSpan, + SerializableDocumentSpan serializableDocumentSpan, HighlightSpanKind spanKind, SymbolUsageInfo symbolUsageInfo, ImmutableDictionary additionalProperties, CancellationToken cancellationToken) { - var sourceText = await documentSpan.Document.GetTextAsync(cancellationToken).ConfigureAwait(false); + var document = solution.GetRequiredDocument(serializableDocumentSpan.DocumentId); + var documentSpan = new DocumentSpan(document, serializableDocumentSpan.SourceSpan); + var sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); var (excerptResult, lineText) = await ExcerptAsync(sourceText, documentSpan, cancellationToken).ConfigureAwait(false); var mappedDocumentSpan = await AbstractDocumentSpanEntry.TryMapAndGetFirstAsync(documentSpan, sourceText, cancellationToken).ConfigureAwait(false); @@ -341,10 +345,16 @@ public sealed override ValueTask OnDefinitionFoundAsync(DefinitionItem definitio return null; } + var (guid, projectName, projectFlavor) = GetGuidAndProjectInfo(document); + return DocumentSpanEntry.TryCreate( this, definitionBucket, - documentSpan, + guid, + projectName, + projectFlavor, + document.FilePath, + documentSpan.SourceSpan, spanKind, mappedDocumentSpan.Value, excerptResult, @@ -379,10 +389,10 @@ public sealed override ValueTask OnDefinitionFoundAsync(DefinitionItem definitio return (excerptResult, AbstractDocumentSpanEntry.GetLineContainingPosition(sourceText, documentSpan.SourceSpan.Start)); } - public sealed override ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) - => OnReferenceFoundWorkerAsync(reference, cancellationToken); + public sealed override ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) + => OnReferenceFoundWorkerAsync(solution, reference, cancellationToken); - protected abstract ValueTask OnReferenceFoundWorkerAsync(SourceReferenceItem reference, CancellationToken cancellationToken); + protected abstract ValueTask OnReferenceFoundWorkerAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken); protected RoslynDefinitionBucket GetOrCreateDefinitionBucket(DefinitionItem definition, bool expandedByDefault) { diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs index d4b3be1456835..c89af14a7c953 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs @@ -38,16 +38,16 @@ public WithReferencesFindUsagesContext( { } - protected override async ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem definition, CancellationToken cancellationToken) + protected override async ValueTask OnDefinitionFoundWorkerAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) { // If this is a definition we always want to show, then create entries for all the declaration locations // immediately. Otherwise, we'll create them on demand when we hear about references for this // definition. if (definition.DisplayIfNoReferences) - await AddDeclarationEntriesAsync(definition, expandedByDefault: true, cancellationToken).ConfigureAwait(false); + await AddDeclarationEntriesAsync(solution, definition, expandedByDefault: true, cancellationToken).ConfigureAwait(false); } - private async Task AddDeclarationEntriesAsync(DefinitionItem definition, bool expandedByDefault, CancellationToken cancellationToken) + private async Task AddDeclarationEntriesAsync(Solution solution, DefinitionItem definition, bool expandedByDefault, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -70,8 +70,13 @@ private async Task AddDeclarationEntriesAsync(DefinitionItem definition, bool ex foreach (var declarationLocation in definition.SourceSpans) { var definitionEntry = await TryCreateDocumentSpanEntryAsync( - definitionBucket, declarationLocation, HighlightSpanKind.Definition, SymbolUsageInfo.None, - additionalProperties: definition.DisplayableProperties, cancellationToken).ConfigureAwait(false); + solution, + definitionBucket, + declarationLocation, + HighlightSpanKind.Definition, + SymbolUsageInfo.None, + definition.DisplayableProperties, + cancellationToken).ConfigureAwait(false); declarations.AddIfNotNull(definitionEntry); } @@ -105,14 +110,17 @@ private bool HasDeclarationEntries(DefinitionItem definition) } } - protected override ValueTask OnReferenceFoundWorkerAsync(SourceReferenceItem reference, CancellationToken cancellationToken) + protected override ValueTask OnReferenceFoundWorkerAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) { // Normal references go into both sets of entries. We ensure an entry for the definition, and an entry // for the reference itself. return OnEntryFoundAsync( + solution, reference.Definition, bucket => TryCreateDocumentSpanEntryAsync( - bucket, reference.SourceSpan, + solution, + bucket, + reference.SourceSpan, reference.IsWrittenTo ? HighlightSpanKind.WrittenReference : HighlightSpanKind.Reference, reference.SymbolUsageInfo, reference.AdditionalProperties, @@ -124,6 +132,7 @@ protected override ValueTask OnReferenceFoundWorkerAsync(SourceReferenceItem ref } private async ValueTask OnEntryFoundAsync( + Solution solution, DefinitionItem definition, Func> createEntryAsync, bool addToEntriesWhenGroupingByDefinition, @@ -138,7 +147,7 @@ private async ValueTask OnEntryFoundAsync( // that we haven't created any declaration entries for (i.e. because it had DisplayIfNoReferences = // false). Because we've now found a reference, we want to make sure all its declaration entries are // added. - await AddDeclarationEntriesAsync(definition, expandedByDefault, cancellationToken).ConfigureAwait(false); + await AddDeclarationEntriesAsync(solution, definition, expandedByDefault, cancellationToken).ConfigureAwait(false); // First find the bucket corresponding to our definition. var definitionBucket = GetOrCreateDefinitionBucket(definition, expandedByDefault); @@ -166,22 +175,22 @@ private async ValueTask OnEntryFoundAsync( NotifyChange(); } - protected override async Task OnCompletedAsyncWorkerAsync(CancellationToken cancellationToken) + protected override async Task OnCompletedAsyncWorkerAsync(Solution solution, CancellationToken cancellationToken) { // Now that we know the search is over, create and display any error messages // for definitions that were not found. - await CreateMissingReferenceEntriesIfNecessaryAsync(cancellationToken).ConfigureAwait(false); - await CreateNoResultsFoundEntryIfNecessaryAsync(cancellationToken).ConfigureAwait(false); + await CreateMissingReferenceEntriesIfNecessaryAsync(solution, cancellationToken).ConfigureAwait(false); + await CreateNoResultsFoundEntryIfNecessaryAsync(solution, cancellationToken).ConfigureAwait(false); } - private async Task CreateMissingReferenceEntriesIfNecessaryAsync(CancellationToken cancellationToken) + private async Task CreateMissingReferenceEntriesIfNecessaryAsync(Solution solution, CancellationToken cancellationToken) { - await CreateMissingReferenceEntriesIfNecessaryAsync(whenGroupingByDefinition: true, cancellationToken).ConfigureAwait(false); - await CreateMissingReferenceEntriesIfNecessaryAsync(whenGroupingByDefinition: false, cancellationToken).ConfigureAwait(false); + await CreateMissingReferenceEntriesIfNecessaryAsync(solution, whenGroupingByDefinition: true, cancellationToken).ConfigureAwait(false); + await CreateMissingReferenceEntriesIfNecessaryAsync(solution, whenGroupingByDefinition: false, cancellationToken).ConfigureAwait(false); } private async Task CreateMissingReferenceEntriesIfNecessaryAsync( - bool whenGroupingByDefinition, CancellationToken cancellationToken) + Solution solution, bool whenGroupingByDefinition, CancellationToken cancellationToken) { // Go through and add dummy entries for any definitions that // that we didn't find any references for. @@ -191,7 +200,9 @@ private async Task CreateMissingReferenceEntriesIfNecessaryAsync( { if (definition.IsExternal) { - await OnEntryFoundAsync(definition, + await OnEntryFoundAsync( + solution, + definition, bucket => SimpleMessageEntry.CreateAsync(bucket, bucket, ServicesVSResources.External_reference_found)!, addToEntriesWhenGroupingByDefinition: whenGroupingByDefinition, addToEntriesWhenNotGroupingByDefinition: !whenGroupingByDefinition, @@ -204,7 +215,9 @@ await OnEntryFoundAsync(definition, // // We'll place this under a single bucket called "Symbols without references" and we'll allow // the user to navigate on that text entry to that definition if possible. - await OnEntryFoundAsync(SymbolsWithoutReferencesDefinitionItem, + await OnEntryFoundAsync( + solution, + SymbolsWithoutReferencesDefinitionItem, bucket => SimpleMessageEntry.CreateAsync( definitionBucket: bucket, navigationBucket: RoslynDefinitionBucket.Create(Presenter, this, definition, expandedByDefault: false), @@ -255,7 +268,7 @@ private ImmutableArray GetDefinitionsToCreateMissingReferenceIte } } - private async Task CreateNoResultsFoundEntryIfNecessaryAsync(CancellationToken cancellationToken) + private async Task CreateNoResultsFoundEntryIfNecessaryAsync(Solution solution, CancellationToken cancellationToken) { bool noDefinitions; lock (Gate) @@ -266,7 +279,9 @@ private async Task CreateNoResultsFoundEntryIfNecessaryAsync(CancellationToken c if (noDefinitions) { // Create a fake definition/reference called "search found no results" - await OnEntryFoundAsync(NoResultsDefinitionItem, + await OnEntryFoundAsync( + solution, + NoResultsDefinitionItem, bucket => SimpleMessageEntry.CreateAsync(bucket, null, ServicesVSResources.Search_found_no_results)!, addToEntriesWhenGroupingByDefinition: true, addToEntriesWhenNotGroupingByDefinition: true, diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs index af994b360b8a7..d6f176115ac94 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs @@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.DocumentHighlighting; using Microsoft.CodeAnalysis.FindUsages; using Microsoft.CodeAnalysis.PooledObjects; +using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.VisualStudio.Shell.FindAllReferences; using Microsoft.VisualStudio.Shell.TableControl; @@ -35,14 +36,14 @@ public WithoutReferencesFindUsagesContext( } // We should never be called in a context where we get references. - protected override ValueTask OnReferenceFoundWorkerAsync(SourceReferenceItem reference, CancellationToken cancellationToken) + protected override ValueTask OnReferenceFoundWorkerAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) => throw new InvalidOperationException(); // Nothing to do on completion. protected override Task OnCompletedAsyncWorkerAsync(CancellationToken cancellationToken) => Task.CompletedTask; - protected override async ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem definition, CancellationToken cancellationToken) + protected override async ValueTask OnDefinitionFoundWorkerAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) { var definitionBucket = GetOrCreateDefinitionBucket(definition, expandedByDefault: true); @@ -54,7 +55,7 @@ protected override async ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem d // definition as what to show. That way we show enough information for things // methods. i.e. we'll show "void TypeName.MethodName(args...)" allowing // the user to see the type the method was created in. - var entry = await TryCreateEntryAsync(definitionBucket, definition, cancellationToken).ConfigureAwait(false); + var entry = await TryCreateEntryAsync(solution, definitionBucket, definition, cancellationToken).ConfigureAwait(false); entries.AddIfNotNull(entry); } else if (definition.SourceSpans.Length == 0) @@ -72,6 +73,7 @@ protected override async ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem d foreach (var sourceSpan in definition.SourceSpans) { var entry = await TryCreateDocumentSpanEntryAsync( + solution, definitionBucket, sourceSpan, HighlightSpanKind.Definition, @@ -95,9 +97,10 @@ protected override async ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem d } private async Task TryCreateEntryAsync( - RoslynDefinitionBucket definitionBucket, DefinitionItem definition, CancellationToken cancellationToken) + Solution solution, RoslynDefinitionBucket definitionBucket, DefinitionItem definition, CancellationToken cancellationToken) { - var documentSpan = definition.SourceSpans[0]; + var document = solution.GetRequiredDocument(definition.SourceSpans[0].DocumentId); + var documentSpan = new DocumentSpan(document, definition.SourceSpans[0].SourceSpan); var (guid, projectName, _) = GetGuidAndProjectInfo(documentSpan.Document); var sourceText = await documentSpan.Document.GetTextAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/DocumentSpanEntry.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/DocumentSpanEntry.cs index 71a1bf7ab6966..673d2782af7d0 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/DocumentSpanEntry.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/DocumentSpanEntry.cs @@ -105,7 +105,11 @@ private void AddFlavor(string? projectFlavor) public static DocumentSpanEntry? TryCreate( AbstractTableDataSourceFindUsagesContext context, RoslynDefinitionBucket definitionBucket, - DocumentSpan documentSpan, + Guid guid, + string projectName, + string? projectFlavor, + string? filePath, + TextSpan sourceSpan, HighlightSpanKind spanKind, MappedSpanResult mappedSpanResult, ExcerptResult excerptResult, @@ -113,8 +117,6 @@ private void AddFlavor(string? projectFlavor) SymbolUsageInfo symbolUsageInfo, ImmutableDictionary customColumnsData) { - var document = documentSpan.Document; - var (guid, projectName, projectFlavor) = GetGuidAndProjectInfo(document); var entry = new DocumentSpanEntry( context, definitionBucket, projectName, projectFlavor, guid, @@ -126,7 +128,7 @@ private void AddFlavor(string? projectFlavor) // for the user. i.e. they're the same file/span. Showing multiple entries for these // is just noisy and gets worse and worse with shared projects and whatnot. So, we // collapse things down to only show a single entry for each unique file/span pair. - var winningEntry = definitionBucket.GetOrAddEntry(documentSpan, entry); + var winningEntry = definitionBucket.GetOrAddEntry(filePath, sourceSpan, entry); // If we were the one that successfully added this entry to the bucket, then pass us // back out to be put in the ui. diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/RoslynDefinitionBucket.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/RoslynDefinitionBucket.cs index f0f66726823b5..94dc7c0350978 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/RoslynDefinitionBucket.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/RoslynDefinitionBucket.cs @@ -114,9 +114,9 @@ public override bool TryCreateStringContent(out string? content) return null; } - public DocumentSpanEntry GetOrAddEntry(DocumentSpan documentSpan, DocumentSpanEntry entry) + public DocumentSpanEntry GetOrAddEntry(string? filePath, TextSpan sourceSpan, DocumentSpanEntry entry) { - var key = (documentSpan.Document.FilePath, documentSpan.SourceSpan); + var key = (filePath, sourceSpan); lock (_locationToEntry) { return _locationToEntry.GetOrAdd(key, entry); diff --git a/src/Workspaces/Core/Portable/FindSymbols/IStreamingFindReferencesProgress.cs b/src/Workspaces/Core/Portable/FindSymbols/IStreamingFindReferencesProgress.cs index ba5c90f6ea97e..28c67beb09b8e 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/IStreamingFindReferencesProgress.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/IStreamingFindReferencesProgress.cs @@ -66,7 +66,7 @@ internal interface IStreamingFindReferencesProgress IStreamingProgressTracker ProgressTracker { get; } ValueTask OnStartedAsync(CancellationToken cancellationToken); - ValueTask OnCompletedAsync(CancellationToken cancellationToken); + ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken); ValueTask OnFindInDocumentStartedAsync(Document document, CancellationToken cancellationToken); ValueTask OnFindInDocumentCompletedAsync(Document document, CancellationToken cancellationToken); diff --git a/src/Workspaces/Remote/ServiceHub/Services/FindUsages/RemoteFindUsagesService.cs b/src/Workspaces/Remote/ServiceHub/Services/FindUsages/RemoteFindUsagesService.cs index 8ec4923b98d2c..ba3fc3b7d4e9b 100644 --- a/src/Workspaces/Remote/ServiceHub/Services/FindUsages/RemoteFindUsagesService.cs +++ b/src/Workspaces/Remote/ServiceHub/Services/FindUsages/RemoteFindUsagesService.cs @@ -108,7 +108,7 @@ public ValueTask ReportMessageAsync(string message, CancellationToken cancellati public ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) => _callback.InvokeAsync((callback, cancellationToken) => callback.SetSearchTitleAsync(_callbackId, title, cancellationToken), cancellationToken); - public ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) + public ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) { var id = GetOrAddDefinitionItemId(definition); var dehydratedDefinition = SerializableDefinitionItem.Dehydrate(id, definition); @@ -129,7 +129,7 @@ private int GetOrAddDefinitionItemId(DefinitionItem item) } } - public ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) + public ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) { var definitionItem = GetOrAddDefinitionItemId(reference.Definition); var dehydratedReference = SerializableSourceReferenceItem.Dehydrate(definitionItem, reference); From 42dceae75371cfb671829ceb6b9ce8f5473faaee Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Aug 2021 08:46:08 -0700 Subject: [PATCH 02/42] Don't hold onto documents in 'Find' features --- .../FindBaseSymbolsCommandHandler.cs | 4 +- .../FindDerivedSymbolsCommandHandler.cs | 4 +- .../FindExtensionMethodsCommandHandler.cs | 74 +++++++++---------- .../FindImplementingMembersCommandHandler.cs | 2 +- .../FindMemberOverloadsCommandHandler.cs | 4 +- ...FindReferencesOfOverloadsCommandHandler.cs | 5 +- .../FindReferencesCommandHandler.cs | 2 +- .../Core/FindUsages/FindUsagesContext.cs | 2 +- .../Host/IStreamingFindReferencesPresenter.cs | 2 +- .../FindReferencesCommandHandlerTests.cs | 2 +- .../InheritanceMarginTests.cs | 7 +- .../FindReferences/FindReferencesTests.vb | 27 +++---- .../GoToDefinition/GoToDefinitionTestsBase.vb | 2 +- .../Test2/GoToHelpers/GoToHelpers.vb | 5 +- .../ValueTracker.FindReferencesProgress.cs | 2 +- .../CustomProtocol/FindUsagesLSPContext.cs | 2 +- .../References/FindAllReferencesHandler.cs | 2 +- .../Debugger/DebuggerFindReferencesService.cs | 2 +- .../FindUsages/FSharpFindUsagesContext.cs | 8 +- .../FindUsages/FSharpFindUsagesService.cs | 4 +- ...bstractTableDataSourceFindUsagesContext.cs | 6 +- .../WithoutReferencesFindUsagesContext.cs | 2 +- .../MarginGlyph/InheritanceMargin.xaml.cs | 2 +- .../AbstractObjectBrowserLibraryManager.cs | 2 +- .../VisualStudioSymbolNavigationService.cs | 15 ++-- .../FindReferencesSearchEngine.cs | 2 +- .../NoOpStreamingFindReferencesProgress.cs | 2 +- .../StreamingFindReferencesProgress.cs | 2 +- .../FindSymbols/StreamingProgressCollector.cs | 7 +- ...mbolFinder.FindReferencesServerCallback.cs | 2 +- .../SymbolFinder/RemoteSymbolFinderService.cs | 4 +- 31 files changed, 109 insertions(+), 99 deletions(-) diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs index 117f0df95255b..c5661a0f20e1d 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs @@ -70,12 +70,12 @@ private async Task StreamingFindBaseSymbolsAsync( KeyValueLogMessage.Create(LogType.UserAction, m => m["type"] = "streaming"), cancellationToken)) { + var solution = document.Project.Solution; try { var relevantSymbol = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, cancellationToken).ConfigureAwait(false); var overriddenSymbol = relevantSymbol?.symbol.GetOverriddenMember(); - var solution = document.Project.Solution; while (overriddenSymbol != null) { if (cancellationToken.IsCancellationRequested) @@ -92,7 +92,7 @@ private async Task StreamingFindBaseSymbolsAsync( } finally { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs index 3cf1359365123..3e0bf771d6e98 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs @@ -84,6 +84,7 @@ private static async Task> GatherSymbolsAsync(ISymbol symbo private async Task FindDerivedSymbolsAsync( Document document, int caretPosition, IStreamingFindUsagesPresenter presenter) { + var solution = document.Project.Solution; try { using var token = _asyncListener.BeginAsyncOperation(nameof(FindDerivedSymbolsAsync)); @@ -100,7 +101,6 @@ private async Task FindDerivedSymbolsAsync( if (candidateSymbolProjectPair?.symbol == null) return; - var solution = document.Project.Solution; var candidates = await GatherSymbolsAsync( candidateSymbolProjectPair.Value.symbol, solution, cancellationToken).ConfigureAwait(false); @@ -113,7 +113,7 @@ private async Task FindDerivedSymbolsAsync( } finally { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs index 5ea7bbd1830f4..6aebb99319778 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs @@ -62,67 +62,65 @@ protected override bool TryExecuteCommand(int caretPosition, Document document, private async Task FindExtensionMethodsAsync( Document document, int caretPosition, IStreamingFindUsagesPresenter presenter) { + var solution = document.Project.Solution; try { using var token = _asyncListener.BeginAsyncOperation(nameof(FindExtensionMethodsAsync)); var (context, cancellationToken) = presenter.StartSearch(EditorFeaturesResources.Navigating, supportsReferences: true); - using (Logger.LogBlock( - FunctionId.CommandHandler_FindAllReference, - KeyValueLogMessage.Create(LogType.UserAction, m => m["type"] = "streaming"), - cancellationToken)) + try { - var candidateSymbolProjectPair = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, cancellationToken).ConfigureAwait(false); - - var symbol = candidateSymbolProjectPair?.symbol as INamedTypeSymbol; - - // if we didn't get the right symbol, just abort - if (symbol == null) + using (Logger.LogBlock( + FunctionId.CommandHandler_FindAllReference, + KeyValueLogMessage.Create(LogType.UserAction, m => m["type"] = "streaming"), + cancellationToken)) { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); - return; - } + var candidateSymbolProjectPair = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, cancellationToken).ConfigureAwait(false); - if (!document.Project.TryGetCompilation(out var compilation)) - { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); - return; - } + var symbol = candidateSymbolProjectPair?.symbol as INamedTypeSymbol; - var solution = document.Project.Solution; + // if we didn't get the right symbol, just abort + if (symbol == null) + return; - foreach (var type in compilation.Assembly.GlobalNamespace.GetAllTypes(cancellationToken)) - { - if (!type.MightContainExtensionMethods) - continue; + if (!document.Project.TryGetCompilation(out var compilation)) + return; - foreach (var extMethod in type.GetMembers().OfType().Where(method => method.IsExtensionMethod)) + foreach (var type in compilation.Assembly.GlobalNamespace.GetAllTypes(cancellationToken)) { - if (cancellationToken.IsCancellationRequested) - break; + if (!type.MightContainExtensionMethods) + continue; - var reducedMethod = extMethod.ReduceExtensionMethod(symbol); - if (reducedMethod != null) + foreach (var extMethod in type.GetMembers().OfType().Where(method => method.IsExtensionMethod)) { - var loc = extMethod.Locations.First(); + if (cancellationToken.IsCancellationRequested) + break; - var sourceDefinition = await SymbolFinder.FindSourceDefinitionAsync(reducedMethod, solution, cancellationToken).ConfigureAwait(false); - - // And if our definition actually is from source, then let's re-figure out what project it came from - if (sourceDefinition != null) + var reducedMethod = extMethod.ReduceExtensionMethod(symbol); + if (reducedMethod != null) { - var originatingProject = solution.GetProject(sourceDefinition.ContainingAssembly, cancellationToken); + var loc = extMethod.Locations.First(); + + var sourceDefinition = await SymbolFinder.FindSourceDefinitionAsync(reducedMethod, solution, cancellationToken).ConfigureAwait(false); + + // And if our definition actually is from source, then let's re-figure out what project it came from + if (sourceDefinition != null) + { + var originatingProject = solution.GetProject(sourceDefinition.ContainingAssembly, cancellationToken); - var definitionItem = reducedMethod.ToNonClassifiedDefinitionItem(solution, true); + var definitionItem = reducedMethod.ToNonClassifiedDefinitionItem(solution, true); - await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); + } } } } } - - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + } + finally + { + await context.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs index 6c3ee273ca489..c88de382641c4 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs @@ -119,7 +119,7 @@ private async Task FindImplementingMembersAsync( } finally { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs index 13c489a94204d..9d93ecfeb4dbd 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs @@ -70,6 +70,7 @@ private async Task FindMemberOverloadsAsync( KeyValueLogMessage.Create(LogType.UserAction, m => m["type"] = "streaming"), cancellationToken)) { + var solution = document.Project.Solution; try { var candidateSymbolProjectPair = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, cancellationToken).ConfigureAwait(false); @@ -81,7 +82,6 @@ private async Task FindMemberOverloadsAsync( if (symbol == null || symbol.ContainingType == null) return; - var solution = document.Project.Solution; foreach (var curSymbol in symbol.ContainingType.GetMembers() .Where(m => m.Kind == symbol.Kind && m.Name == symbol.Name)) { @@ -91,7 +91,7 @@ private async Task FindMemberOverloadsAsync( } finally { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs index 5006710ae5adb..962ff9d62f921 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs @@ -108,6 +108,7 @@ private async Task StreamingFindReferencesAsync( KeyValueLogMessage.Create(LogType.UserAction, m => m["type"] = "streaming"), cancellationToken)) { + var solution = document.Project.Solution; var symbolsToLookup = new List(); foreach (var curSymbol in symbol.ContainingType.GetMembers() @@ -122,7 +123,7 @@ private async Task StreamingFindReferencesAsync( foreach (var sym in SymbolFinder.FindSimilarSymbols(curSymbol, compilation, cancellationToken)) { // assumption here is, that FindSimilarSymbols returns symbols inside same project - var symbolsToAdd = await GatherSymbolsAsync(sym, document.Project.Solution, cancellationToken).ConfigureAwait(false); + var symbolsToAdd = await GatherSymbolsAsync(sym, solution, cancellationToken).ConfigureAwait(false); symbolsToLookup.AddRange(symbolsToAdd); } } @@ -137,7 +138,7 @@ private async Task StreamingFindReferencesAsync( // that means that a new search has started. We don't care about telling the // context it has completed. In the latter case something wrong has happened // and we don't want to run any more code in this particular context. - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/src/EditorFeatures/Core/FindReferences/FindReferencesCommandHandler.cs b/src/EditorFeatures/Core/FindReferences/FindReferencesCommandHandler.cs index b7c79db5a3fd2..5d78122c90279 100644 --- a/src/EditorFeatures/Core/FindReferences/FindReferencesCommandHandler.cs +++ b/src/EditorFeatures/Core/FindReferences/FindReferencesCommandHandler.cs @@ -137,7 +137,7 @@ private async Task StreamingFindReferencesAsync( } finally { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs b/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs index 7328ed3f0721e..08e0e2ba90986 100644 --- a/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs +++ b/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs @@ -19,7 +19,7 @@ protected FindUsagesContext() public virtual ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) => default; - public virtual ValueTask OnCompletedAsync(CancellationToken cancellationToken) => default; + public virtual ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) => default; public virtual ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) => default; diff --git a/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs b/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs index c1123f6a26932..d2053de3b16c1 100644 --- a/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs +++ b/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs @@ -116,7 +116,7 @@ public static async Task TryNavigateToOrPresentItemsAsync( } finally { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); } } diff --git a/src/EditorFeatures/Test/FindReferences/FindReferencesCommandHandlerTests.cs b/src/EditorFeatures/Test/FindReferences/FindReferencesCommandHandlerTests.cs index 38bcb96c02e7b..afae423000e15 100644 --- a/src/EditorFeatures/Test/FindReferences/FindReferencesCommandHandlerTests.cs +++ b/src/EditorFeatures/Test/FindReferences/FindReferencesCommandHandlerTests.cs @@ -31,7 +31,7 @@ private class MockFindUsagesContext : FindUsagesContext { public readonly List Result = new List(); - public override ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) + public override ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) { lock (Result) { diff --git a/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs b/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs index da73cc155115a..e93a4e56ff072 100644 --- a/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs +++ b/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs @@ -98,11 +98,11 @@ private static void VerifyInheritanceMember(TestWorkspace testWorkspace, TestInh .ToImmutableArray(); for (var i = 0; i < expectedTargets.Length; i++) { - VerifyInheritanceTarget(expectedTargets[i], sortedActualTargets[i]); + VerifyInheritanceTarget(testWorkspace.CurrentSolution, expectedTargets[i], sortedActualTargets[i]); } } - private static void VerifyInheritanceTarget(TestInheritanceTargetItem expectedTarget, InheritanceTargetItem actualTarget) + private static void VerifyInheritanceTarget(Solution solution, TestInheritanceTargetItem expectedTarget, InheritanceTargetItem actualTarget) { Assert.Equal(expectedTarget.TargetSymbolName, actualTarget.DefinitionItem.DisplayParts.JoinText()); Assert.Equal(expectedTarget.RelationshipToMember, actualTarget.RelationToMember); @@ -120,7 +120,8 @@ private static void VerifyInheritanceTarget(TestInheritanceTargetItem expectedTa for (var i = 0; i < actualDocumentSpans.Length; i++) { Assert.Equal(expectedDocumentSpans[i].SourceSpan, actualDocumentSpans[i].SourceSpan); - Assert.Equal(expectedDocumentSpans[i].Document.FilePath, actualDocumentSpans[i].Document.FilePath); + var document = solution.GetRequiredDocument(actualDocumentSpans[i].DocumentId); + Assert.Equal(expectedDocumentSpans[i].Document.FilePath, document.FilePath); } } } diff --git a/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb b/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb index e88e0ee842ffd..25bc5ff00852f 100644 --- a/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb +++ b/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb @@ -67,8 +67,9 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences For Each cursorDocument In workspace.Documents.Where(Function(d) d.CursorPosition.HasValue) Dim cursorPosition = cursorDocument.CursorPosition.Value - Dim startDocument = If(workspace.CurrentSolution.GetDocument(cursorDocument.Id), - Await workspace.CurrentSolution.GetSourceGeneratedDocumentAsync(cursorDocument.Id, CancellationToken.None)) + Dim solution = workspace.CurrentSolution + Dim startDocument = If(solution.GetDocument(cursorDocument.Id), + Await solution.GetSourceGeneratedDocumentAsync(cursorDocument.Id, CancellationToken.None)) Assert.NotNull(startDocument) Dim findRefsService = startDocument.GetLanguageService(Of IFindUsagesService) @@ -81,7 +82,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(d) New FileNameAndSpans( d.Name, d.AnnotatedSpans(DefinitionKey).ToList())).ToList() - Dim actualDefinitions = GetFileNamesAndSpans( + Dim actualDefinitions = GetFileNamesAndSpans(solution, context.Definitions.Where(AddressOf context.ShouldShow). SelectMany(Function(d) d.SourceSpans)) @@ -93,7 +94,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(d) New FileNameAndSpans( d.Name, d.SelectedSpans.ToList())).ToList() - Dim actualReferences = GetFileNamesAndSpans( + Dim actualReferences = GetFileNamesAndSpans(solution, context.References.Select(Function(r) r.SourceSpan)) Assert.Equal(expectedReferences, actualReferences) @@ -106,7 +107,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(d) New FileNameAndSpans( d.Name, d.AnnotatedSpans(key).ToList())).ToList() Dim valueUsageInfoField = key.Substring(ValueUsageInfoKey.Length) - Dim actual = GetFileNamesAndSpans( + Dim actual = GetFileNamesAndSpans(solution, context.References.Where(Function(r) r.SymbolUsageInfo.ValueUsageInfoOpt?.ToString() = valueUsageInfoField).Select(Function(r) r.SourceSpan)) Assert.Equal(expected, actual) @@ -120,7 +121,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(d) New FileNameAndSpans( d.Name, d.AnnotatedSpans(key).ToList())).ToList() Dim typeOrNamespaceUsageInfoFieldNames = key.Substring(TypeOrNamespaceUsageInfoKey.Length).Split(","c).Select(Function(s) s.Trim) - Dim actual = GetFileNamesAndSpans( + Dim actual = GetFileNamesAndSpans(solution, context.References.Where(Function(r) Return r.SymbolUsageInfo.TypeOrNamespaceUsageInfoOpt IsNot Nothing AndAlso r.SymbolUsageInfo.TypeOrNamespaceUsageInfoOpt.ToString().Split(","c).Select(Function(s) s.Trim).SetEquals(typeOrNamespaceUsageInfoFieldNames) @@ -139,7 +140,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences OrderBy(Function(d) d.Name). Select(Function(d) New FileNameAndSpans( d.Name, d.AnnotatedSpans(annotationKey).ToList())).ToList() - Dim actual = GetFileNamesAndSpans( + Dim actual = GetFileNamesAndSpans(solution, context.References.Where(Function(r) Dim actualValue As String = Nothing If r.AdditionalProperties.TryGetValue(propertyName, actualValue) Then @@ -176,14 +177,14 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Return additionalPropertiesMap End Function - Private Shared Function GetFileNamesAndSpans(items As IEnumerable(Of DocumentSpan)) As List(Of FileNameAndSpans) - Return items.Where(Function(i) i.Document IsNot Nothing). - GroupBy(Function(i) i.Document). + Private Shared Function GetFileNamesAndSpans(solution As Solution, items As IEnumerable(Of SerializableDocumentSpan)) As List(Of FileNameAndSpans) + Return items.Where(Function(i) i.DocumentId IsNot Nothing). + GroupBy(Function(i) solution.GetRequiredDocument(i.DocumentId)). OrderBy(Function(g) g.Key.Name). Select(Function(g) GetFileNameAndSpans(g)).ToList() End Function - Private Shared Function GetFileNameAndSpans(g As IGrouping(Of Document, DocumentSpan)) As FileNameAndSpans + Private Shared Function GetFileNameAndSpans(g As IGrouping(Of Document, SerializableDocumentSpan)) As FileNameAndSpans Return New FileNameAndSpans( g.Key.Name, g.Select(Function(i) i.SourceSpan).OrderBy(Function(s) s.Start). @@ -232,7 +233,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Return definition.DisplayIfNoReferences End Function - Public Overrides Function OnDefinitionFoundAsync(definition As DefinitionItem, cancellationToken As CancellationToken) As ValueTask + Public Overrides Function OnDefinitionFoundAsync(solution As Solution, definition As DefinitionItem, cancellationToken As CancellationToken) As ValueTask SyncLock gate Me.Definitions.Add(definition) End SyncLock @@ -240,7 +241,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Return Nothing End Function - Public Overrides Function OnReferenceFoundAsync(reference As SourceReferenceItem, cancellationToken As CancellationToken) As ValueTask + Public Overrides Function OnReferenceFoundAsync(solution As Solution, reference As SourceReferenceItem, cancellationToken As CancellationToken) As ValueTask SyncLock gate References.Add(reference) End SyncLock diff --git a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb index d97d0b6a347f5..59088a8041d2c 100644 --- a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb +++ b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb @@ -91,7 +91,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition For Each location In items For Each docSpan In location.SourceSpans - actualLocations.Add(New FilePathAndSpan(docSpan.Document.FilePath, docSpan.SourceSpan)) + actualLocations.Add(New FilePathAndSpan(solution.GetRequiredDocument(docSpan.DocumentId).FilePath, docSpan.SourceSpan)) Next Next diff --git a/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb b/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb index f1eca34f8ca03..22acb311f0d57 100644 --- a/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb +++ b/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb @@ -22,7 +22,8 @@ Friend Class GoToHelpers Dim documentWithCursor = workspace.DocumentWithCursor Dim position = documentWithCursor.CursorPosition.Value - Dim document = workspace.CurrentSolution.GetDocument(documentWithCursor.Id) + Dim solution = workspace.CurrentSolution + Dim document = solution.GetDocument(documentWithCursor.Id) Dim context = New SimpleFindUsagesContext() Await testingMethod(document, position, context) @@ -32,7 +33,7 @@ Friend Class GoToHelpers Else Dim actualDefinitions = context.GetDefinitions(). SelectMany(Function(d) d.SourceSpans). - Select(Function(ss) New FilePathAndSpan(ss.Document.FilePath, ss.SourceSpan)). + Select(Function(ss) New FilePathAndSpan(solution.GetRequiredDocument(ss.DocumentId).FilePath, ss.SourceSpan)). ToList() actualDefinitions.Sort() diff --git a/src/Features/Core/Portable/ValueTracking/ValueTracker.FindReferencesProgress.cs b/src/Features/Core/Portable/ValueTracking/ValueTracker.FindReferencesProgress.cs index 017373779b62a..9b31e64c42cb6 100644 --- a/src/Features/Core/Portable/ValueTracking/ValueTracker.FindReferencesProgress.cs +++ b/src/Features/Core/Portable/ValueTracking/ValueTracker.FindReferencesProgress.cs @@ -28,7 +28,7 @@ public FindReferencesProgress(OperationCollector valueTrackingProgressCollector) public ValueTask ItemCompletedAsync(CancellationToken _) => new(); - public ValueTask OnCompletedAsync(CancellationToken _) => new(); + public ValueTask OnCompletedAsync(Solution solution, CancellationToken _) => new(); public ValueTask OnDefinitionFoundAsync(SymbolGroup symbolGroup, CancellationToken _) => new(); diff --git a/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs b/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs index 39ae31dd17281..fec1c5e302343 100644 --- a/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs +++ b/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs @@ -86,7 +86,7 @@ public FindUsagesLSPContext( } // After all definitions/references have been found, wait here until all results have been reported. - public override async ValueTask OnCompletedAsync(CancellationToken cancellationToken) + public override async ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) => await _workQueue.WaitUntilCurrentBatchCompletesAsync().ConfigureAwait(false); public override async ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) diff --git a/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs b/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs index e36ac13036669..f9c2d6a47afe0 100644 --- a/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs @@ -63,7 +63,7 @@ public FindAllReferencesHandler( // Finds the references for the symbol at the specific position in the document, reporting them via streaming to the LSP client. await findUsagesService.FindReferencesAsync(document, position, findUsagesContext, cancellationToken).ConfigureAwait(false); - await findUsagesContext.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await findUsagesContext.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); return progress.GetValues(); } diff --git a/src/Tools/ExternalAccess/Debugger/DebuggerFindReferencesService.cs b/src/Tools/ExternalAccess/Debugger/DebuggerFindReferencesService.cs index c7526f1d34bc8..c1c2aa6661fde 100644 --- a/src/Tools/ExternalAccess/Debugger/DebuggerFindReferencesService.cs +++ b/src/Tools/ExternalAccess/Debugger/DebuggerFindReferencesService.cs @@ -48,7 +48,7 @@ public async Task FindSymbolReferencesAsync(ISymbol symbol, Project project, Can } finally { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(project.Solution, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs index e8bf8c1cb9041..6d5d0b1727d1f 100644 --- a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs +++ b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs @@ -11,11 +11,13 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.FSharp.Internal.Editor.FindUsage { internal class FSharpFindUsagesContext : IFSharpFindUsagesContext { + private readonly Solution _solution; private readonly IFindUsagesContext _context; private readonly CancellationToken _cancellationToken; - public FSharpFindUsagesContext(IFindUsagesContext context, CancellationToken cancellationToken) + public FSharpFindUsagesContext(Solution solution, IFindUsagesContext context, CancellationToken cancellationToken) { + _solution = solution; _context = context; _cancellationToken = cancellationToken; } @@ -24,12 +26,12 @@ public FSharpFindUsagesContext(IFindUsagesContext context, CancellationToken can public Task OnDefinitionFoundAsync(FSharp.FindUsages.FSharpDefinitionItem definition) { - return _context.OnDefinitionFoundAsync(definition.RoslynDefinitionItem, _cancellationToken).AsTask(); + return _context.OnDefinitionFoundAsync(_solution, definition.RoslynDefinitionItem, _cancellationToken).AsTask(); } public Task OnReferenceFoundAsync(FSharp.FindUsages.FSharpSourceReferenceItem reference) { - return _context.OnReferenceFoundAsync(reference.RoslynSourceReferenceItem, _cancellationToken).AsTask(); + return _context.OnReferenceFoundAsync(_solution, reference.RoslynSourceReferenceItem, _cancellationToken).AsTask(); } public Task ReportMessageAsync(string message) diff --git a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesService.cs b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesService.cs index 623dda3cb550c..8a3ccefe71b52 100644 --- a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesService.cs +++ b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesService.cs @@ -25,9 +25,9 @@ public FSharpFindUsagesService(IFSharpFindUsagesService service) => _service = service; public Task FindImplementationsAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _service.FindImplementationsAsync(document, position, new FSharpFindUsagesContext(context, cancellationToken)); + => _service.FindImplementationsAsync(document, position, new FSharpFindUsagesContext(document.Project.Solution, context, cancellationToken)); public Task FindReferencesAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _service.FindReferencesAsync(document, position, new FSharpFindUsagesContext(context, cancellationToken)); + => _service.FindReferencesAsync(document, position, new FSharpFindUsagesContext(document.Project.Solution, context, cancellationToken)); } } diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs index 6a0594f173cd0..7e0b7e94a98ab 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs @@ -303,14 +303,14 @@ public sealed override ValueTask SetSearchTitleAsync(string title, CancellationT return default; } - public sealed override async ValueTask OnCompletedAsync(CancellationToken cancellationToken) + public sealed override async ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) { - await OnCompletedAsyncWorkerAsync(cancellationToken).ConfigureAwait(false); + await OnCompletedAsyncWorkerAsync(solution, cancellationToken).ConfigureAwait(false); _tableDataSink.IsStable = true; } - protected abstract Task OnCompletedAsyncWorkerAsync(CancellationToken cancellationToken); + protected abstract Task OnCompletedAsyncWorkerAsync(Solution solution, CancellationToken cancellationToken); public sealed override ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) { diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs index d6f176115ac94..597fbb8e1f1d1 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs @@ -40,7 +40,7 @@ protected override ValueTask OnReferenceFoundWorkerAsync(Solution solution, Sour => throw new InvalidOperationException(); // Nothing to do on completion. - protected override Task OnCompletedAsyncWorkerAsync(CancellationToken cancellationToken) + protected override Task OnCompletedAsyncWorkerAsync(Solution solution, CancellationToken cancellationToken) => Task.CompletedTask; protected override async ValueTask OnDefinitionFoundWorkerAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) diff --git a/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/MarginGlyph/InheritanceMargin.xaml.cs b/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/MarginGlyph/InheritanceMargin.xaml.cs index 30e2294a889a7..d48730cc69010 100644 --- a/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/MarginGlyph/InheritanceMargin.xaml.cs +++ b/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/MarginGlyph/InheritanceMargin.xaml.cs @@ -73,7 +73,7 @@ private void TargetMenuItem_OnClick(object sender, RoutedEventArgs e) showProgress: false), context => GoToDefinitionHelpers.TryGoToDefinition( ImmutableArray.Create(viewModel.DefinitionItem), - _workspace, + _workspace.CurrentSolution, string.Format(EditorFeaturesResources._0_declarations, viewModel.DisplayContent), _threadingContext, _streamingFindUsagesPresenter, diff --git a/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs b/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs index 5bca469a14289..181b903fc1e0b 100644 --- a/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs +++ b/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs @@ -525,7 +525,7 @@ await Task.Run( } finally { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(project.Solution, cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs index 8b69b663f2a2d..0ce50bb1ac8cc 100644 --- a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs +++ b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs @@ -173,7 +173,7 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey1, out var rqName); if (!TryGetNavigationAPIRequiredArguments( - definitionItem, rqName, cancellationToken, + solution, definitionItem, rqName, cancellationToken, out var hierarchy, out var itemID, out var navigationNotify)) { return false; @@ -195,8 +195,8 @@ public bool WouldNavigateToSymbol( definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey1, out var rqName1); definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey2, out var rqName2); - if (WouldNotifyToSpecificSymbol(definitionItem, rqName1, cancellationToken, out filePath, out lineNumber, out charOffset) || - WouldNotifyToSpecificSymbol(definitionItem, rqName2, cancellationToken, out filePath, out lineNumber, out charOffset)) + if (WouldNotifyToSpecificSymbol(solution, definitionItem, rqName1, cancellationToken, out filePath, out lineNumber, out charOffset) || + WouldNotifyToSpecificSymbol(solution, definitionItem, rqName2, cancellationToken, out filePath, out lineNumber, out charOffset)) { return true; } @@ -208,7 +208,7 @@ public bool WouldNavigateToSymbol( } public bool WouldNotifyToSpecificSymbol( - DefinitionItem definitionItem, string? rqName, CancellationToken cancellationToken, + Solution solution, DefinitionItem definitionItem, string? rqName, CancellationToken cancellationToken, [NotNullWhen(true)] out string? filePath, out int lineNumber, out int charOffset) { AssertIsForeground(); @@ -223,7 +223,7 @@ public bool WouldNotifyToSpecificSymbol( } if (!TryGetNavigationAPIRequiredArguments( - definitionItem, rqName, cancellationToken, + solution, definitionItem, rqName, cancellationToken, out var hierarchy, out var itemID, out var navigationNotify)) { return false; @@ -252,6 +252,7 @@ public bool WouldNotifyToSpecificSymbol( } private bool TryGetNavigationAPIRequiredArguments( + Solution solution, DefinitionItem definitionItem, string? rqName, CancellationToken cancellationToken, @@ -276,7 +277,9 @@ private bool TryGetNavigationAPIRequiredArguments( return false; } - var documents = sourceLocations.SelectAsArray(loc => loc.Document); + var documents = sourceLocations.Select(loc => solution.GetDocument(loc.DocumentId)) + .WhereNotNull() + .ToImmutableArrayOrEmpty(); // We can only pass one itemid to IVsSymbolicNavigationNotify, so prefer itemids from // documents we consider to be "generated" to give external language services the best diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs index b31f26d59a01b..e986586ff3d28 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs @@ -113,7 +113,7 @@ public async Task FindReferencesAsync(ISymbol symbol, CancellationToken cancella } finally { - await _progress.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await _progress.OnCompletedAsync(_solution, cancellationToken).ConfigureAwait(false); } } diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/NoOpStreamingFindReferencesProgress.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/NoOpStreamingFindReferencesProgress.cs index 9dfc71ad26461..266a038607d65 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/NoOpStreamingFindReferencesProgress.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/NoOpStreamingFindReferencesProgress.cs @@ -29,7 +29,7 @@ private NoOpStreamingFindReferencesProgress() public static Task ReportProgressAsync(int current, int maximum) => Task.CompletedTask; #pragma warning restore IDE0060 // Remove unused parameter - public ValueTask OnCompletedAsync(CancellationToken cancellationToken) => default; + public ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) => default; public ValueTask OnStartedAsync(CancellationToken cancellationToken) => default; public ValueTask OnDefinitionFoundAsync(SymbolGroup group, CancellationToken cancellationToken) => default; public ValueTask OnReferenceFoundAsync(SymbolGroup group, ISymbol symbol, ReferenceLocation location, CancellationToken cancellationToken) => default; diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/StreamingFindReferencesProgress.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/StreamingFindReferencesProgress.cs index 0dc8f2679485c..d60a8f931dc49 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/StreamingFindReferencesProgress.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/StreamingFindReferencesProgress.cs @@ -30,7 +30,7 @@ public StreamingFindReferencesProgressAdapter(IFindReferencesProgress progress) }); } - public ValueTask OnCompletedAsync(CancellationToken cancellationToken) + public ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) { _progress.OnCompleted(); return default; diff --git a/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs b/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs index fcc4e5d2c12f7..22422ca016d02 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs @@ -54,8 +54,11 @@ public ImmutableArray GetReferencedSymbols() } } - public ValueTask OnStartedAsync(CancellationToken cancellationToken) => _underlyingProgress.OnStartedAsync(cancellationToken); - public ValueTask OnCompletedAsync(CancellationToken cancellationToken) => _underlyingProgress.OnCompletedAsync(cancellationToken); + public ValueTask OnStartedAsync(CancellationToken cancellationToken) + => _underlyingProgress.OnStartedAsync(cancellationToken); + + public ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) + => _underlyingProgress.OnCompletedAsync(solution, cancellationToken); public ValueTask OnFindInDocumentCompletedAsync(Document document, CancellationToken cancellationToken) => _underlyingProgress.OnFindInDocumentCompletedAsync(document, cancellationToken); public ValueTask OnFindInDocumentStartedAsync(Document document, CancellationToken cancellationToken) => _underlyingProgress.OnFindInDocumentStartedAsync(document, cancellationToken); diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.FindReferencesServerCallback.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.FindReferencesServerCallback.cs index 77d5c5640eb39..e10ae4002608b 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.FindReferencesServerCallback.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.FindReferencesServerCallback.cs @@ -47,7 +47,7 @@ public ValueTask OnStartedAsync(CancellationToken cancellationToken) => _progress.OnStartedAsync(cancellationToken); public ValueTask OnCompletedAsync(CancellationToken cancellationToken) - => _progress.OnCompletedAsync(cancellationToken); + => _progress.OnCompletedAsync(_solution, cancellationToken); public ValueTask OnFindInDocumentStartedAsync(DocumentId documentId, CancellationToken cancellationToken) { diff --git a/src/Workspaces/Remote/ServiceHub/Services/SymbolFinder/RemoteSymbolFinderService.cs b/src/Workspaces/Remote/ServiceHub/Services/SymbolFinder/RemoteSymbolFinderService.cs index d1fe987bbfb55..306f708c95933 100644 --- a/src/Workspaces/Remote/ServiceHub/Services/SymbolFinder/RemoteSymbolFinderService.cs +++ b/src/Workspaces/Remote/ServiceHub/Services/SymbolFinder/RemoteSymbolFinderService.cs @@ -53,7 +53,7 @@ public ValueTask FindReferencesAsync( if (symbol == null) { await progressCallback.OnStartedAsync(cancellationToken).ConfigureAwait(false); - await progressCallback.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await progressCallback.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); return; } @@ -224,7 +224,7 @@ public FindReferencesProgressCallback(Solution solution, RemoteCallback _callback.InvokeAsync((callback, cancellationToken) => callback.OnStartedAsync(_callbackId, cancellationToken), cancellationToken); - public ValueTask OnCompletedAsync(CancellationToken cancellationToken) + public ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) => _callback.InvokeAsync((callback, cancellationToken) => callback.OnCompletedAsync(_callbackId, cancellationToken), cancellationToken); public ValueTask OnFindInDocumentStartedAsync(Document document, CancellationToken cancellationToken) From 3cd32476ac39a749e08be71d8311b3a76682cd1b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Aug 2021 09:03:15 -0700 Subject: [PATCH 03/42] Move to rehydrate --- .../InheritanceMargin/InheritanceMarginTests.cs | 14 +++++++------- .../GoToDefinition/GoToDefinitionTestsBase.vb | 7 ++++--- .../CustomProtocol/FindUsagesLSPContext.cs | 5 +++-- .../References/FindImplementationsHandler.cs | 2 +- .../AbstractTableDataSourceFindUsagesContext.cs | 4 ++-- .../Contexts/WithoutReferencesFindUsagesContext.cs | 3 +-- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs b/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs index e93a4e56ff072..165b47127ea28 100644 --- a/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs +++ b/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs @@ -81,11 +81,11 @@ private static async Task VerifyTestMemberInDocumentAsync( for (var i = 0; i < sortedActualItems.Length; i++) { - VerifyInheritanceMember(testWorkspace, sortedExpectedItems[i], sortedActualItems[i]); + await VerifyInheritanceMemberAsync(testWorkspace, sortedExpectedItems[i], sortedActualItems[i]); } } - private static void VerifyInheritanceMember(TestWorkspace testWorkspace, TestInheritanceMemberItem expectedItem, InheritanceMarginItem actualItem) + private static async Task VerifyInheritanceMemberAsync(TestWorkspace testWorkspace, TestInheritanceMemberItem expectedItem, InheritanceMarginItem actualItem) { Assert.Equal(expectedItem.LineNumber, actualItem.LineNumber); Assert.Equal(expectedItem.MemberName, actualItem.DisplayTexts.JoinText()); @@ -98,11 +98,11 @@ private static void VerifyInheritanceMember(TestWorkspace testWorkspace, TestInh .ToImmutableArray(); for (var i = 0; i < expectedTargets.Length; i++) { - VerifyInheritanceTarget(testWorkspace.CurrentSolution, expectedTargets[i], sortedActualTargets[i]); + await VerifyInheritanceTargetAsync(testWorkspace.CurrentSolution, expectedTargets[i], sortedActualTargets[i]); } } - private static void VerifyInheritanceTarget(Solution solution, TestInheritanceTargetItem expectedTarget, InheritanceTargetItem actualTarget) + private static async Task VerifyInheritanceTargetAsync(Solution solution, TestInheritanceTargetItem expectedTarget, InheritanceTargetItem actualTarget) { Assert.Equal(expectedTarget.TargetSymbolName, actualTarget.DefinitionItem.DisplayParts.JoinText()); Assert.Equal(expectedTarget.RelationshipToMember, actualTarget.RelationToMember); @@ -119,9 +119,9 @@ private static void VerifyInheritanceTarget(Solution solution, TestInheritanceTa Assert.Equal(expectedDocumentSpans.Length, actualDocumentSpans.Length); for (var i = 0; i < actualDocumentSpans.Length; i++) { - Assert.Equal(expectedDocumentSpans[i].SourceSpan, actualDocumentSpans[i].SourceSpan); - var document = solution.GetRequiredDocument(actualDocumentSpans[i].DocumentId); - Assert.Equal(expectedDocumentSpans[i].Document.FilePath, document.FilePath); + var docSpan = await actualDocumentSpans[i].RehydrateAsync(solution, CancellationToken.None); + Assert.Equal(expectedDocumentSpans[i].SourceSpan, docSpan.SourceSpan); + Assert.Equal(expectedDocumentSpans[i].Document.FilePath, docSpan.Document.FilePath); } } } diff --git a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb index 59088a8041d2c..ea968cd1c17e7 100644 --- a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb +++ b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb @@ -14,7 +14,7 @@ Imports Microsoft.VisualStudio.Text Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition Public Class GoToDefinitionTestsBase - Private Shared Sub Test( + Private Shared Async Sub Test( workspaceDefinition As XElement, expectedResult As Boolean, executeOnDocument As Func(Of Document, Integer, IThreadingContext, IStreamingFindUsagesPresenter, Boolean)) @@ -90,8 +90,9 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition Dim items = context.GetDefinitions() For Each location In items - For Each docSpan In location.SourceSpans - actualLocations.Add(New FilePathAndSpan(solution.GetRequiredDocument(docSpan.DocumentId).FilePath, docSpan.SourceSpan)) + For Each ss In location.SourceSpans + Dim docSpan = Await ss.RehydrateAsync(solution, CancellationToken.None) + actualLocations.Add(New FilePathAndSpan(docSpan.Document.FilePath, docSpan.SourceSpan)) Next Next diff --git a/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs b/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs index fec1c5e302343..d6b89ca58b545 100644 --- a/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs +++ b/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs @@ -133,7 +133,8 @@ public override async ValueTask OnReferenceFoundAsync(Solution solution, SourceR if (!_definitionToId.TryGetValue(reference.Definition, out var definitionId)) return; - var document = solution.GetRequiredDocument(reference.SourceSpan.DocumentId); + var documentSpan = await reference.SourceSpan.RehydrateAsync(solution, cancellationToken).ConfigureAwait(false); + var document = documentSpan.Document; // If this is reference to the same physical location we've already reported, just // filter this out. it will clutter the UI to show the same places. @@ -176,7 +177,7 @@ public override async ValueTask OnReferenceFoundAsync(Solution solution, SourceR bool isWrittenTo, CancellationToken cancellationToken) { - var documentSpan = new DocumentSpan(document.Project.Solution.GetRequiredDocument(serializableDocumentSpan.DocumentId), serializableDocumentSpan.SourceSpan); + var documentSpan = await serializableDocumentSpan.RehydrateAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); var location = await ComputeLocationAsync(document, position, documentSpan, metadataAsSourceFileService, cancellationToken).ConfigureAwait(false); // Getting the text for the Text property. If we somehow can't compute the text, that means we're probably dealing with a metadata diff --git a/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs b/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs index 77b2db4d17c9d..3bacd732576ca 100644 --- a/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs @@ -52,7 +52,7 @@ public FindImplementationsHandler() var text = definition.GetClassifiedText(); foreach (var sourceSpan in definition.SourceSpans) { - var span = new DocumentSpan(solution.GetRequiredDocument(sourceSpan.DocumentId), sourceSpan.SourceSpan); + var span = await sourceSpan.RehydrateAsync(solution, cancellationToken).ConfigureAwait(false); if (context.ClientCapabilities?.HasVisualStudioLspCapability() == true) { locations.AddIfNotNull(await ProtocolConversions.DocumentSpanToLocationWithTextAsync(span, text, cancellationToken).ConfigureAwait(false)); diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs index 7e0b7e94a98ab..6e78491cf7c36 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs @@ -333,8 +333,8 @@ public sealed override ValueTask OnDefinitionFoundAsync(Solution solution, Defin ImmutableDictionary additionalProperties, CancellationToken cancellationToken) { - var document = solution.GetRequiredDocument(serializableDocumentSpan.DocumentId); - var documentSpan = new DocumentSpan(document, serializableDocumentSpan.SourceSpan); + var documentSpan = await serializableDocumentSpan.RehydrateAsync(solution, cancellationToken).ConfigureAwait(false); + var document = documentSpan.Document; var sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); var (excerptResult, lineText) = await ExcerptAsync(sourceText, documentSpan, cancellationToken).ConfigureAwait(false); diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs index 597fbb8e1f1d1..073d5b326eac5 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs @@ -99,8 +99,7 @@ protected override async ValueTask OnDefinitionFoundWorkerAsync(Solution solutio private async Task TryCreateEntryAsync( Solution solution, RoslynDefinitionBucket definitionBucket, DefinitionItem definition, CancellationToken cancellationToken) { - var document = solution.GetRequiredDocument(definition.SourceSpans[0].DocumentId); - var documentSpan = new DocumentSpan(document, definition.SourceSpans[0].SourceSpan); + var documentSpan = await definition.SourceSpans[0].RehydrateAsync(solution, cancellationToken).ConfigureAwait(false); var (guid, projectName, _) = GetGuidAndProjectInfo(documentSpan.Document); var sourceText = await documentSpan.Document.GetTextAsync(cancellationToken).ConfigureAwait(false); From f65655f6827fd0bc262b604552e655437e49a2a5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Aug 2021 09:28:03 -0700 Subject: [PATCH 04/42] Move to rehydrate --- .../Core.Wpf/Peek/PeekableItemFactory.cs | 5 +- .../FindReferences/FindReferencesTests.vb | 39 ++++--- .../DefaultSymbolNavigationService.cs | 11 +- .../Navigation/ISymbolNavigationService.cs | 6 +- .../VisualStudioSymbolNavigationService.cs | 104 +++++++----------- 5 files changed, 69 insertions(+), 96 deletions(-) diff --git a/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs b/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs index 64f04022aa8c6..3b95b6e5b8715 100644 --- a/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs +++ b/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs @@ -67,9 +67,8 @@ public async Task> GetPeekableItemsAsync( var symbolNavigationService = solution.Workspace.Services.GetService(); var definitionItem = symbol.ToNonClassifiedDefinitionItem(solution, includeHiddenLocations: true); - if (symbolNavigationService.WouldNavigateToSymbol( - definitionItem, solution, cancellationToken, - out var filePath, out var lineNumber, out var charOffset)) + var result = await symbolNavigationService.WouldNavigateToSymbolAsync(definitionItem, solution, cancellationToken).ConfigureAwait(false); + if (result is var (filePath, lineNumber, charOffset)) { var position = new LinePosition(lineNumber, charOffset); results.Add(new ExternalFilePeekableItem(new FileLinePositionSpan(filePath, position, position), PredefinedPeekRelationships.Definitions, peekResultFactory)); diff --git a/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb b/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb index 25bc5ff00852f..3db1017743fd2 100644 --- a/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb +++ b/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb @@ -82,7 +82,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(d) New FileNameAndSpans( d.Name, d.AnnotatedSpans(DefinitionKey).ToList())).ToList() - Dim actualDefinitions = GetFileNamesAndSpans(solution, + Dim actualDefinitions = Await GetFileNamesAndSpansAsync(solution, context.Definitions.Where(AddressOf context.ShouldShow). SelectMany(Function(d) d.SourceSpans)) @@ -94,7 +94,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(d) New FileNameAndSpans( d.Name, d.SelectedSpans.ToList())).ToList() - Dim actualReferences = GetFileNamesAndSpans(solution, + Dim actualReferences = Await GetFileNamesAndSpansAsync(solution, context.References.Select(Function(r) r.SourceSpan)) Assert.Equal(expectedReferences, actualReferences) @@ -107,7 +107,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(d) New FileNameAndSpans( d.Name, d.AnnotatedSpans(key).ToList())).ToList() Dim valueUsageInfoField = key.Substring(ValueUsageInfoKey.Length) - Dim actual = GetFileNamesAndSpans(solution, + Dim actual = Await GetFileNamesAndSpansAsync(solution, context.References.Where(Function(r) r.SymbolUsageInfo.ValueUsageInfoOpt?.ToString() = valueUsageInfoField).Select(Function(r) r.SourceSpan)) Assert.Equal(expected, actual) @@ -121,7 +121,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(d) New FileNameAndSpans( d.Name, d.AnnotatedSpans(key).ToList())).ToList() Dim typeOrNamespaceUsageInfoFieldNames = key.Substring(TypeOrNamespaceUsageInfoKey.Length).Split(","c).Select(Function(s) s.Trim) - Dim actual = GetFileNamesAndSpans(solution, + Dim actual = Await GetFileNamesAndSpansAsync(solution, context.References.Where(Function(r) Return r.SymbolUsageInfo.TypeOrNamespaceUsageInfoOpt IsNot Nothing AndAlso r.SymbolUsageInfo.TypeOrNamespaceUsageInfoOpt.ToString().Split(","c).Select(Function(s) s.Trim).SetEquals(typeOrNamespaceUsageInfoFieldNames) @@ -140,7 +140,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences OrderBy(Function(d) d.Name). Select(Function(d) New FileNameAndSpans( d.Name, d.AnnotatedSpans(annotationKey).ToList())).ToList() - Dim actual = GetFileNamesAndSpans(solution, + Dim actual = Await GetFileNamesAndSpansAsync(solution, context.References.Where(Function(r) Dim actualValue As String = Nothing If r.AdditionalProperties.TryGetValue(propertyName, actualValue) Then @@ -177,18 +177,29 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Return additionalPropertiesMap End Function - Private Shared Function GetFileNamesAndSpans(solution As Solution, items As IEnumerable(Of SerializableDocumentSpan)) As List(Of FileNameAndSpans) - Return items.Where(Function(i) i.DocumentId IsNot Nothing). - GroupBy(Function(i) solution.GetRequiredDocument(i.DocumentId)). - OrderBy(Function(g) g.Key.Name). - Select(Function(g) GetFileNameAndSpans(g)).ToList() + Private Shared Async Function GetFileNamesAndSpansAsync(solution As Solution, items As IEnumerable(Of SerializableDocumentSpan)) As Task(Of List(Of FileNameAndSpans)) + Dim dict = New Dictionary(Of Document, List(Of SerializableDocumentSpan)) + + For Each item In items + Dim docSpan = Await item.RehydrateAsync(solution, CancellationToken.None) + + Dim list As List(Of SerializableDocumentSpan) = Nothing + If Not dict.TryGetValue(docSpan.Document, list) Then + list = New List(Of SerializableDocumentSpan)() + dict.Add(docSpan.Document, list) + End If + + list.Add(item) + Next + + Return dict.OrderBy(Function(g) g.Key.Name). + Select(Function(g) GetFileNameAndSpans(g.Key, g.Value)).ToList() End Function - Private Shared Function GetFileNameAndSpans(g As IGrouping(Of Document, SerializableDocumentSpan)) As FileNameAndSpans + Private Shared Function GetFileNameAndSpans(document As Document, items As List(Of SerializableDocumentSpan)) As FileNameAndSpans Return New FileNameAndSpans( - g.Key.Name, - g.Select(Function(i) i.SourceSpan).OrderBy(Function(s) s.Start). - Distinct().ToList()) + document.Name, + items.Select(Function(i) i.SourceSpan).OrderBy(Function(s) s.Start).Distinct().ToList()) End Function Private Structure FileNameAndSpans diff --git a/src/Features/Core/Portable/Navigation/DefaultSymbolNavigationService.cs b/src/Features/Core/Portable/Navigation/DefaultSymbolNavigationService.cs index e83f04659ab10..88732fd717c39 100644 --- a/src/Features/Core/Portable/Navigation/DefaultSymbolNavigationService.cs +++ b/src/Features/Core/Portable/Navigation/DefaultSymbolNavigationService.cs @@ -19,15 +19,10 @@ public bool TryNavigateToSymbol(ISymbol symbol, Project project, OptionSet? opti public Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project project, CancellationToken cancellationToken) => SpecializedTasks.False; - public bool WouldNavigateToSymbol( - DefinitionItem definitionItem, Solution solution, CancellationToken cancellationToken, - [NotNullWhen(true)] out string? filePath, out int lineNumber, out int charOffset) + public Task<(string filePath, int lineNumber, int charOffset)?> WouldNavigateToSymbolAsync( + DefinitionItem definitionItem, Solution solution, CancellationToken cancellationToken) { - filePath = null; - lineNumber = 0; - charOffset = 0; - - return false; + return Task.FromResult<(string filePath, int lineNumber, int charOffset)?>(null); } } } diff --git a/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs b/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs index ad30f8cf4da83..079d919b1046a 100644 --- a/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs +++ b/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.FindUsages; @@ -29,8 +28,7 @@ internal interface ISymbolNavigationService : IWorkspaceService Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project project, CancellationToken cancellationToken); /// True if the navigation would be handled. - bool WouldNavigateToSymbol( - DefinitionItem definitionItem, Solution solution, CancellationToken cancellationToken, - [NotNullWhen(true)] out string? filePath, out int lineNumber, out int charOffset); + Task<(string filePath, int lineNumber, int charOffset)?> WouldNavigateToSymbolAsync( + DefinitionItem definitionItem, Solution solution, CancellationToken cancellationToken); } } diff --git a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs index 0ce50bb1ac8cc..47a81801c2c02 100644 --- a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs +++ b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs @@ -18,6 +18,7 @@ using Microsoft.CodeAnalysis.MetadataAsSource; using Microsoft.CodeAnalysis.Navigation; using Microsoft.CodeAnalysis.Options; +using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.Editor; @@ -172,12 +173,10 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p var definitionItem = symbol.ToNonClassifiedDefinitionItem(solution, includeHiddenLocations: true); definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey1, out var rqName); - if (!TryGetNavigationAPIRequiredArguments( - solution, definitionItem, rqName, cancellationToken, - out var hierarchy, out var itemID, out var navigationNotify)) - { + var result = await TryGetNavigationAPIRequiredArgumentsAsync( + solution, definitionItem, rqName, cancellationToken).ConfigureAwait(true); + if (result is not var (hierarchy, itemID, navigationNotify)) return false; - } var returnCode = navigationNotify.OnBeforeNavigateToSymbol( hierarchy, @@ -188,46 +187,28 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p return returnCode == VSConstants.S_OK && navigationHandled == 1; } - public bool WouldNavigateToSymbol( - DefinitionItem definitionItem, Solution solution, CancellationToken cancellationToken, - [NotNullWhen(true)] out string? filePath, out int lineNumber, out int charOffset) + public async Task<(string filePath, int lineNumber, int charOffset)?> WouldNavigateToSymbolAsync( + DefinitionItem definitionItem, Solution solution, CancellationToken cancellationToken) { definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey1, out var rqName1); definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey2, out var rqName2); - if (WouldNotifyToSpecificSymbol(solution, definitionItem, rqName1, cancellationToken, out filePath, out lineNumber, out charOffset) || - WouldNotifyToSpecificSymbol(solution, definitionItem, rqName2, cancellationToken, out filePath, out lineNumber, out charOffset)) - { - return true; - } - - filePath = null; - lineNumber = 0; - charOffset = 0; - return false; + return await WouldNotifyToSpecificSymbolAsync(solution, definitionItem, rqName1, cancellationToken).ConfigureAwait(false) ?? + await WouldNotifyToSpecificSymbolAsync(solution, definitionItem, rqName2, cancellationToken).ConfigureAwait(false); } - public bool WouldNotifyToSpecificSymbol( - Solution solution, DefinitionItem definitionItem, string? rqName, CancellationToken cancellationToken, - [NotNullWhen(true)] out string? filePath, out int lineNumber, out int charOffset) + public async Task<(string filePath, int lineNumber, int charOffset)?> WouldNotifyToSpecificSymbolAsync( + Solution solution, DefinitionItem definitionItem, string? rqName, CancellationToken cancellationToken) { AssertIsForeground(); - filePath = null; - lineNumber = 0; - charOffset = 0; - if (rqName == null) - { - return false; - } + return null; - if (!TryGetNavigationAPIRequiredArguments( - solution, definitionItem, rqName, cancellationToken, - out var hierarchy, out var itemID, out var navigationNotify)) - { - return false; - } + var values = await TryGetNavigationAPIRequiredArgumentsAsync( + solution, definitionItem, rqName, cancellationToken).ConfigureAwait(true); + if (values is not var (hierarchy, itemID, navigationNotify)) + return null; var navigateToTextSpan = new Microsoft.VisualStudio.TextManager.Interop.TextSpan[1]; @@ -240,46 +221,39 @@ public bool WouldNotifyToSpecificSymbol( navigateToTextSpan, out var wouldNavigate); - if (queryNavigateStatusCode == VSConstants.S_OK && wouldNavigate == 1) - { - navigateToHierarchy.GetCanonicalName(navigateToItem, out filePath); - lineNumber = navigateToTextSpan[0].iStartLine; - charOffset = navigateToTextSpan[0].iStartIndex; - return true; - } + if (queryNavigateStatusCode != VSConstants.S_OK || wouldNavigate != 1) + return null; - return false; + navigateToHierarchy.GetCanonicalName(navigateToItem, out var filePath); + var lineNumber = navigateToTextSpan[0].iStartLine; + var charOffset = navigateToTextSpan[0].iStartIndex; + + return (filePath, lineNumber, charOffset); } - private bool TryGetNavigationAPIRequiredArguments( + private async Task<(IVsHierarchy hierarchy, uint itemId, IVsSymbolicNavigationNotify navigationNotify)?> TryGetNavigationAPIRequiredArgumentsAsync( Solution solution, DefinitionItem definitionItem, string? rqName, - CancellationToken cancellationToken, - [NotNullWhen(true)] out IVsHierarchy? hierarchy, - out uint itemID, - [NotNullWhen(true)] out IVsSymbolicNavigationNotify? navigationNotify) + CancellationToken cancellationToken) { AssertIsForeground(); - hierarchy = null; - navigationNotify = null; - itemID = (uint)VSConstants.VSITEMID.Nil; - if (rqName == null) - { - return false; - } + return null; var sourceLocations = definitionItem.SourceSpans; if (!sourceLocations.Any()) + return null; + + using var _ = ArrayBuilder.GetInstance(out var documentsBuilder); + foreach (var loc in sourceLocations) { - return false; + var docSpan = await loc.RehydrateAsync(solution, cancellationToken).ConfigureAwait(true); + documentsBuilder.AddIfNotNull(docSpan.Document); } - var documents = sourceLocations.Select(loc => solution.GetDocument(loc.DocumentId)) - .WhereNotNull() - .ToImmutableArrayOrEmpty(); + var documents = documentsBuilder.ToImmutable(); // We can only pass one itemid to IVsSymbolicNavigationNotify, so prefer itemids from // documents we consider to be "generated" to give external language services the best @@ -288,18 +262,14 @@ private bool TryGetNavigationAPIRequiredArguments( var generatedDocuments = documents.WhereAsArray(d => d.IsGeneratedCode(cancellationToken)); var documentToUse = generatedDocuments.FirstOrDefault() ?? documents.First(); - if (!TryGetVsHierarchyAndItemId(documentToUse, out hierarchy, out itemID)) - { - return false; - } + if (!TryGetVsHierarchyAndItemId(documentToUse, out var hierarchy, out var itemID)) + return null; - navigationNotify = hierarchy as IVsSymbolicNavigationNotify; + var navigationNotify = hierarchy as IVsSymbolicNavigationNotify; if (navigationNotify == null) - { - return false; - } + return null; - return true; + return (hierarchy, itemID, navigationNotify); } private bool TryGetVsHierarchyAndItemId(Document document, [NotNullWhen(true)] out IVsHierarchy? hierarchy, out uint itemID) From b42ba1b1c8384a72a5ac26efd23bfab01f054c98 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Aug 2021 09:34:44 -0700 Subject: [PATCH 05/42] Sigh... --- ...bstractFindUsagesService_FindReferences.cs | 20 +++++++++++++------ .../IDefinitionsAndReferencesFactory.cs | 7 +++---- .../GoToDefinition/GoToDefinitionHelpers.cs | 7 +++++-- .../Test2/GoToHelpers/GoToHelpers.vb | 12 +++++++---- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs index 2354905c34231..3e34241d0c43d 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs @@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.FindSymbols; using Microsoft.CodeAnalysis.FindUsages; using Microsoft.CodeAnalysis.LanguageServices; +using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Remote; using Microsoft.CodeAnalysis.Shared.Extensions; using Roslyn.Utilities; @@ -33,8 +34,8 @@ await FindLiteralOrSymbolReferencesAsync( // After the FAR engine is done call into any third party extensions to see // if they want to add results. - var thirdPartyDefinitions = GetThirdPartyDefinitions( - document.Project.Solution, definitionTrackingContext.GetDefinitions(), cancellationToken); + var thirdPartyDefinitions = await GetThirdPartyDefinitionsAsync( + document.Project.Solution, definitionTrackingContext.GetDefinitions(), cancellationToken).ConfigureAwait(true); // From this point on we can do ConfigureAwait(false) as we're not calling back // into third parties anymore. @@ -74,15 +75,22 @@ await FindSymbolReferencesAsync( document, position, context, cancellationToken).ConfigureAwait(false); } - private static ImmutableArray GetThirdPartyDefinitions( + private static async Task> GetThirdPartyDefinitionsAsync( Solution solution, ImmutableArray definitions, CancellationToken cancellationToken) { + using var _ = ArrayBuilder.GetInstance(out var result); + var factory = solution.Workspace.Services.GetRequiredService(); - return definitions.Select(d => factory.GetThirdPartyDefinitionItem(solution, d, cancellationToken)) - .WhereNotNull() - .ToImmutableArray(); + + foreach (var definition in definitions) + { + var thirdParty = await factory.GetThirdPartyDefinitionItemAsync(solution, definition, cancellationToken).ConfigureAwait(true); + result.AddIfNotNull(thirdParty); + } + + return result.ToImmutable(); } private static async Task FindSymbolReferencesAsync( diff --git a/src/EditorFeatures/Core/FindUsages/IDefinitionsAndReferencesFactory.cs b/src/EditorFeatures/Core/FindUsages/IDefinitionsAndReferencesFactory.cs index 74f1fff6d3164..d84848d3af49f 100644 --- a/src/EditorFeatures/Core/FindUsages/IDefinitionsAndReferencesFactory.cs +++ b/src/EditorFeatures/Core/FindUsages/IDefinitionsAndReferencesFactory.cs @@ -16,7 +16,6 @@ using Microsoft.CodeAnalysis.FindUsages; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Collections; using Microsoft.CodeAnalysis.Shared.Extensions; using Roslyn.Utilities; @@ -27,7 +26,7 @@ namespace Microsoft.CodeAnalysis.Editor.FindUsages internal interface IDefinitionsAndReferencesFactory : IWorkspaceService { - DefinitionItem? GetThirdPartyDefinitionItem( + Task GetThirdPartyDefinitionItemAsync( Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken); } @@ -44,10 +43,10 @@ public DefaultDefinitionsAndReferencesFactory() /// Provides an extension point that allows for other workspace layers to add additional /// results to the results found by the FindReferences engine. /// - public virtual DefinitionItem? GetThirdPartyDefinitionItem( + public virtual Task GetThirdPartyDefinitionItemAsync( Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken) { - return null; + return SpecializedTasks.Null(); } } diff --git a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs index 903949b9a59f8..03eb0d0c761db 100644 --- a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs +++ b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs @@ -88,8 +88,11 @@ public static ImmutableArray GetDefinitions( if (thirdPartyNavigationAllowed) { var factory = solution.Workspace.Services.GetService(); - var thirdPartyItem = factory?.GetThirdPartyDefinitionItem(solution, definitionItem, cancellationToken); - definitions.AddIfNotNull(thirdPartyItem); + if (factory != null) + { + var thirdPartyItem = await factory.GetThirdPartyDefinitionItem(solution, definitionItem, cancellationToken); + definitions.AddIfNotNull(thirdPartyItem); + } } definitions.Add(definitionItem); diff --git a/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb b/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb index 22acb311f0d57..61eb62295da93 100644 --- a/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb +++ b/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb @@ -31,10 +31,14 @@ Friend Class GoToHelpers If Not shouldSucceed Then Assert.NotNull(context.Message) Else - Dim actualDefinitions = context.GetDefinitions(). - SelectMany(Function(d) d.SourceSpans). - Select(Function(ss) New FilePathAndSpan(solution.GetRequiredDocument(ss.DocumentId).FilePath, ss.SourceSpan)). - ToList() + Dim actualDefinitions = New List(Of FilePathAndSpan) + + For Each definition In context.GetDefinitions() + For Each sourceSpan In definition.SourceSpans + Dim docSpan = Await sourceSpan.RehydrateAsync(solution, CancellationToken.None) + actualDefinitions.Add(New FilePathAndSpan(docSpan.Document.FilePath, docSpan.SourceSpan)) + Next + Next actualDefinitions.Sort() Dim expectedDefinitions = workspace.Documents.SelectMany( From 50dca19d288055c6af873319a07338476474f9c9 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Aug 2021 09:42:59 -0700 Subject: [PATCH 06/42] Almost done with goto def --- .../AbstractGoToSymbolService.cs | 17 ++++++----------- .../GoToDefinition/GoToDefinitionHelpers.cs | 18 +++++++++++------- ...ualStudioDefinitionsAndReferencesFactory.cs | 10 ++++------ .../VisualStudioSymbolNavigationService.cs | 1 + 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs index 07315b3d7fb31..c18aa5eaba6db 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs @@ -4,7 +4,9 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; +using Microsoft.CodeAnalysis.FindUsages; using Microsoft.CodeAnalysis.GoToDefinition; +using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.VisualStudio.Threading; @@ -35,20 +37,13 @@ public async Task GetSymbolsAsync(GoToSymbolContext context) return; } - // We want ctrl-click GTD to be as close to regular GTD as possible. - // This means we have to query for "third party navigation", from - // XAML, etc. That call has to be done on the UI thread. - await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, cancellationToken); - var solution = document.Project.Solution; - var definitions = GoToDefinitionHelpers.GetDefinitions(symbol, solution, thirdPartyNavigationAllowed: true, cancellationToken) - .WhereAsArray(d => d.CanNavigateTo(solution.Workspace, cancellationToken)); - - await TaskScheduler.Default; + var definitions = await GoToDefinitionHelpers.GetDefinitionsAsync(symbol, solution, thirdPartyNavigationAllowed: true, cancellationToken).ConfigureAwait(false); - foreach (var definition in definitions) + foreach (var def in definitions) { - context.AddItem(WellKnownSymbolTypes.Definition, definition); + if (def.CanNavigateTo(solution.Workspace, cancellationToken)) + context.AddItem(WellKnownSymbolTypes.Definition, def); } context.Span = span; diff --git a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs index 03eb0d0c761db..7f7a05f1c94f4 100644 --- a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs +++ b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs @@ -8,6 +8,7 @@ using System.Collections.Immutable; using System.Linq; using System.Threading; +using System.Threading.Tasks; using Microsoft.CodeAnalysis.Editor.FindUsages; using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; @@ -21,7 +22,7 @@ namespace Microsoft.CodeAnalysis.Editor.GoToDefinition { internal static class GoToDefinitionHelpers { - public static ImmutableArray GetDefinitions( + public static async Task> GetDefinitionsAsync( ISymbol symbol, Solution solution, bool thirdPartyNavigationAllowed, @@ -50,7 +51,7 @@ public static ImmutableArray GetDefinitions( } } - var definition = SymbolFinder.FindSourceDefinitionAsync(symbol, solution, cancellationToken).WaitAndGetResult(cancellationToken); + var definition = await SymbolFinder.FindSourceDefinitionAsync(symbol, solution, cancellationToken).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); symbol = definition ?? symbol; @@ -90,7 +91,7 @@ public static ImmutableArray GetDefinitions( var factory = solution.Workspace.Services.GetService(); if (factory != null) { - var thirdPartyItem = await factory.GetThirdPartyDefinitionItem(solution, definitionItem, cancellationToken); + var thirdPartyItem = await factory.GetThirdPartyDefinitionItemAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); definitions.AddIfNotNull(thirdPartyItem); } } @@ -107,14 +108,17 @@ public static bool TryGoToDefinition( CancellationToken cancellationToken, bool thirdPartyNavigationAllowed = true) { - var definitions = GetDefinitions(symbol, solution, thirdPartyNavigationAllowed, cancellationToken); - var title = string.Format(EditorFeaturesResources._0_declarations, FindUsagesHelpers.GetDisplayName(symbol)); return threadingContext.JoinableTaskFactory.Run( - () => streamingPresenter.TryNavigateToOrPresentItemsAsync( - threadingContext, solution, title, definitions, cancellationToken)); + async () => + { + var definitions = await GetDefinitionsAsync(symbol, solution, thirdPartyNavigationAllowed, cancellationToken).ConfigureAwait(false); + + return await streamingPresenter.TryNavigateToOrPresentItemsAsync( + threadingContext, solution, title, definitions, cancellationToken).ConfigureAwait(false); + }); } public static bool TryGoToDefinition( diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs index 02ba4d1f393cb..f586bbef8a551 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs @@ -7,6 +7,7 @@ using System.Composition; using System.Runtime.InteropServices; using System.Threading; +using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Editor.FindUsages; using Microsoft.CodeAnalysis.FindSymbols.FindReferences; @@ -33,16 +34,13 @@ internal class VisualStudioDefinitionsAndReferencesFactory public VisualStudioDefinitionsAndReferencesFactory(SVsServiceProvider serviceProvider) => _serviceProvider = serviceProvider; - public override DefinitionItem? GetThirdPartyDefinitionItem( + public override async Task GetThirdPartyDefinitionItemAsync( Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken) { var symbolNavigationService = solution.Workspace.Services.GetRequiredService(); - if (!symbolNavigationService.WouldNavigateToSymbol( - definitionItem, solution, cancellationToken, - out var filePath, out var lineNumber, out var charOffset)) - { + var result = await symbolNavigationService.WouldNavigateToSymbolAsync(definitionItem, solution, cancellationToken).ConfigureAwait(false); + if (result is not var (filePath, lineNumber, charOffset)) return null; - } var displayParts = GetDisplayParts(filePath, lineNumber, charOffset); return new ExternalDefinitionItem( diff --git a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs index 47a81801c2c02..a0098984ce776 100644 --- a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs +++ b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs @@ -200,6 +200,7 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p public async Task<(string filePath, int lineNumber, int charOffset)?> WouldNotifyToSpecificSymbolAsync( Solution solution, DefinitionItem definitionItem, string? rqName, CancellationToken cancellationToken) { + await this.ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); AssertIsForeground(); if (rqName == null) From a27dced31bc7d0f000d2b57bc20d091ae74aaa39 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Aug 2021 09:54:37 -0700 Subject: [PATCH 07/42] More async work --- ...UsagesService.DefinitionTrackingContext.cs | 2 +- .../AbstractGoToDefinitionService.cs | 21 ++++++++++++------- .../GoToDefinition/GoToDefinitionTestsBase.vb | 12 +++++------ .../MockSymbolNavigationService.vb | 4 ++-- .../MockSymbolNavigationServiceProvider.vb | 15 +++++-------- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs index 8f542a09ab505..1868225df2c96 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs @@ -17,7 +17,7 @@ internal abstract partial class AbstractFindUsagesService /// Forwards notifications to an underlying /// while also keeping track of the definitions reported. /// - /// These can then be used by to report the + /// These can then be used by to report the /// definitions found to third parties in case they want to add any additional definitions /// to the results we present. /// diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs index a5e4aaf90146f..4c2e5015a5a6a 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs @@ -11,9 +11,11 @@ using Microsoft.CodeAnalysis.Editor.FindUsages; using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; +using Microsoft.CodeAnalysis.FindUsages; using Microsoft.CodeAnalysis.GoToDefinition; using Microsoft.CodeAnalysis.LanguageServices; using Microsoft.CodeAnalysis.Navigation; +using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; using Roslyn.Utilities; @@ -112,16 +114,21 @@ private bool TryGoToAlternativeLocationIfAlreadyOnDefinition( if (interfaceImpls.Length == 0) return false; - var definitions = interfaceImpls.SelectMany( - i => GoToDefinitionHelpers.GetDefinitions( - i, solution, thirdPartyNavigationAllowed: false, cancellationToken)).ToImmutableArray(); - var title = string.Format(EditorFeaturesResources._0_implemented_members, FindUsagesHelpers.GetDisplayName(symbol)); - return _threadingContext.JoinableTaskFactory.Run(() => - _streamingPresenter.TryNavigateToOrPresentItemsAsync( - _threadingContext, solution, title, definitions, cancellationToken)); + return _threadingContext.JoinableTaskFactory.Run(async () => + { + using var _ = ArrayBuilder.GetInstance(out var definitions); + foreach (var impl in interfaceImpls) + { + foreach (var def in await GoToDefinitionHelpers.GetDefinitionsAsync(impl, solution, thirdPartyNavigationAllowed: false, cancellationToken).ConfigureAwait(false)) + definitions.Add(def); + } + + return await _streamingPresenter.TryNavigateToOrPresentItemsAsync( + _threadingContext, solution, title, definitions.ToImmutable(), cancellationToken).ConfigureAwait(false); + }); } private static bool IsThirdPartyNavigationAllowed(ISymbol symbolToNavigateTo, int caretPosition, Document document, CancellationToken cancellationToken) diff --git a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb index ea968cd1c17e7..a9bb26b18d608 100644 --- a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb +++ b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb @@ -14,10 +14,10 @@ Imports Microsoft.VisualStudio.Text Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition Public Class GoToDefinitionTestsBase - Private Shared Async Sub Test( + Private Shared Async Function Test( workspaceDefinition As XElement, expectedResult As Boolean, - executeOnDocument As Func(Of Document, Integer, IThreadingContext, IStreamingFindUsagesPresenter, Boolean)) + executeOnDocument As Func(Of Document, Integer, IThreadingContext, IStreamingFindUsagesPresenter, Boolean)) As Task Using workspace = TestWorkspace.Create(workspaceDefinition, composition:=GoToTestHelpers.Composition) Dim solution = workspace.CurrentSolution Dim cursorDocument = workspace.Documents.First(Function(d) d.CursorPosition.HasValue) @@ -110,10 +110,10 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition End If End Using - End Sub + End Function - Friend Shared Sub Test(workspaceDefinition As XElement, Optional expectedResult As Boolean = True) - Test(workspaceDefinition, expectedResult, + Friend Shared Async Function Test(workspaceDefinition As XElement, Optional expectedResult As Boolean = True) As Task + Await Test(workspaceDefinition, expectedResult, Function(document, cursorPosition, threadingContext, presenter) Dim goToDefService = If(document.Project.Language = LanguageNames.CSharp, DirectCast(New CSharpGoToDefinitionService(threadingContext, presenter), IGoToDefinitionService), @@ -121,7 +121,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition Return goToDefService.TryGoToDefinition(document, cursorPosition, CancellationToken.None) End Function) - End Sub + End Function End Class End Namespace diff --git a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb index 392863ffccfb8..321dcfdcf417d 100644 --- a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb +++ b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb @@ -26,9 +26,9 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers Return SpecializedTasks.True End Function - Public Function WouldNavigateToSymbol(definitionItem As DefinitionItem, solution As Solution, cancellationToken As CancellationToken, ByRef filePath As String, ByRef lineNumber As Integer, ByRef charOffset As Integer) As Boolean Implements ISymbolNavigationService.WouldNavigateToSymbol + Public Function WouldNavigateToSymbolAsync(definitionItem As DefinitionItem, solution As Solution, cancellationToken As CancellationToken) As Task(Of (filePath As String, lineNumber As Integer, charOffset As Integer)?) Implements ISymbolNavigationService.WouldNavigateToSymbolAsync _wouldNavigateToSymbol = True - Return True + Return Task.FromResult(Of (filePath As String, lineNumber As Integer, charOffset As Integer)?)(Nothing) End Function End Class End Namespace diff --git a/src/EditorFeatures/TestUtilities2/Utilities/MockSymbolNavigationServiceProvider.vb b/src/EditorFeatures/TestUtilities2/Utilities/MockSymbolNavigationServiceProvider.vb index 631dfb334c914..48362c32bcb6e 100644 --- a/src/EditorFeatures/TestUtilities2/Utilities/MockSymbolNavigationServiceProvider.vb +++ b/src/EditorFeatures/TestUtilities2/Utilities/MockSymbolNavigationServiceProvider.vb @@ -41,7 +41,6 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities Public WouldNavigateToSymbolProvidedDefinitionItem As DefinitionItem Public WouldNavigateToSymbolProvidedSolution As Solution - Public WouldNavigateToSymbolReturnValue As Boolean Public NavigationFilePathReturnValue As String = String.Empty Public NavigationLineNumberReturnValue As Integer Public NavigationCharOffsetReturnValue As Integer @@ -63,18 +62,14 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities Return Task.FromResult(TrySymbolNavigationNotifyReturnValue) End Function - Public Function WouldNavigateToSymbol(definitionItem As DefinitionItem, - solution As Solution, - cancellationToken As CancellationToken, - ByRef filePath As String, ByRef lineNumber As Integer, ByRef charOffset As Integer) As Boolean Implements ISymbolNavigationService.WouldNavigateToSymbol + Public Function WouldNavigateToSymbolAsync( + definitionItem As DefinitionItem, + solution As Solution, + cancellationToken As CancellationToken) As Task(Of (filePath As String, lineNumber As Integer, charOffset As Integer)?) Implements ISymbolNavigationService.WouldNavigateToSymbolAsync Me.WouldNavigateToSymbolProvidedDefinitionItem = definitionItem Me.WouldNavigateToSymbolProvidedSolution = solution - filePath = Me.NavigationFilePathReturnValue - lineNumber = Me.NavigationLineNumberReturnValue - charOffset = Me.NavigationCharOffsetReturnValue - - Return WouldNavigateToSymbolReturnValue + Return Task.FromResult(Of (filePath As String, lineNumber As Integer, charOffset As Integer)?)((Me.NavigationFilePathReturnValue, Me.NavigationLineNumberReturnValue, Me.NavigationCharOffsetReturnValue)) End Function End Class End Class From 67a04c5906c363c886eda804e78ae51149bec212 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Aug 2021 11:16:37 -0700 Subject: [PATCH 08/42] Add a TWD for find usages navigation --- .../AbstractGoToSymbolService.cs | 5 +- .../Host/IStreamingFindReferencesPresenter.cs | 24 ++++--- ...tionItem.DocumentLocationDefinitionItem.cs | 30 +++++++-- .../Portable/FindUsages/DefinitionItem.cs | 17 +++++ .../Entries/DocumentSpanEntry.cs | 5 +- .../Entries/MetadataDefinitionItemEntry.cs | 5 +- .../Entries/SimpleMessageEntry.cs | 4 +- ...encesTableControlEventProcessorProvider.cs | 64 ++++++++++++------- .../FindReferences/ISupportsNavigation.cs | 3 +- .../FindReferences/RoslynDefinitionBucket.cs | 5 +- ...alStudioDefinitionsAndReferencesFactory.cs | 14 +++- 11 files changed, 124 insertions(+), 52 deletions(-) diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs index c18aa5eaba6db..d0fdb8795a250 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs @@ -4,11 +4,8 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; -using Microsoft.CodeAnalysis.FindUsages; using Microsoft.CodeAnalysis.GoToDefinition; -using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Shared.Extensions; -using Microsoft.VisualStudio.Threading; namespace Microsoft.CodeAnalysis.Editor.GoToDefinition { @@ -42,7 +39,7 @@ public async Task GetSymbolsAsync(GoToSymbolContext context) foreach (var def in definitions) { - if (def.CanNavigateTo(solution.Workspace, cancellationToken)) + if (await def.CanNavigateToAsync(solution.Workspace, cancellationToken).ConfigureAwait(false)) context.AddItem(WellKnownSymbolTypes.Definition, def); } diff --git a/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs b/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs index d2053de3b16c1..d846dfaafa801 100644 --- a/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs +++ b/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.FindUsages; +using Microsoft.CodeAnalysis.PooledObjects; namespace Microsoft.CodeAnalysis.Editor.Host { @@ -65,12 +66,17 @@ public static async Task TryNavigateToOrPresentItemsAsync( ImmutableArray items, CancellationToken cancellationToken) { - // Can only navigate or present items on UI thread. - await threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); - var workspace = solution.Workspace; // Ignore any definitions that we can't navigate to. - var definitions = items.WhereAsArray(d => d.CanNavigateTo(workspace, cancellationToken)); + + using var _ = ArrayBuilder.GetInstance(out var definitionsBuilder); + foreach (var item in items) + { + if (await item.CanNavigateToAsync(workspace, cancellationToken).ConfigureAwait(false)) + definitionsBuilder.Add(item); + } + + var definitions = definitionsBuilder.ToImmutable(); // See if there's a third party external item we can navigate to. If so, defer // to that item and finish. @@ -80,10 +86,8 @@ public static async Task TryNavigateToOrPresentItemsAsync( // If we're directly going to a location we need to activate the preview so // that focus follows to the new cursor position. This behavior is expected // because we are only going to navigate once successfully - if (item.TryNavigateTo(workspace, showInPreviewTab: true, activateTab: true, cancellationToken)) - { + if (await item.TryNavigateToAsync(workspace, showInPreviewTab: true, activateTab: true, cancellationToken).ConfigureAwait(false)) return true; - } } var nonExternalItems = definitions.WhereAsArray(d => !d.IsExternal); @@ -98,11 +102,15 @@ public static async Task TryNavigateToOrPresentItemsAsync( // There was only one location to navigate to. Just directly go to that location. If we're directly // going to a location we need to activate the preview so that focus follows to the new cursor position. - return nonExternalItems[0].TryNavigateTo(workspace, showInPreviewTab: true, activateTab: true, cancellationToken); + return await nonExternalItems[0].TryNavigateToAsync( + workspace, showInPreviewTab: true, activateTab: true, cancellationToken).ConfigureAwait(false); } if (presenter != null) { + // Can only navigate or present items on UI thread. + await threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + // We have multiple definitions, or we have definitions with multiple locations. Present this to the // user so they can decide where they want to go to. // diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs index 1868c9086dfa9..20c9e07b23f0d 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Immutable; using System.Threading; +using System.Threading.Tasks; using Microsoft.CodeAnalysis.Navigation; using Roslyn.Utilities; @@ -37,14 +38,27 @@ public DefaultDefinitionItem( { } - private DocumentSpan? TryGetDocumentSpan(Workspace workspace) + private async Task TryGetDocumentSpanAsync(Workspace workspace, CancellationToken cancellationToken) { - var currentSolution = workspace.CurrentSolution; - var document = currentSolution.GetDocument(SourceSpans[0].DocumentId); - return document != null ? new DocumentSpan(document, SourceSpans[0].SourceSpan) : null; + var solution = workspace.CurrentSolution; + var documentId = SourceSpans[0].DocumentId; + var document = solution.GetDocument(documentId) ?? + await solution.GetSourceGeneratedDocumentAsync(documentId, cancellationToken).ConfigureAwait(false); + if (document == null) + return null; + + return new DocumentSpan(document, SourceSpans[0].SourceSpan); } + [Obsolete] public override bool CanNavigateTo(Workspace workspace, CancellationToken cancellationToken) + => throw ExceptionUtilities.Unreachable; + + [Obsolete] + public override bool TryNavigateTo(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) + => throw ExceptionUtilities.Unreachable; + + public override async Task CanNavigateToAsync(Workspace workspace, CancellationToken cancellationToken) { if (Properties.ContainsKey(NonNavigable)) return false; @@ -52,10 +66,11 @@ public override bool CanNavigateTo(Workspace workspace, CancellationToken cancel if (Properties.TryGetValue(MetadataSymbolKey, out var symbolKey)) return CanNavigateToMetadataSymbol(workspace, symbolKey); - return TryGetDocumentSpan(workspace) is DocumentSpan span && span.CanNavigateTo(cancellationToken); + return await TryGetDocumentSpanAsync(workspace, cancellationToken).ConfigureAwait(false) is DocumentSpan span && + span.CanNavigateTo(cancellationToken); } - public override bool TryNavigateTo(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) + public override async Task TryNavigateToAsync(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) { if (Properties.ContainsKey(NonNavigable)) return false; @@ -63,7 +78,8 @@ public override bool TryNavigateTo(Workspace workspace, bool showInPreviewTab, b if (Properties.TryGetValue(MetadataSymbolKey, out var symbolKey)) return TryNavigateToMetadataSymbol(workspace, symbolKey); - return TryGetDocumentSpan(workspace) is DocumentSpan span && span.TryNavigateTo(showInPreviewTab, activateTab, cancellationToken); + return await TryGetDocumentSpanAsync(workspace, cancellationToken).ConfigureAwait(false) is DocumentSpan span && + span.TryNavigateTo(showInPreviewTab, activateTab, cancellationToken); } private bool CanNavigateToMetadataSymbol(Workspace workspace, string symbolKey) diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.cs index 35100b96a54f4..8675cefb8e084 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Immutable; using System.Threading; +using System.Threading.Tasks; using Microsoft.CodeAnalysis.Tags; using Roslyn.Utilities; @@ -156,9 +157,25 @@ protected DefinitionItem( } } + [Obsolete("Override CanNavigateToAsync instead", error: false)] public abstract bool CanNavigateTo(Workspace workspace, CancellationToken cancellationToken); + [Obsolete("Override TryNavigateToAsync instead", error: false)] public abstract bool TryNavigateTo(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken); + public virtual Task CanNavigateToAsync(Workspace workspace, CancellationToken cancellationToken) + { +#pragma warning disable CS0618 // Type or member is obsolete + return Task.FromResult(CanNavigateTo(workspace, cancellationToken)); +#pragma warning restore CS0618 // Type or member is obsolete + } + + public virtual Task TryNavigateToAsync(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) + { +#pragma warning disable CS0618 // Type or member is obsolete + return Task.FromResult(TryNavigateTo(workspace, showInPreviewTab, activateTab, cancellationToken)); +#pragma warning restore CS0618 // Type or member is obsolete + } + public static DefinitionItem Create( ImmutableArray tags, ImmutableArray displayParts, diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/DocumentSpanEntry.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/DocumentSpanEntry.cs index 673d2782af7d0..3819d7bf0a4a6 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/DocumentSpanEntry.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/DocumentSpanEntry.cs @@ -7,6 +7,7 @@ using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; using System.Threading; +using System.Threading.Tasks; using System.Windows; using System.Windows.Media; using Microsoft.CodeAnalysis; @@ -24,6 +25,7 @@ using Microsoft.VisualStudio.Shell.TableControl; using Microsoft.VisualStudio.Shell.TableManager; using Microsoft.VisualStudio.Text; +using Roslyn.Utilities; namespace Microsoft.VisualStudio.LanguageServices.FindUsages { @@ -278,7 +280,7 @@ private static Span GetRegionSpanForReference(SourceText sourceText, TextSpan so sourceText.Lines[lastLineNumber].End); } - bool ISupportsNavigation.TryNavigateTo(bool isPreview, CancellationToken cancellationToken) + async Task ISupportsNavigation.TryNavigateToAsync(bool isPreview, CancellationToken cancellationToken) { // If the document is a source generated document, we need to do the navigation ourselves; // this is because the file path given to the table control isn't a real file path to a file @@ -290,6 +292,7 @@ bool ISupportsNavigation.TryNavigateTo(bool isPreview, CancellationToken cancell if (documentNavigationService != null) { + await this.Presenter.ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); return documentNavigationService.TryNavigateToSpan( workspace, _excerptResult.Document.Id, diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/MetadataDefinitionItemEntry.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/MetadataDefinitionItemEntry.cs index 7b893d6d13b5b..6895c3a9d8c6f 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/MetadataDefinitionItemEntry.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/MetadataDefinitionItemEntry.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Threading; +using System.Threading.Tasks; using System.Windows.Documents; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Editor.Shared.Extensions; @@ -33,8 +34,8 @@ public MetadataDefinitionItemEntry( return null; } - bool ISupportsNavigation.TryNavigateTo(bool isPreview, CancellationToken cancellationToken) - => DefinitionBucket.DefinitionItem.TryNavigateTo( + Task ISupportsNavigation.TryNavigateToAsync(bool isPreview, CancellationToken cancellationToken) + => DefinitionBucket.DefinitionItem.TryNavigateToAsync( Presenter._workspace, showInPreviewTab: isPreview, activateTab: !isPreview, cancellationToken); // Only activate the tab if not opening in preview protected override IList CreateLineTextInlines() diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/SimpleMessageEntry.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/SimpleMessageEntry.cs index 30d45e1feb6b8..ee68ad11f7bb6 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/SimpleMessageEntry.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/SimpleMessageEntry.cs @@ -44,8 +44,8 @@ public static Task CreateAsync( }; } - public bool TryNavigateTo(bool isPreview, CancellationToken cancellationToken) - => _navigationBucket != null && _navigationBucket.TryNavigateTo(isPreview, cancellationToken); + public async Task TryNavigateToAsync(bool isPreview, CancellationToken cancellationToken) + => _navigationBucket != null && await _navigationBucket.TryNavigateToAsync(isPreview, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/FindReferencesTableControlEventProcessorProvider.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/FindReferencesTableControlEventProcessorProvider.cs index 182db6c5dc3fb..4c1fd2ecf14b3 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/FindReferencesTableControlEventProcessorProvider.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/FindReferencesTableControlEventProcessorProvider.cs @@ -9,6 +9,9 @@ using System; using Microsoft.CodeAnalysis.Host.Mef; using System.Threading; +using Microsoft.CodeAnalysis.Editor; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Shared.TestHooks; namespace Microsoft.VisualStudio.LanguageServices.FindUsages { @@ -25,43 +28,58 @@ namespace Microsoft.VisualStudio.LanguageServices.FindUsages [Order(Before = Priority.Default)] internal class FindUsagesTableControlEventProcessorProvider : ITableControlEventProcessorProvider { + private readonly IUIThreadOperationExecutor _operationExecutor; + private readonly IAsynchronousOperationListener _listener; + [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public FindUsagesTableControlEventProcessorProvider() + public FindUsagesTableControlEventProcessorProvider( + IUIThreadOperationExecutor operationExecutor, + IAsynchronousOperationListenerProvider asyncProvider) { + _operationExecutor = operationExecutor; + _listener = asyncProvider.GetListener(FeatureAttribute.FindReferences); } - public ITableControlEventProcessor GetAssociatedEventProcessor( - IWpfTableControl tableControl) - { - return new TableControlEventProcessor(); - } + public ITableControlEventProcessor GetAssociatedEventProcessor(IWpfTableControl tableControl) + => new TableControlEventProcessor(_operationExecutor, _listener); private class TableControlEventProcessor : TableControlEventProcessorBase { + private readonly IUIThreadOperationExecutor _operationExecutor; + private readonly IAsynchronousOperationListener _listener; + + public TableControlEventProcessor(IUIThreadOperationExecutor operationExecutor, IAsynchronousOperationListener listener) + { + _operationExecutor = operationExecutor; + _listener = listener; + } + public override void PreprocessNavigate(ITableEntryHandle entry, TableEntryNavigateEventArgs e) { - if (entry.Identity is ISupportsNavigation supportsNavigation) + var supportsNavigation = entry.Identity as ISupportsNavigation ?? + (entry.TryGetValue(StreamingFindUsagesPresenter.SelfKeyName, out var item) ? item as ISupportsNavigation : null); + if (supportsNavigation == null) { - // TODO: Use a threaded-wait-dialog here so we can cancel navigation. - if (supportsNavigation.TryNavigateTo(e.IsPreview, CancellationToken.None)) - { - e.Handled = true; - return; - } + base.PreprocessNavigate(entry, e); + return; } - if (entry.TryGetValue(StreamingFindUsagesPresenter.SelfKeyName, out var item) && item is ISupportsNavigation itemSupportsNavigation) - { - // TODO: Use a threaded-wait-dialog here so we can cancel navigation. - if (itemSupportsNavigation.TryNavigateTo(e.IsPreview, CancellationToken.None)) - { - e.Handled = true; - return; - } - } + // Fire and forget + e.Handled = true; + _ = ProcessNavigateAsync(supportsNavigation, e); + } + + private async Task ProcessNavigateAsync(ISupportsNavigation supportsNavigation, TableEntryNavigateEventArgs e) + { + using var token = _listener.BeginAsyncOperation(nameof(ProcessNavigateAsync)); + using var context = _operationExecutor.BeginExecute( + ServicesVSResources.IntelliSense, + EditorFeaturesResources.Navigating, + allowCancellation: true, + showProgress: false); - base.PreprocessNavigate(entry, e); + await supportsNavigation.TryNavigateToAsync(e.IsPreview, context.UserCancellationToken).ConfigureAwait(false); } } } diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/ISupportsNavigation.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/ISupportsNavigation.cs index cc2363b5fc0b2..e447dc9745b7c 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/ISupportsNavigation.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/ISupportsNavigation.cs @@ -3,11 +3,12 @@ // See the LICENSE file in the project root for more information. using System.Threading; +using System.Threading.Tasks; namespace Microsoft.VisualStudio.LanguageServices.FindUsages { internal interface ISupportsNavigation { - bool TryNavigateTo(bool isPreview, CancellationToken cancellationToken); + Task TryNavigateToAsync(bool isPreview, CancellationToken cancellationToken); } } diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/RoslynDefinitionBucket.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/RoslynDefinitionBucket.cs index 94dc7c0350978..1f7e02bfaefae 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/RoslynDefinitionBucket.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/RoslynDefinitionBucket.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Threading; +using System.Threading.Tasks; using System.Windows; using System.Windows.Documents; using Microsoft.CodeAnalysis; @@ -62,8 +63,8 @@ public static RoslynDefinitionBucket Create( name, expandedByDefault, presenter, context, definitionItem); } - public bool TryNavigateTo(bool isPreview, CancellationToken cancellationToken) - => DefinitionItem.TryNavigateTo( + public Task TryNavigateToAsync(bool isPreview, CancellationToken cancellationToken) + => DefinitionItem.TryNavigateToAsync( _presenter._workspace, showInPreviewTab: isPreview, activateTab: !isPreview, cancellationToken); // Only activate the tab if not opening in preview public override bool TryGetValue(string key, out object? content) diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs index f586bbef8a551..cb5b9d2ff930d 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs @@ -18,6 +18,7 @@ using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.TextManager.Interop; +using Roslyn.Utilities; namespace Microsoft.VisualStudio.LanguageServices.Implementation.FindReferences { @@ -102,10 +103,19 @@ public ExternalDefinitionItem( _charOffset = charOffset; } - public override bool CanNavigateTo(Workspace workspace, CancellationToken cancellationToken) => true; + public override Task CanNavigateToAsync(Workspace workspace, CancellationToken cancellationToken) + => SpecializedTasks.True; + public override Task TryNavigateToAsync(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) + => Task.FromResult(TryOpenFile() && TryNavigateToPosition()); + + [Obsolete] + public override bool CanNavigateTo(Workspace workspace, CancellationToken cancellationToken) + => throw ExceptionUtilities.Unreachable; + + [Obsolete] public override bool TryNavigateTo(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) - => TryOpenFile() && TryNavigateToPosition(); + => throw ExceptionUtilities.Unreachable; private bool TryOpenFile() { From 7ee157d4e179c5b5d48f21e09c6461a9c46ef7e6 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Aug 2021 11:21:24 -0700 Subject: [PATCH 09/42] Move threading switches --- .../AbstractFindUsagesService_FindReferences.cs | 2 +- .../Workspace/VisualStudioSymbolNavigationService.cs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs index 3e34241d0c43d..e7290a5cb0577 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs @@ -86,7 +86,7 @@ private static async Task> GetThirdPartyDefinitio foreach (var definition in definitions) { - var thirdParty = await factory.GetThirdPartyDefinitionItemAsync(solution, definition, cancellationToken).ConfigureAwait(true); + var thirdParty = await factory.GetThirdPartyDefinitionItemAsync(solution, definition, cancellationToken).ConfigureAwait(false); result.AddIfNotNull(thirdParty); } diff --git a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs index a0098984ce776..84941ac1a1274 100644 --- a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs +++ b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs @@ -200,9 +200,6 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p public async Task<(string filePath, int lineNumber, int charOffset)?> WouldNotifyToSpecificSymbolAsync( Solution solution, DefinitionItem definitionItem, string? rqName, CancellationToken cancellationToken) { - await this.ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); - AssertIsForeground(); - if (rqName == null) return null; @@ -213,6 +210,8 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p var navigateToTextSpan = new Microsoft.VisualStudio.TextManager.Interop.TextSpan[1]; + await this.ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + var queryNavigateStatusCode = navigationNotify.QueryNavigateToSymbol( hierarchy, itemID, @@ -238,8 +237,6 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p string? rqName, CancellationToken cancellationToken) { - AssertIsForeground(); - if (rqName == null) return null; @@ -250,7 +247,7 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p using var _ = ArrayBuilder.GetInstance(out var documentsBuilder); foreach (var loc in sourceLocations) { - var docSpan = await loc.RehydrateAsync(solution, cancellationToken).ConfigureAwait(true); + var docSpan = await loc.RehydrateAsync(solution, cancellationToken).ConfigureAwait(false); documentsBuilder.AddIfNotNull(docSpan.Document); } @@ -263,6 +260,9 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p var generatedDocuments = documents.WhereAsArray(d => d.IsGeneratedCode(cancellationToken)); var documentToUse = generatedDocuments.FirstOrDefault() ?? documents.First(); + + await this.ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + if (!TryGetVsHierarchyAndItemId(documentToUse, out var hierarchy, out var itemID)) return null; From 0e3d7683065e883bb7c366faa31d88c12219af66 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Aug 2021 11:23:47 -0700 Subject: [PATCH 10/42] Use conditional --- .../DefinitionItem.DocumentLocationDefinitionItem.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs index 20c9e07b23f0d..1edc60ae3f588 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs @@ -44,10 +44,7 @@ public DefaultDefinitionItem( var documentId = SourceSpans[0].DocumentId; var document = solution.GetDocument(documentId) ?? await solution.GetSourceGeneratedDocumentAsync(documentId, cancellationToken).ConfigureAwait(false); - if (document == null) - return null; - - return new DocumentSpan(document, SourceSpans[0].SourceSpan); + return document == null ? null : new DocumentSpan(document, SourceSpans[0].SourceSpan); } [Obsolete] From 6295006a764da2a24bd5f9a7f782c7845beab2eb Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Aug 2021 11:34:54 -0700 Subject: [PATCH 11/42] can do CA9false) --- .../Workspace/VisualStudioSymbolNavigationService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs index 84941ac1a1274..a2e1cef8fb8f6 100644 --- a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs +++ b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs @@ -204,7 +204,7 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p return null; var values = await TryGetNavigationAPIRequiredArgumentsAsync( - solution, definitionItem, rqName, cancellationToken).ConfigureAwait(true); + solution, definitionItem, rqName, cancellationToken).ConfigureAwait(false); if (values is not var (hierarchy, itemID, navigationNotify)) return null; From b14d9d302ed62ef262dde734cd0ba0423e52b6d1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Aug 2021 11:41:00 -0700 Subject: [PATCH 12/42] Fix tests --- .../CSharpGoToDefinitionTests.vb | 792 +++++++++--------- .../VisualBasicGoToDefinitionTests.vb | 415 +++++---- 2 files changed, 603 insertions(+), 604 deletions(-) diff --git a/src/EditorFeatures/Test2/GoToDefinition/CSharpGoToDefinitionTests.vb b/src/EditorFeatures/Test2/GoToDefinition/CSharpGoToDefinitionTests.vb index 88d4a4bc661e5..d84cf8c4e3c97 100644 --- a/src/EditorFeatures/Test2/GoToDefinition/CSharpGoToDefinitionTests.vb +++ b/src/EditorFeatures/Test2/GoToDefinition/CSharpGoToDefinitionTests.vb @@ -9,7 +9,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition #Region "P2P Tests" - Public Sub TestP2PClassReference() + Public Async Function TestP2PClassReference() As Task Dim workspace = @@ -33,15 +33,15 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition - Test(workspace) - End Sub + Await Test(workspace) + End Function #End Region #Region "Normal CSharp Tests" - Public Sub TestCSharpGoToDefinition() + Public Async Function TestCSharpGoToDefinition() As Task Dim workspace = @@ -52,12 +52,12 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpLiteralGoToDefinition() + Public Async Function TestCSharpLiteralGoToDefinition() As Task Dim workspace = @@ -67,12 +67,12 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpStringLiteralGoToDefinition() + Public Async Function TestCSharpStringLiteralGoToDefinition() As Task Dim workspace = @@ -82,12 +82,12 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToDefinitionOnAnonymousMember() + Public Async Function TestCSharpGoToDefinitionOnAnonymousMember() As Task Dim workspace = @@ -111,11 +111,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToDefinitionSameClass() + Public Async Function TestCSharpGoToDefinitionSameClass() As Task Dim workspace = @@ -125,11 +125,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToDefinitionNestedClass() + Public Async Function TestCSharpGoToDefinitionNestedClass() As Task Dim workspace = @@ -146,11 +146,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionDifferentFiles() + Public Async Function TestCSharpGotoDefinitionDifferentFiles() As Task Dim workspace = @@ -166,11 +166,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionPartialClasses() + Public Async Function TestCSharpGotoDefinitionPartialClasses() As Task Dim workspace = @@ -189,11 +189,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionMethod() + Public Async Function TestCSharpGotoDefinitionMethod() As Task Dim workspace = @@ -212,12 +212,12 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionPartialMethod() + Public Async Function TestCSharpGotoDefinitionPartialMethod() As Task Dim workspace = @@ -245,11 +245,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionExtendedPartialMethod() + Public Async Function TestCSharpGotoDefinitionExtendedPartialMethod() As Task Dim workspace = @@ -277,11 +277,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionOnMethodCall1() + Public Async Function TestCSharpGotoDefinitionOnMethodCall1() As Task Dim workspace = @@ -302,11 +302,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionOnMethodCall2() + Public Async Function TestCSharpGotoDefinitionOnMethodCall2() As Task Dim workspace = @@ -327,11 +327,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionOnMethodCall3() + Public Async Function TestCSharpGotoDefinitionOnMethodCall3() As Task Dim workspace = @@ -352,11 +352,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionOnMethodCall4() + Public Async Function TestCSharpGotoDefinitionOnMethodCall4() As Task Dim workspace = @@ -377,11 +377,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionOnConstructor1() + Public Async Function TestCSharpGotoDefinitionOnConstructor1() As Task Dim workspace = @@ -397,12 +397,12 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionOnConstructor2() + Public Async Function TestCSharpGotoDefinitionOnConstructor2() As Task Dim workspace = @@ -418,11 +418,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionWithoutExplicitConstruct() + Public Async Function TestCSharpGotoDefinitionWithoutExplicitConstruct() As Task Dim workspace = @@ -438,11 +438,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionOnLocalVariable1() + Public Async Function TestCSharpGotoDefinitionOnLocalVariable1() As Task Dim workspace = @@ -459,11 +459,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionOnLocalVariable2() + Public Async Function TestCSharpGotoDefinitionOnLocalVariable2() As Task Dim workspace = @@ -480,11 +480,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionOnLocalField() + Public Async Function TestCSharpGotoDefinitionOnLocalField() As Task Dim workspace = @@ -501,11 +501,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionOnAttributeClass() + Public Async Function TestCSharpGotoDefinitionOnAttributeClass() As Task Dim workspace = @@ -519,11 +519,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionTouchLeft() + Public Async Function TestCSharpGotoDefinitionTouchLeft() As Task Dim workspace = @@ -536,11 +536,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionTouchRight() + Public Async Function TestCSharpGotoDefinitionTouchRight() As Task Dim workspace = @@ -553,11 +553,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionOnGenericTypeParameterInPresenceOfInheritedNestedTypeWithSameName() + Public Async Function TestCSharpGotoDefinitionOnGenericTypeParameterInPresenceOfInheritedNestedTypeWithSameName() As Task Dim workspace = @@ -574,12 +574,12 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionThroughOddlyNamedType() + Public Async Function TestCSharpGotoDefinitionThroughOddlyNamedType() As Task Dim workspace = @@ -590,11 +590,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToDefinitionOnConstructorInitializer1() + Public Async Function TestCSharpGoToDefinitionOnConstructorInitializer1() As Task Dim workspace = @@ -619,11 +619,11 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToDefinitionOnExtensionMethod() + Public Async Function TestCSharpGoToDefinitionOnExtensionMethod() As Task Dim workspace = @@ -645,12 +645,12 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpTestLambdaParameter() + Public Async Function TestCSharpTestLambdaParameter() As Task Dim workspace = @@ -667,11 +667,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpTestLabel() + Public Async Function TestCSharpTestLabel() As Task Dim workspace = @@ -689,11 +689,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToDefinitionFromCref() + Public Async Function TestCSharpGoToDefinitionFromCref() As Task Dim workspace = @@ -706,12 +706,12 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOverriddenDefinition_FromDeconstructionDeclaration() + Public Async Function TestCSharpGoToOverriddenDefinition_FromDeconstructionDeclaration() As Task Dim workspace = @@ -729,12 +729,12 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOverriddenDefinition_FromDeconstructionAssignment() + Public Async Function TestCSharpGoToOverriddenDefinition_FromDeconstructionAssignment() As Task Dim workspace = @@ -753,12 +753,12 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOverriddenDefinition_FromDeconstructionForeach() + Public Async Function TestCSharpGoToOverriddenDefinition_FromDeconstructionForeach() As Task Dim workspace = @@ -776,11 +776,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOverriddenDefinition_FromOverride() + Public Async Function TestCSharpGoToOverriddenDefinition_FromOverride() As Task Dim workspace = @@ -793,11 +793,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOverriddenDefinition_FromOverride2() + Public Async Function TestCSharpGoToOverriddenDefinition_FromOverride2() As Task Dim workspace = @@ -808,11 +808,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOverriddenProperty_FromOverride() + Public Async Function TestCSharpGoToOverriddenProperty_FromOverride() As Task Dim workspace = @@ -823,11 +823,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToUnmanaged_Keyword() + Public Async Function TestCSharpGoToUnmanaged_Keyword() As Task Dim workspace = @@ -839,11 +839,11 @@ class C - Test(workspace, expectedResult:=False) - End Sub + Await Test(workspace, expectedResult:=False) + End Function - Public Sub TestCSharpGoToUnmanaged_Type() + Public Async Function TestCSharpGoToUnmanaged_Type() As Task Dim workspace = @@ -858,12 +858,12 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToImplementedInterfaceMemberFromImpl1() + Public Async Function TestCSharpGoToImplementedInterfaceMemberFromImpl1() As Task Dim workspace = @@ -881,12 +881,12 @@ class Foo : IFoo1 - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToImplementedInterfaceMemberFromImpl2() + Public Async Function TestCSharpGoToImplementedInterfaceMemberFromImpl2() As Task Dim workspace = @@ -904,12 +904,12 @@ class Foo : IFoo1 - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToImplementedInterfaceMemberFromImpl3() + Public Async Function TestCSharpGoToImplementedInterfaceMemberFromImpl3() As Task Dim workspace = @@ -928,12 +928,12 @@ class Foo : IFoo1, IFoo2 - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToDefinitionInVarPatterns() + Public Async Function TestCSharpGoToDefinitionInVarPatterns() As Task Dim workspace = @@ -955,8 +955,8 @@ class D - Test(workspace) - End Sub + Await Test(workspace) + End Function #End Region #Region "CSharp TupleTests" @@ -985,7 +985,7 @@ namespace System ]]> - Public Sub TestCSharpGotoDefinitionTupleFieldEqualTuples01() + Public Async Function TestCSharpGotoDefinitionTupleFieldEqualTuples01() As Task Dim workspace = @@ -1008,11 +1008,11 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionTupleFieldEqualTuples02() + Public Async Function TestCSharpGotoDefinitionTupleFieldEqualTuples02() As Task Dim workspace = @@ -1034,11 +1034,11 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionTupleFieldMatchToOuter01() + Public Async Function TestCSharpGotoDefinitionTupleFieldMatchToOuter01() As Task Dim workspace = @@ -1058,11 +1058,11 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionTupleFieldMatchToOuter02() + Public Async Function TestCSharpGotoDefinitionTupleFieldMatchToOuter02() As Task Dim workspace = @@ -1082,11 +1082,11 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionTupleFieldMatchToOuter03() + Public Async Function TestCSharpGotoDefinitionTupleFieldMatchToOuter03() As Task Dim workspace = @@ -1106,11 +1106,11 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionTupleFieldRedeclared01() + Public Async Function TestCSharpGotoDefinitionTupleFieldRedeclared01() As Task Dim workspace = @@ -1130,11 +1130,11 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionTupleFieldRedeclared02() + Public Async Function TestCSharpGotoDefinitionTupleFieldRedeclared02() As Task Dim workspace = @@ -1154,11 +1154,11 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionTupleFieldItem01() + Public Async Function TestCSharpGotoDefinitionTupleFieldItem01() As Task Dim workspace = @@ -1178,11 +1178,11 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionTupleFieldItem02() + Public Async Function TestCSharpGotoDefinitionTupleFieldItem02() As Task Dim workspace = @@ -1202,11 +1202,11 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGotoDefinitionTupleFieldItem03() + Public Async Function TestCSharpGotoDefinitionTupleFieldItem03() As Task Dim workspace = @@ -1226,14 +1226,14 @@ namespace System - Test(workspace, expectedResult:=False) - End Sub + Await Test(workspace, expectedResult:=False) + End Function #End Region #Region "CSharp Venus Tests" - Public Sub TestCSharpVenusGotoDefinition() + Public Async Function TestCSharpVenusGotoDefinition() As Task Dim workspace = @@ -1249,12 +1249,12 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpFilterGotoDefResultsFromHiddenCodeForUIPresenters() + Public Async Function TestCSharpFilterGotoDefResultsFromHiddenCodeForUIPresenters() As Task Dim workspace = @@ -1270,12 +1270,12 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpDoNotFilterGotoDefResultsFromHiddenCodeForApis() + Public Async Function TestCSharpDoNotFilterGotoDefResultsFromHiddenCodeForApis() As Task Dim workspace = @@ -1291,15 +1291,15 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function #End Region #Region "CSharp Script Tests" - Public Sub TestCSharpScriptGoToDefinition() + Public Async Function TestCSharpScriptGoToDefinition() As Task Dim workspace = @@ -1311,11 +1311,11 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpScriptGoToDefinitionSameClass() + Public Async Function TestCSharpScriptGoToDefinitionSameClass() As Task Dim workspace = @@ -1326,11 +1326,11 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpScriptGoToDefinitionNestedClass() + Public Async Function TestCSharpScriptGoToDefinitionNestedClass() As Task Dim workspace = @@ -1348,11 +1348,11 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpScriptGotoDefinitionDifferentFiles() + Public Async Function TestCSharpScriptGotoDefinitionDifferentFiles() As Task Dim workspace = @@ -1371,11 +1371,11 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpScriptGotoDefinitionPartialClasses() + Public Async Function TestCSharpScriptGotoDefinitionPartialClasses() As Task Dim workspace = @@ -1398,11 +1398,11 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpScriptGotoDefinitionMethod() + Public Async Function TestCSharpScriptGotoDefinitionMethod() As Task Dim workspace = @@ -1423,11 +1423,11 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpScriptGotoDefinitionOnMethodCall1() + Public Async Function TestCSharpScriptGotoDefinitionOnMethodCall1() As Task Dim workspace = @@ -1449,11 +1449,11 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpScriptGotoDefinitionOnMethodCall2() + Public Async Function TestCSharpScriptGotoDefinitionOnMethodCall2() As Task Dim workspace = @@ -1475,10 +1475,10 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpScriptGotoDefinitionOnMethodCall3() + Public Async Function TestCSharpScriptGotoDefinitionOnMethodCall3() As Task Dim workspace = @@ -1500,11 +1500,11 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpScriptGotoDefinitionOnMethodCall4() + Public Async Function TestCSharpScriptGotoDefinitionOnMethodCall4() As Task Dim workspace = @@ -1526,12 +1526,12 @@ namespace System - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpDoNotFilterGeneratedSourceLocations() + Public Async Function TestCSharpDoNotFilterGeneratedSourceLocations() As Task Dim workspace = @@ -1551,12 +1551,12 @@ partial class [|C|] - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpUseGeneratedSourceLocationsIfNoNongeneratedLocationsAvailable() + Public Async Function TestCSharpUseGeneratedSourceLocationsIfNoNongeneratedLocationsAvailable() As Task Dim workspace = @@ -1576,14 +1576,14 @@ class D - Test(workspace) - End Sub + Await Test(workspace) + End Function #End Region - Public Sub TestCSharpTestAliasAndTarget1() + Public Async Function TestCSharpTestAliasAndTarget1() As Task Dim workspace = @@ -1607,12 +1607,12 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpTestAliasAndTarget2() + Public Async Function TestCSharpTestAliasAndTarget2() As Task Dim workspace = @@ -1636,12 +1636,12 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpTestAliasAndTarget3() + Public Async Function TestCSharpTestAliasAndTarget3() As Task Dim workspace = @@ -1665,12 +1665,12 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpTestAliasAndTarget4() + Public Async Function TestCSharpTestAliasAndTarget4() As Task Dim workspace = @@ -1694,13 +1694,13 @@ class Program - Test(workspace) - End Sub + Await Test(workspace) + End Function #Region "Show notification tests" - Public Sub TestShowNotificationCS() + Public Async Function TestShowNotificationCS() As Task Dim workspace = @@ -1714,12 +1714,12 @@ class Program - Test(workspace, expectedResult:=False) - End Sub + Await Test(workspace, expectedResult:=False) + End Function - Public Sub TestGoToDefinitionOnGlobalKeyword() + Public Async Function TestGoToDefinitionOnGlobalKeyword() As Task Dim workspace = @@ -1732,8 +1732,8 @@ class Program - Test(workspace, expectedResult:=False) - End Sub + Await Test(workspace, expectedResult:=False) + End Function #End Region #Region "CSharp Query expressions Tests" @@ -1798,7 +1798,7 @@ namespace QueryPattern - Public Sub TestQuerySelect() + Public Async Function TestQuerySelect() As Task Dim workspace = @@ -1824,12 +1824,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryWhere() + Public Async Function TestQueryWhere() As Task Dim workspace = @@ -1856,12 +1856,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQuerySelectMany1() + Public Async Function TestQuerySelectMany1() As Task Dim workspace = @@ -1888,12 +1888,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQuerySelectMany2() + Public Async Function TestQuerySelectMany2() As Task Dim workspace = @@ -1920,12 +1920,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryJoin1() + Public Async Function TestQueryJoin1() As Task Dim workspace = @@ -1952,12 +1952,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryJoin2() + Public Async Function TestQueryJoin2() As Task Dim workspace = @@ -1984,12 +1984,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryJoin3() + Public Async Function TestQueryJoin3() As Task Dim workspace = @@ -2016,12 +2016,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryJoin4() + Public Async Function TestQueryJoin4() As Task Dim workspace = @@ -2048,12 +2048,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryGroupJoin1() + Public Async Function TestQueryGroupJoin1() As Task Dim workspace = @@ -2080,12 +2080,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryGroupJoin2() + Public Async Function TestQueryGroupJoin2() As Task Dim workspace = @@ -2112,12 +2112,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryGroupJoin3() + Public Async Function TestQueryGroupJoin3() As Task Dim workspace = @@ -2144,12 +2144,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryGroupJoin4() + Public Async Function TestQueryGroupJoin4() As Task Dim workspace = @@ -2176,12 +2176,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryGroupBy1() + Public Async Function TestQueryGroupBy1() As Task Dim workspace = @@ -2207,12 +2207,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryGroupBy2() + Public Async Function TestQueryGroupBy2() As Task Dim workspace = @@ -2238,12 +2238,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryFromCast1() + Public Async Function TestQueryFromCast1() As Task Dim workspace = @@ -2269,12 +2269,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryFromCast2() + Public Async Function TestQueryFromCast2() As Task Dim workspace = @@ -2300,12 +2300,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryJoinCast1() + Public Async Function TestQueryJoinCast1() As Task Dim workspace = @@ -2332,12 +2332,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryJoinCast2() + Public Async Function TestQueryJoinCast2() As Task Dim workspace = @@ -2364,12 +2364,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQuerySelectManyCast1() + Public Async Function TestQuerySelectManyCast1() As Task Dim workspace = @@ -2396,12 +2396,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQuerySelectManyCast2() + Public Async Function TestQuerySelectManyCast2() As Task Dim workspace = @@ -2428,12 +2428,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryOrderBySingleParameter() + Public Async Function TestQueryOrderBySingleParameter() As Task Dim workspace = @@ -2460,12 +2460,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryOrderBySingleParameterWithOrderClause() + Public Async Function TestQueryOrderBySingleParameterWithOrderClause() As Task Dim workspace = @@ -2492,12 +2492,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryOrderByTwoParameterWithoutOrderClause() + Public Async Function TestQueryOrderByTwoParameterWithoutOrderClause() As Task Dim workspace = @@ -2524,12 +2524,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryOrderByTwoParameterWithOrderClause() + Public Async Function TestQueryOrderByTwoParameterWithOrderClause() As Task Dim workspace = @@ -2556,12 +2556,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestQueryDegeneratedSelect() + Public Async Function TestQueryDegeneratedSelect() As Task Dim workspace = @@ -2588,12 +2588,12 @@ class Test - Test(workspace, False) - End Sub + Await Test(workspace, False) + End Function - Public Sub TestQueryLet() + Public Async Function TestQueryLet() As Task Dim workspace = @@ -2620,12 +2620,12 @@ class Test - Test(workspace) - End Sub + Await Test(workspace) + End Function #End Region - Public Sub TestCSharpGoToOnBreakInSwitchStatement() + Public Async Function TestCSharpGoToOnBreakInSwitchStatement() As Task Dim workspace = @@ -2647,11 +2647,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnContinueInSwitchStatement() + Public Async Function TestCSharpGoToOnContinueInSwitchStatement() As Task Dim workspace = @@ -2673,11 +2673,11 @@ class C - Test(workspace, expectedResult:=False) - End Sub + Await Test(workspace, expectedResult:=False) + End Function - Public Sub TestCSharpGoToOnBreakInDoStatement() + Public Async Function TestCSharpGoToOnBreakInDoStatement() As Task Dim workspace = @@ -2697,11 +2697,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnContinueInDoStatement() + Public Async Function TestCSharpGoToOnContinueInDoStatement() As Task Dim workspace = @@ -2721,11 +2721,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnBreakInForStatement() + Public Async Function TestCSharpGoToOnBreakInForStatement() As Task Dim workspace = @@ -2744,11 +2744,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnContinueInForStatement() + Public Async Function TestCSharpGoToOnContinueInForStatement() As Task Dim workspace = @@ -2767,11 +2767,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnBreakInForeachStatement() + Public Async Function TestCSharpGoToOnBreakInForeachStatement() As Task Dim workspace = @@ -2790,11 +2790,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnContinueInForeachStatement() + Public Async Function TestCSharpGoToOnContinueInForeachStatement() As Task Dim workspace = @@ -2813,11 +2813,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnBreakInForeachVariableStatement() + Public Async Function TestCSharpGoToOnBreakInForeachVariableStatement() As Task Dim workspace = @@ -2836,11 +2836,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnContinueInForeachVariableStatement() + Public Async Function TestCSharpGoToOnContinueInForeachVariableStatement() As Task Dim workspace = @@ -2859,11 +2859,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnContinueInSwitchInForeach() + Public Async Function TestCSharpGoToOnContinueInSwitchInForeach() As Task Dim workspace = @@ -2886,11 +2886,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnTopLevelContinue() + Public Async Function TestCSharpGoToOnTopLevelContinue() As Task Dim workspace = @@ -2900,11 +2900,11 @@ cont$$inue; - Test(workspace, expectedResult:=False) - End Sub + Await Test(workspace, expectedResult:=False) + End Function - Public Sub TestCSharpGoToOnBreakInParenthesizedLambda() + Public Async Function TestCSharpGoToOnBreakInParenthesizedLambda() As Task Dim workspace = @@ -2927,11 +2927,11 @@ class C - Test(workspace, expectedResult:=False) - End Sub + Await Test(workspace, expectedResult:=False) + End Function - Public Sub TestCSharpGoToOnBreakInSimpleLambda() + Public Async Function TestCSharpGoToOnBreakInSimpleLambda() As Task Dim workspace = @@ -2954,11 +2954,11 @@ class C - Test(workspace, expectedResult:=False) - End Sub + Await Test(workspace, expectedResult:=False) + End Function - Public Sub TestCSharpGoToOnBreakInLocalFunction() + Public Async Function TestCSharpGoToOnBreakInLocalFunction() As Task Dim workspace = @@ -2984,11 +2984,11 @@ class C - Test(workspace, expectedResult:=False) - End Sub + Await Test(workspace, expectedResult:=False) + End Function - Public Sub TestCSharpGoToOnBreakInMethod() + Public Async Function TestCSharpGoToOnBreakInMethod() As Task Dim workspace = @@ -3004,11 +3004,11 @@ class C - Test(workspace, expectedResult:=False) - End Sub + Await Test(workspace, expectedResult:=False) + End Function - Public Sub TestCSharpGoToOnBreakInAccessor() + Public Async Function TestCSharpGoToOnBreakInAccessor() As Task Dim workspace = @@ -3024,11 +3024,11 @@ class C - Test(workspace, expectedResult:=False) - End Sub + Await Test(workspace, expectedResult:=False) + End Function - Public Sub TestCSharpGoToOnReturnInVoidMethod() + Public Async Function TestCSharpGoToOnReturnInVoidMethod() As Task Dim workspace = @@ -3047,11 +3047,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnReturnInIntMethod() + Public Async Function TestCSharpGoToOnReturnInIntMethod() As Task Dim workspace = @@ -3071,11 +3071,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnReturnInVoidLambda() + Public Async Function TestCSharpGoToOnReturnInVoidLambda() As Task Dim workspace = @@ -3097,11 +3097,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnReturnedExpression() + Public Async Function TestCSharpGoToOnReturnedExpression() As Task Dim workspace = @@ -3120,11 +3120,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnReturnedConstantExpression() + Public Async Function TestCSharpGoToOnReturnedConstantExpression() As Task Dim workspace = @@ -3143,11 +3143,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnYieldReturn_Return() + Public Async Function TestCSharpGoToOnYieldReturn_Return() As Task Dim workspace = @@ -3163,11 +3163,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnYieldReturn_Yield() + Public Async Function TestCSharpGoToOnYieldReturn_Yield() As Task Dim workspace = @@ -3183,11 +3183,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnYieldReturn_Yield_Partial() + Public Async Function TestCSharpGoToOnYieldReturn_Yield_Partial() As Task Dim workspace = @@ -3205,11 +3205,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnYieldReturn_Yield_Partial_ReverseOrder() + Public Async Function TestCSharpGoToOnYieldReturn_Yield_Partial_ReverseOrder() As Task Dim workspace = @@ -3227,11 +3227,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnYieldBreak_Yield() + Public Async Function TestCSharpGoToOnYieldBreak_Yield() As Task Dim workspace = @@ -3247,11 +3247,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCSharpGoToOnYieldBreak_Break() + Public Async Function TestCSharpGoToOnYieldBreak_Break() As Task Dim workspace = @@ -3267,11 +3267,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub ExtendedPropertyPattern_FirstPart() + Public Async Function ExtendedPropertyPattern_FirstPart() As Task Dim workspace = @@ -3290,11 +3290,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub ExtendedPropertyPattern_SecondPart() + Public Async Function ExtendedPropertyPattern_SecondPart() As Task Dim workspace = @@ -3313,11 +3313,11 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TopLevelStatements_EmptySpace() + Public Async Function TopLevelStatements_EmptySpace() As Task Dim workspace = @@ -3331,7 +3331,7 @@ $$ - Test(workspace, expectedResult:=False) - End Sub + Await Test(workspace, expectedResult:=False) + End Function End Class End Namespace diff --git a/src/EditorFeatures/Test2/GoToDefinition/VisualBasicGoToDefinitionTests.vb b/src/EditorFeatures/Test2/GoToDefinition/VisualBasicGoToDefinitionTests.vb index aab33b5a34ef7..2a5818ee3ccf8 100644 --- a/src/EditorFeatures/Test2/GoToDefinition/VisualBasicGoToDefinitionTests.vb +++ b/src/EditorFeatures/Test2/GoToDefinition/VisualBasicGoToDefinitionTests.vb @@ -10,7 +10,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition - Public Sub TestVisualBasicGoToDefinitionOnAnonymousMember() + Public Async Function TestVisualBasicGoToDefinitionOnAnonymousMember() As Task Dim workspace = @@ -29,11 +29,11 @@ end class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToDefinition() + Public Async Function TestVisualBasicGoToDefinition() As Task Dim workspace = @@ -47,12 +47,12 @@ end class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicLiteralGoToDefinition() + Public Async Function TestVisualBasicLiteralGoToDefinition() As Task Dim workspace = @@ -62,12 +62,12 @@ end class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicStringLiteralGoToDefinition() + Public Async Function TestVisualBasicStringLiteralGoToDefinition() As Task Dim workspace = @@ -77,12 +77,12 @@ end class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicPropertyBackingField() + Public Async Function TestVisualBasicPropertyBackingField() As Task Dim workspace = @@ -97,11 +97,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToDefinitionSameClass() + Public Async Function TestVisualBasicGoToDefinitionSameClass() As Task Dim workspace = @@ -113,11 +113,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToDefinitionNestedClass() + Public Async Function TestVisualBasicGoToDefinitionNestedClass() As Task Dim workspace = @@ -131,11 +131,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGotoDefinitionDifferentFiles() + Public Async Function TestVisualBasicGotoDefinitionDifferentFiles() As Task Dim workspace = @@ -156,11 +156,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGotoDefinitionPartialClasses() + Public Async Function TestVisualBasicGotoDefinitionPartialClasses() As Task Dim workspace = @@ -186,11 +186,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGotoDefinitionMethod() + Public Async Function TestVisualBasicGotoDefinitionMethod() As Task Dim workspace = @@ -209,12 +209,12 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGotoDefinitionPartialMethod() + Public Async Function TestVisualBasicGotoDefinitionPartialMethod() As Task Dim workspace = @@ -239,11 +239,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicTouchLeft() + Public Async Function TestVisualBasicTouchLeft() As Task Dim workspace = @@ -262,11 +262,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicTouchRight() + Public Async Function TestVisualBasicTouchRight() As Task Dim workspace = @@ -285,12 +285,12 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicMe() + Public Async Function TestVisualBasicMe() As Task Dim workspace = @@ -319,12 +319,12 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicMyClass() + Public Async Function TestVisualBasicMyClass() As Task Dim workspace = @@ -353,12 +353,12 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicMyBase() + Public Async Function TestVisualBasicMyBase() As Task Dim workspace = @@ -387,11 +387,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOverridenSubDefinition() + Public Async Function TestVisualBasicGoToOverridenSubDefinition() As Task Dim workspace = @@ -410,11 +410,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOverridenFunctionDefinition() + Public Async Function TestVisualBasicGoToOverridenFunctionDefinition() As Task Dim workspace = @@ -435,11 +435,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOverridenPropertyDefinition() + Public Async Function TestVisualBasicGoToOverridenPropertyDefinition() As Task Dim workspace = @@ -456,14 +456,14 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function #End Region #Region "Venus Visual Basic Tests" - Public Sub TestVisualBasicVenusGotoDefinition() + Public Async Function TestVisualBasicVenusGotoDefinition() As Task Dim workspace = @@ -479,12 +479,12 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicFilterGotoDefResultsFromHiddenCodeForUIPresenters() + Public Async Function TestVisualBasicFilterGotoDefResultsFromHiddenCodeForUIPresenters() As Task Dim workspace = @@ -500,12 +500,12 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicDoNotFilterGotoDefResultsFromHiddenCodeForApis() + Public Async Function TestVisualBasicDoNotFilterGotoDefResultsFromHiddenCodeForApis() As Task Dim workspace = @@ -521,12 +521,12 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function #End Region - Public Sub TestVisualBasicTestThroughExecuteCommand() + Public Async Function TestVisualBasicTestThroughExecuteCommand() As Task Dim workspace = @@ -545,11 +545,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToDefinitionOnExtensionMethod() + Public Async Function TestVisualBasicGoToDefinitionOnExtensionMethod() As Task Dim workspace = @@ -574,12 +574,12 @@ End Module]]>] - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicQueryRangeVariable() + Public Async Function TestVisualBasicQueryRangeVariable() As Task Dim workspace = @@ -598,12 +598,12 @@ End Module - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGotoConstant() + Public Async Function TestVisualBasicGotoConstant() As Task Dim workspace = @@ -618,13 +618,13 @@ End Module - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCrossLanguageParameterizedPropertyOverride() + Public Async Function TestCrossLanguageParameterizedPropertyOverride() As Task Dim workspace = @@ -651,12 +651,12 @@ class B : A - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestCrossLanguageNavigationToVBModuleMember() + Public Async Function TestCrossLanguageNavigationToVBModuleMember() As Task Dim workspace = @@ -681,13 +681,13 @@ class C - Test(workspace) - End Sub + Await Test(workspace) + End Function #Region "Show notification tests" - Public Sub TestShowNotificationVB() + Public Async Function TestShowNotificationVB() As Task Dim workspace = @@ -701,12 +701,12 @@ class C - Test(workspace, expectedResult:=False) - End Sub + Await Test(workspace, expectedResult:=False) + End Function - Public Sub TestGoToDefinitionOnInferredFieldInitializer() + Public Async Function TestGoToDefinitionOnInferredFieldInitializer() As Task Dim workspace = @@ -728,12 +728,12 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestGoToDefinitionGlobalImportAlias() + Public Async Function TestGoToDefinitionGlobalImportAlias() As Task Dim workspace = @@ -760,12 +760,12 @@ End Namespace - Test(workspace) - End Sub + Await Test(workspace) + End Function #End Region - Public Sub TestVisualBasicGoToOnExitSelect_Exit() + Public Async Function TestVisualBasicGoToOnExitSelect_Exit() As Task Dim workspace = @@ -782,11 +782,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnExitSelect_Select() + Public Async Function TestVisualBasicGoToOnExitSelect_Select() As Task Dim workspace = @@ -803,11 +803,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnExitSub() + Public Async Function TestVisualBasicGoToOnExitSub() As Task Dim workspace = @@ -821,11 +821,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnExitFunction() + Public Async Function TestVisualBasicGoToOnExitFunction() As Task Dim workspace = @@ -839,11 +839,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnContinueWhile_Continue() + Public Async Function TestVisualBasicGoToOnContinueWhile_Continue() As Task Dim workspace = @@ -859,11 +859,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnContinueWhile_While() + Public Async Function TestVisualBasicGoToOnContinueWhile_While() As Task Dim workspace = @@ -879,11 +879,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnExitWhile_While() + Public Async Function TestVisualBasicGoToOnExitWhile_While() As Task Dim workspace = @@ -899,11 +899,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnContinueFor_Continue() + Public Async Function TestVisualBasicGoToOnContinueFor_Continue() As Task Dim workspace = @@ -919,11 +919,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnContinueFor_For() + Public Async Function TestVisualBasicGoToOnContinueFor_For() As Task Dim workspace = @@ -939,11 +939,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnExitFor_For() + Public Async Function TestVisualBasicGoToOnExitFor_For() As Task Dim workspace = @@ -959,11 +959,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnContinueForEach_For() + Public Async Function TestVisualBasicGoToOnContinueForEach_For() As Task Dim workspace = @@ -979,11 +979,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnExitForEach_For() + Public Async Function TestVisualBasicGoToOnExitForEach_For() As Task Dim workspace = @@ -999,11 +999,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnContinueDoWhileLoop_Do() + Public Async Function TestVisualBasicGoToOnContinueDoWhileLoop_Do() As Task Dim workspace = @@ -1019,11 +1019,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnExitDoWhileLoop_Do() + Public Async Function TestVisualBasicGoToOnExitDoWhileLoop_Do() As Task Dim workspace = @@ -1039,11 +1039,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnContinueDoUntilLoop_Do() + Public Async Function TestVisualBasicGoToOnContinueDoUntilLoop_Do() As Task Dim workspace = @@ -1059,11 +1059,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnExitDoUntilLoop_Do() + Public Async Function TestVisualBasicGoToOnExitDoUntilLoop_Do() As Task Dim workspace = @@ -1079,11 +1079,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnContinueDoLoopWhile_Do() + Public Async Function TestVisualBasicGoToOnContinueDoLoopWhile_Do() As Task Dim workspace = @@ -1099,11 +1099,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnContinueDoLoopUntil_Do() + Public Async Function TestVisualBasicGoToOnContinueDoLoopUntil_Do() As Task Dim workspace = @@ -1119,11 +1119,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnExitTry() + Public Async Function TestVisualBasicGoToOnExitTry() As Task Dim workspace = @@ -1139,11 +1139,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnExitTryInCatch() + Public Async Function TestVisualBasicGoToOnExitTryInCatch() As Task Dim workspace = @@ -1160,11 +1160,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnReturnInSub() + Public Async Function TestVisualBasicGoToOnReturnInSub() As Task Dim workspace = @@ -1178,11 +1178,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnReturnInSub_Partial() + Public Async Function TestVisualBasicGoToOnReturnInSub_Partial() As Task Dim workspace = @@ -1199,11 +1199,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnReturnInSub_Partial_ReverseOrder() + Public Async Function TestVisualBasicGoToOnReturnInSub_Partial_ReverseOrder() As Task Dim workspace = @@ -1220,11 +1220,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnReturnInSubLambda() + Public Async Function TestVisualBasicGoToOnReturnInSubLambda() As Task Dim workspace = @@ -1240,11 +1240,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnReturnInFunction() + Public Async Function TestVisualBasicGoToOnReturnInFunction() As Task Dim workspace = @@ -1258,11 +1258,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnReturnInFunction_OnValue() + Public Async Function TestVisualBasicGoToOnReturnInFunction_OnValue() As Task Dim workspace = @@ -1276,11 +1276,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnReturnInIterator() + Public Async Function TestVisualBasicGoToOnReturnInIterator() As Task Dim workspace = @@ -1294,11 +1294,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnReturnInIterator_OnValue() + Public Async Function TestVisualBasicGoToOnReturnInIterator_OnValue() As Task Dim workspace = @@ -1312,11 +1312,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnReturnInFunctionLambda() + Public Async Function TestVisualBasicGoToOnReturnInFunctionLambda() As Task Dim workspace = @@ -1332,11 +1332,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnReturnInConstructor() + Public Async Function TestVisualBasicGoToOnReturnInConstructor() As Task Dim workspace = @@ -1350,11 +1350,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnReturnInOperator() + Public Async Function TestVisualBasicGoToOnReturnInOperator() As Task Dim workspace = @@ -1368,11 +1368,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnReturnInGetAccessor() + Public Async Function TestVisualBasicGoToOnReturnInGetAccessor() As Task Dim workspace = @@ -1388,11 +1388,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnReturnInSetAccessor() + Public Async Function TestVisualBasicGoToOnReturnInSetAccessor() As Task Dim workspace = @@ -1408,11 +1408,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnExitPropertyInGetAccessor() + Public Async Function TestVisualBasicGoToOnExitPropertyInGetAccessor() As Task Dim workspace = @@ -1428,11 +1428,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnExitPropertyInSetAccessor() + Public Async Function TestVisualBasicGoToOnExitPropertyInSetAccessor() As Task Dim workspace = @@ -1448,11 +1448,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnReturnInAddHandler() + Public Async Function TestVisualBasicGoToOnReturnInAddHandler() As Task Dim workspace = @@ -1468,11 +1468,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnReturnInRemoveHandler() + Public Async Function TestVisualBasicGoToOnReturnInRemoveHandler() As Task Dim workspace = @@ -1488,11 +1488,11 @@ End Class - Test(workspace) - End Sub + Await Test(workspace) + End Function - Public Sub TestVisualBasicGoToOnReturnInRaiseEvent() + Public Async Function TestVisualBasicGoToOnReturnInRaiseEvent() As Task Dim workspace = @@ -1508,8 +1508,7 @@ End Class - Test(workspace) - End Sub - + Await Test(workspace) + End Function End Class End Namespace From 0eb6533a28fdace0e8f90fda8b00b03c844ddb58 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Aug 2021 13:04:44 -0700 Subject: [PATCH 13/42] Properly switch --- ...alStudioDefinitionsAndReferencesFactory.cs | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs index cb5b9d2ff930d..f9a1967949af5 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Editor.FindUsages; +using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.FindSymbols.FindReferences; using Microsoft.CodeAnalysis.FindUsages; using Microsoft.CodeAnalysis.Host.Mef; @@ -29,11 +30,17 @@ internal class VisualStudioDefinitionsAndReferencesFactory : DefaultDefinitionsAndReferencesFactory { private readonly IServiceProvider _serviceProvider; + private readonly IThreadingContext _threadingContext; [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public VisualStudioDefinitionsAndReferencesFactory(SVsServiceProvider serviceProvider) - => _serviceProvider = serviceProvider; + public VisualStudioDefinitionsAndReferencesFactory( + SVsServiceProvider serviceProvider, + IThreadingContext threadingContext) + { + _serviceProvider = serviceProvider; + _threadingContext = threadingContext; + } public override async Task GetThirdPartyDefinitionItemAsync( Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken) @@ -46,7 +53,8 @@ public VisualStudioDefinitionsAndReferencesFactory(SVsServiceProvider servicePro var displayParts = GetDisplayParts(filePath, lineNumber, charOffset); return new ExternalDefinitionItem( definitionItem.Tags, displayParts, - _serviceProvider, filePath, lineNumber, charOffset); + _serviceProvider, _threadingContext, + filePath, lineNumber, charOffset); } private ImmutableArray GetDisplayParts( @@ -77,6 +85,7 @@ private string GetSourceLine(string filePath, int lineNumber) private class ExternalDefinitionItem : DefinitionItem { private readonly IServiceProvider _serviceProvider; + private readonly IThreadingContext _threadingContext; private readonly string _filePath; private readonly int _lineNumber; private readonly int _charOffset; @@ -87,6 +96,7 @@ public ExternalDefinitionItem( ImmutableArray tags, ImmutableArray displayParts, IServiceProvider serviceProvider, + IThreadingContext threadingContext, string filePath, int lineNumber, int charOffset) @@ -98,6 +108,7 @@ public ExternalDefinitionItem( displayIfNoReferences: true) { _serviceProvider = serviceProvider; + _threadingContext = threadingContext; _filePath = filePath; _lineNumber = lineNumber; _charOffset = charOffset; @@ -106,8 +117,11 @@ public ExternalDefinitionItem( public override Task CanNavigateToAsync(Workspace workspace, CancellationToken cancellationToken) => SpecializedTasks.True; - public override Task TryNavigateToAsync(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) - => Task.FromResult(TryOpenFile() && TryNavigateToPosition()); + public override async Task TryNavigateToAsync(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) + { + await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + return TryOpenFile() && TryNavigateToPosition(); + } [Obsolete] public override bool CanNavigateTo(Workspace workspace, CancellationToken cancellationToken) From 5d57c37232310e902cdde82f7562102935737dc2 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Aug 2021 13:05:26 -0700 Subject: [PATCH 14/42] Properly switch --- .../VisualStudioDefinitionsAndReferencesFactory.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs index f9a1967949af5..e315b65e3a988 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs @@ -100,7 +100,9 @@ public ExternalDefinitionItem( string filePath, int lineNumber, int charOffset) - : base(tags, displayParts, ImmutableArray.Empty, + : base(tags, + displayParts, + nameDisplayParts: ImmutableArray.Empty, originationParts: default, sourceSpans: default, properties: null, From b6ae45386446ad61ab16c4c39a17f4081d868e18 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Aug 2021 20:45:50 -0700 Subject: [PATCH 15/42] Handle null value --- .../Core/Portable/FindUsages/IRemoteFindUsagesService.cs | 1 + .../Protocol/CustomProtocol/FindUsagesLSPContext.cs | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs b/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs index 9ac4c51c74698..be62670f4abd7 100644 --- a/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs +++ b/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs @@ -139,6 +139,7 @@ internal readonly struct SerializableDocumentSpan public SerializableDocumentSpan(DocumentId documentId, TextSpan sourceSpan) { + Contract.ThrowIfNull(documentId); DocumentId = documentId; SourceSpan = sourceSpan; } diff --git a/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs b/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs index d6b89ca58b545..84be390e4455e 100644 --- a/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs +++ b/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs @@ -104,7 +104,7 @@ public override async ValueTask OnDefinitionFoundAsync(Solution solution, Defini // Creating a new VSReferenceItem for the definition var definitionItem = await GenerateVSReferenceItemAsync( - _id, definitionId: _id, _document, _position, definition.SourceSpans.FirstOrDefault(), + _id, definitionId: _id, _document, _position, definition.SourceSpans.FirstOrNull(), definition.DisplayableProperties, _metadataAsSourceFileService, definition.GetClassifiedText(), definition.Tags.GetFirstGlyph(), symbolUsageInfo: null, isWrittenTo: false, cancellationToken).ConfigureAwait(false); @@ -168,7 +168,7 @@ public override async ValueTask OnReferenceFoundAsync(Solution solution, SourceR int? definitionId, Document document, int position, - SerializableDocumentSpan serializableDocumentSpan, + SerializableDocumentSpan? serializableDocumentSpan, ImmutableDictionary properties, IMetadataAsSourceFileService metadataAsSourceFileService, ClassifiedTextElement? definitionText, @@ -177,7 +177,9 @@ public override async ValueTask OnReferenceFoundAsync(Solution solution, SourceR bool isWrittenTo, CancellationToken cancellationToken) { - var documentSpan = await serializableDocumentSpan.RehydrateAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); + var documentSpan = serializableDocumentSpan == null + ? default + : await serializableDocumentSpan.Value.RehydrateAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); var location = await ComputeLocationAsync(document, position, documentSpan, metadataAsSourceFileService, cancellationToken).ConfigureAwait(false); // Getting the text for the Text property. If we somehow can't compute the text, that means we're probably dealing with a metadata From e7148a06b6b8ea4ecca536b36b1ef79d711cb03d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Aug 2021 21:23:59 -0700 Subject: [PATCH 16/42] Async nav --- .../InteractiveDocumentNavigationService.cs | 21 +++++++++++++++++ ...ractiveDocumentNavigationServiceFactory.cs | 7 +++--- .../MockDocumentNavigationService.vb | 14 +++++++++++ .../MockDocumentNavigationServiceProvider.vb | 16 +++++++++++++ .../Core/Portable/DocumentSpanExtensions.cs | 23 ++++++++++++++++++- ...tionItem.DocumentLocationDefinitionItem.cs | 12 ++++++---- .../DefaultDocumentNavigationService.cs | 8 +++++++ .../Navigation/IDocumentNavigationService.cs | 14 +++++++++++ .../VisualStudioDocumentNavigationService.cs | 13 +++++++++++ .../MockDocumentNavigationServiceFactory.cs | 6 +++++ 10 files changed, 125 insertions(+), 9 deletions(-) diff --git a/src/EditorFeatures/Core.Wpf/Interactive/InteractiveDocumentNavigationService.cs b/src/EditorFeatures/Core.Wpf/Interactive/InteractiveDocumentNavigationService.cs index cab4b5b42fb2e..e5757ed209041 100644 --- a/src/EditorFeatures/Core.Wpf/Interactive/InteractiveDocumentNavigationService.cs +++ b/src/EditorFeatures/Core.Wpf/Interactive/InteractiveDocumentNavigationService.cs @@ -7,8 +7,10 @@ using System; using System.Diagnostics; using System.Threading; +using System.Threading.Tasks; using Microsoft.CodeAnalysis.Editor.Interactive; using Microsoft.CodeAnalysis.Editor.Shared.Extensions; +using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Navigation; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Text; @@ -19,6 +21,19 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.Interactive { internal sealed class InteractiveDocumentNavigationService : IDocumentNavigationService { + private readonly IThreadingContext _threadingContext; + + public InteractiveDocumentNavigationService(IThreadingContext threadingContext) + { + _threadingContext = threadingContext; + } + + public async Task CanNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken) + { + await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + return CanNavigateToSpan(workspace, documentId, textSpan, cancellationToken); + } + public bool CanNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken) => true; @@ -28,6 +43,12 @@ public bool CanNavigateToLineAndOffset(Workspace workspace, DocumentId documentI public bool CanNavigateToPosition(Workspace workspace, DocumentId documentId, int position, int virtualSpace, CancellationToken cancellationToken) => false; + public async Task TryNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options, bool allowInvalidSpan, CancellationToken cancellationToken) + { + await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + return TryNavigateToSpan(workspace, documentId, textSpan, options, allowInvalidSpan, cancellationToken); + } + public bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options, bool allowInvalidSpan, CancellationToken cancellationToken) { if (workspace is not InteractiveWindowWorkspace interactiveWorkspace) diff --git a/src/EditorFeatures/Core.Wpf/Interactive/InteractiveDocumentNavigationServiceFactory.cs b/src/EditorFeatures/Core.Wpf/Interactive/InteractiveDocumentNavigationServiceFactory.cs index 736ed526da037..f090b159c0567 100644 --- a/src/EditorFeatures/Core.Wpf/Interactive/InteractiveDocumentNavigationServiceFactory.cs +++ b/src/EditorFeatures/Core.Wpf/Interactive/InteractiveDocumentNavigationServiceFactory.cs @@ -2,10 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Composition; +using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Navigation; @@ -19,8 +18,8 @@ internal sealed class InteractiveDocumentNavigationServiceFactory : IWorkspaceSe [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public InteractiveDocumentNavigationServiceFactory() - => _singleton = new InteractiveDocumentNavigationService(); + public InteractiveDocumentNavigationServiceFactory(IThreadingContext threadingContext) + => _singleton = new InteractiveDocumentNavigationService(threadingContext); public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices) => _singleton; diff --git a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockDocumentNavigationService.vb b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockDocumentNavigationService.vb index d8638f223f8ea..dcdf6004c617a 100644 --- a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockDocumentNavigationService.vb +++ b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockDocumentNavigationService.vb @@ -6,6 +6,7 @@ Imports System.Threading Imports Microsoft.CodeAnalysis.Navigation Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.Text +Imports Roslyn.Utilities Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers Friend Class MockDocumentNavigationService @@ -39,6 +40,10 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers Return _canNavigateToSpan End Function + Public Function CanNavigateToSpanAsync(workspace As Workspace, documentId As DocumentId, textSpan As TextSpan, cancellationToken As CancellationToken) As Task(Of Boolean) Implements IDocumentNavigationService.CanNavigateToSpanAsync + Return If(_canNavigateToSpan, SpecializedTasks.True, SpecializedTasks.False) + End Function + Public Function TryNavigateToLineAndOffset(workspace As Workspace, documentId As DocumentId, lineNumber As Integer, offset As Integer, options As OptionSet, cancellationToken As CancellationToken) As Boolean Implements IDocumentNavigationService.TryNavigateToLineAndOffset _triedNavigationToLineAndOffset = True _documentId = documentId @@ -67,5 +72,14 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers Return _canNavigateToSpan End Function + + Public Function TryNavigateToSpanAsync(workspace As Workspace, documentId As DocumentId, textSpan As TextSpan, options As OptionSet, allowInvalidSpan As Boolean, cancellationToken As CancellationToken) As Task(Of Boolean) Implements IDocumentNavigationService.TryNavigateToSpanAsync + _triedNavigationToSpan = True + _documentId = documentId + _options = options + _span = textSpan + + Return If(_canNavigateToSpan, SpecializedTasks.True, SpecializedTasks.False) + End Function End Class End Namespace diff --git a/src/EditorFeatures/TestUtilities2/Utilities/MockDocumentNavigationServiceProvider.vb b/src/EditorFeatures/TestUtilities2/Utilities/MockDocumentNavigationServiceProvider.vb index 7b29643d7681b..20600f3e6c353 100644 --- a/src/EditorFeatures/TestUtilities2/Utilities/MockDocumentNavigationServiceProvider.vb +++ b/src/EditorFeatures/TestUtilities2/Utilities/MockDocumentNavigationServiceProvider.vb @@ -9,6 +9,7 @@ Imports Microsoft.CodeAnalysis.Host.Mef Imports Microsoft.CodeAnalysis.Navigation Imports Microsoft.CodeAnalysis.Options Imports Microsoft.CodeAnalysis.Text +Imports Roslyn.Utilities Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities ' Note: by default, TestWorkspace produces a composition from all assemblies except EditorServicesTest2. @@ -69,6 +70,13 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities Return CanNavigateToSpanReturnValue End Function + Public Function CanNavigateToSpanAsync(workspace As Workspace, documentId As DocumentId, textSpan As TextSpan, cancellationToken As CancellationToken) As Task(Of Boolean) Implements IDocumentNavigationService.CanNavigateToSpanAsync + Me.ProvidedDocumentId = documentId + Me.ProvidedTextSpan = textSpan + + Return If(CanNavigateToSpanReturnValue, SpecializedTasks.True, SpecializedTasks.False) + End Function + Public Function TryNavigateToLineAndOffset(workspace As Workspace, documentId As DocumentId, lineNumber As Integer, offset As Integer, options As OptionSet, cancellationToken As CancellationToken) As Boolean Implements IDocumentNavigationService.TryNavigateToLineAndOffset Me.ProvidedDocumentId = documentId Me.ProvidedLineNumber = lineNumber @@ -94,6 +102,14 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities Return TryNavigateToSpanReturnValue End Function + + Public Function TryNavigateToSpanAsync(workspace As Workspace, documentId As DocumentId, textSpan As TextSpan, options As OptionSet, allowInvalidSpans As Boolean, cancellationToken As CancellationToken) As Task(Of Boolean) Implements IDocumentNavigationService.TryNavigateToSpanAsync + Me.ProvidedDocumentId = documentId + Me.ProvidedTextSpan = textSpan + Me.ProvidedOptions = options + + Return If(TryNavigateToSpanReturnValue, SpecializedTasks.True, SpecializedTasks.False) + End Function End Class End Class End Namespace diff --git a/src/Features/Core/Portable/DocumentSpanExtensions.cs b/src/Features/Core/Portable/DocumentSpanExtensions.cs index e984967883179..5f2ae2978df36 100644 --- a/src/Features/Core/Portable/DocumentSpanExtensions.cs +++ b/src/Features/Core/Portable/DocumentSpanExtensions.cs @@ -7,6 +7,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Navigation; +using Microsoft.CodeAnalysis.Options; namespace Microsoft.CodeAnalysis { @@ -19,7 +20,15 @@ public static bool CanNavigateTo(this DocumentSpan documentSpan, CancellationTok return service.CanNavigateToSpan(workspace, documentSpan.Document.Id, documentSpan.SourceSpan, cancellationToken); } - public static bool TryNavigateTo(this DocumentSpan documentSpan, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) + public static Task CanNavigateToAsync(this DocumentSpan documentSpan, CancellationToken cancellationToken) + { + var workspace = documentSpan.Document.Project.Solution.Workspace; + var service = workspace.Services.GetService(); + return service.CanNavigateToSpanAsync(workspace, documentSpan.Document.Id, documentSpan.SourceSpan, cancellationToken); + } + + private static (Workspace workspace, IDocumentNavigationService service, OptionSet options) GetNavigationParts( + DocumentSpan documentSpan, bool showInPreviewTab, bool activateTab) { var solution = documentSpan.Document.Project.Solution; var workspace = solution.Workspace; @@ -28,9 +37,21 @@ public static bool TryNavigateTo(this DocumentSpan documentSpan, bool showInPrev var options = solution.Options.WithChangedOption(NavigationOptions.PreferProvisionalTab, showInPreviewTab); options = options.WithChangedOption(NavigationOptions.ActivateTab, activateTab); + return (workspace, service, options); + } + + public static bool TryNavigateTo(this DocumentSpan documentSpan, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) + { + var (workspace, service, options) = GetNavigationParts(documentSpan, showInPreviewTab, activateTab); return service.TryNavigateToSpan(workspace, documentSpan.Document.Id, documentSpan.SourceSpan, options, cancellationToken); } + public static Task TryNavigateToAsync(this DocumentSpan documentSpan, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) + { + var (workspace, service, options) = GetNavigationParts(documentSpan, showInPreviewTab, activateTab); + return service.TryNavigateToSpanAsync(workspace, documentSpan.Document.Id, documentSpan.SourceSpan, options, cancellationToken); + } + public static async Task IsHiddenAsync( this DocumentSpan documentSpan, CancellationToken cancellationToken) { diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs index 1edc60ae3f588..361a515aaf3a5 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs @@ -63,8 +63,10 @@ public override async Task CanNavigateToAsync(Workspace workspace, Cancell if (Properties.TryGetValue(MetadataSymbolKey, out var symbolKey)) return CanNavigateToMetadataSymbol(workspace, symbolKey); - return await TryGetDocumentSpanAsync(workspace, cancellationToken).ConfigureAwait(false) is DocumentSpan span && - span.CanNavigateTo(cancellationToken); + if (await TryGetDocumentSpanAsync(workspace, cancellationToken).ConfigureAwait(false) is not DocumentSpan span) + return false; + + return await span.CanNavigateToAsync(cancellationToken).ConfigureAwait(false); } public override async Task TryNavigateToAsync(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) @@ -75,8 +77,10 @@ public override async Task TryNavigateToAsync(Workspace workspace, bool sh if (Properties.TryGetValue(MetadataSymbolKey, out var symbolKey)) return TryNavigateToMetadataSymbol(workspace, symbolKey); - return await TryGetDocumentSpanAsync(workspace, cancellationToken).ConfigureAwait(false) is DocumentSpan span && - span.TryNavigateTo(showInPreviewTab, activateTab, cancellationToken); + if (await TryGetDocumentSpanAsync(workspace, cancellationToken).ConfigureAwait(false) is not DocumentSpan span) + return false; + + return await span.TryNavigateToAsync(showInPreviewTab, activateTab, cancellationToken).ConfigureAwait(false); } private bool CanNavigateToMetadataSymbol(Workspace workspace, string symbolKey) diff --git a/src/Features/Core/Portable/Navigation/DefaultDocumentNavigationService.cs b/src/Features/Core/Portable/Navigation/DefaultDocumentNavigationService.cs index 05943ab6cef20..4da48804fbd92 100644 --- a/src/Features/Core/Portable/Navigation/DefaultDocumentNavigationService.cs +++ b/src/Features/Core/Portable/Navigation/DefaultDocumentNavigationService.cs @@ -5,8 +5,10 @@ #nullable disable using System.Threading; +using System.Threading.Tasks; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Text; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Navigation { @@ -15,6 +17,9 @@ internal sealed class DefaultDocumentNavigationService : IDocumentNavigationServ public bool CanNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken) => false; + public Task CanNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken) + => SpecializedTasks.False; + public bool CanNavigateToLineAndOffset(Workspace workspace, DocumentId documentId, int lineNumber, int offset, CancellationToken cancellationToken) => false; @@ -24,6 +29,9 @@ public bool CanNavigateToPosition(Workspace workspace, DocumentId documentId, in public bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options, bool allowInvalidSpan, CancellationToken cancellationToken) => false; + public Task TryNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options, bool allowInvalidSpan, CancellationToken cancellationToken) + => SpecializedTasks.False; + public bool TryNavigateToLineAndOffset(Workspace workspace, DocumentId documentId, int lineNumber, int offset, OptionSet options, CancellationToken cancellationToken) => false; diff --git a/src/Features/Core/Portable/Navigation/IDocumentNavigationService.cs b/src/Features/Core/Portable/Navigation/IDocumentNavigationService.cs index c7672002daf51..7e97c6e33d165 100644 --- a/src/Features/Core/Portable/Navigation/IDocumentNavigationService.cs +++ b/src/Features/Core/Portable/Navigation/IDocumentNavigationService.cs @@ -5,6 +5,7 @@ #nullable disable using System.Threading; +using System.Threading.Tasks; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Text; @@ -18,6 +19,11 @@ internal interface IDocumentNavigationService : IWorkspaceService /// bool CanNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken); + /// + /// Determines whether it is possible to navigate to the given position in the specified document. + /// + Task CanNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken); + /// /// Determines whether it is possible to navigate to the given line/offset in the specified document. /// @@ -33,6 +39,11 @@ internal interface IDocumentNavigationService : IWorkspaceService /// bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options, bool allowInvalidSpan, CancellationToken cancellationToken); + /// + /// Navigates to the given position in the specified document, opening it if necessary. + /// + Task TryNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options, bool allowInvalidSpan, CancellationToken cancellationToken); + /// /// Navigates to the given line/offset in the specified document, opening it if necessary. /// @@ -55,6 +66,9 @@ public static bool TryNavigateToSpan(this IDocumentNavigationService service, Wo public static bool TryNavigateToSpan(this IDocumentNavigationService service, Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options, CancellationToken cancellationToken) => service.TryNavigateToSpan(workspace, documentId, textSpan, options, allowInvalidSpan: false, cancellationToken); + public static Task TryNavigateToSpanAsync(this IDocumentNavigationService service, Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options, CancellationToken cancellationToken) + => service.TryNavigateToSpanAsync(workspace, documentId, textSpan, options, allowInvalidSpan: false, cancellationToken); + public static bool TryNavigateToLineAndOffset(this IDocumentNavigationService service, Workspace workspace, DocumentId documentId, int lineNumber, int offset, CancellationToken cancellationToken) => service.TryNavigateToLineAndOffset(workspace, documentId, lineNumber, offset, options: null, cancellationToken); diff --git a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioDocumentNavigationService.cs b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioDocumentNavigationService.cs index 0c42ba3fd8cb8..19279a2e30287 100644 --- a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioDocumentNavigationService.cs +++ b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioDocumentNavigationService.cs @@ -9,6 +9,7 @@ using System.Diagnostics; using System.Linq; using System.Threading; +using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.ErrorReporting; @@ -60,6 +61,12 @@ public VisualStudioDocumentNavigationService( _sourceGeneratedFileManager = sourceGeneratedFileManager; } + public async Task CanNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken) + { + await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + return CanNavigateToSpan(workspace, documentId, textSpan, cancellationToken); + } + public bool CanNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken) { // Navigation should not change the context of linked files and Shared Projects. @@ -141,6 +148,12 @@ public bool CanNavigateToPosition(Workspace workspace, DocumentId documentId, in return CanMapFromSecondaryBufferToPrimaryBuffer(workspace, documentId, vsTextSpan); } + public async Task TryNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options, bool allowInvalidSpan, CancellationToken cancellationToken) + { + await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + return TryNavigateToSpan(workspace, documentId, textSpan, options, allowInvalidSpan, cancellationToken); + } + public bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options, bool allowInvalidSpan, CancellationToken cancellationToken) { return TryNavigateToLocation(workspace, diff --git a/src/VisualStudio/LiveShare/Test/MockDocumentNavigationServiceFactory.cs b/src/VisualStudio/LiveShare/Test/MockDocumentNavigationServiceFactory.cs index 37ca5abb31188..0bd95064351be 100644 --- a/src/VisualStudio/LiveShare/Test/MockDocumentNavigationServiceFactory.cs +++ b/src/VisualStudio/LiveShare/Test/MockDocumentNavigationServiceFactory.cs @@ -7,12 +7,14 @@ using System; using System.Composition; using System.Threading; +using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Navigation; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Text; +using Roslyn.Utilities; namespace Microsoft.VisualStudio.LanguageServices.LiveShare.UnitTests { @@ -40,11 +42,15 @@ private class MockDocumentNavigationService : IDocumentNavigationService public bool CanNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken) => true; + public Task CanNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken) => SpecializedTasks.True; + public bool TryNavigateToLineAndOffset(Workspace workspace, DocumentId documentId, int lineNumber, int offset, OptionSet options, CancellationToken cancellationToken) => true; public bool TryNavigateToPosition(Workspace workspace, DocumentId documentId, int position, int virtualSpace, OptionSet options, CancellationToken cancellationToken) => true; public bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options, bool allowInvalidSpans, CancellationToken cancellationToken) => true; + + public Task TryNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options, bool allowInvalidSpan, CancellationToken cancellationToken) => SpecializedTasks.True; } } } From cf021e0a9f72a5542061c324d5116478a80bd429 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Aug 2021 21:56:02 -0700 Subject: [PATCH 17/42] Use original workspace. --- .../DefinitionItem.DocumentLocationDefinitionItem.cs | 8 ++++---- src/Features/Core/Portable/FindUsages/DefinitionItem.cs | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs index 361a515aaf3a5..21b535c03db37 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs @@ -38,9 +38,9 @@ public DefaultDefinitionItem( { } - private async Task TryGetDocumentSpanAsync(Workspace workspace, CancellationToken cancellationToken) + private async Task TryGetDocumentSpanAsync(CancellationToken cancellationToken) { - var solution = workspace.CurrentSolution; + var solution = Workspace.CurrentSolution; var documentId = SourceSpans[0].DocumentId; var document = solution.GetDocument(documentId) ?? await solution.GetSourceGeneratedDocumentAsync(documentId, cancellationToken).ConfigureAwait(false); @@ -63,7 +63,7 @@ public override async Task CanNavigateToAsync(Workspace workspace, Cancell if (Properties.TryGetValue(MetadataSymbolKey, out var symbolKey)) return CanNavigateToMetadataSymbol(workspace, symbolKey); - if (await TryGetDocumentSpanAsync(workspace, cancellationToken).ConfigureAwait(false) is not DocumentSpan span) + if (await TryGetDocumentSpanAsync(cancellationToken).ConfigureAwait(false) is not DocumentSpan span) return false; return await span.CanNavigateToAsync(cancellationToken).ConfigureAwait(false); @@ -77,7 +77,7 @@ public override async Task TryNavigateToAsync(Workspace workspace, bool sh if (Properties.TryGetValue(MetadataSymbolKey, out var symbolKey)) return TryNavigateToMetadataSymbol(workspace, symbolKey); - if (await TryGetDocumentSpanAsync(workspace, cancellationToken).ConfigureAwait(false) is not DocumentSpan span) + if (await TryGetDocumentSpanAsync(cancellationToken).ConfigureAwait(false) is not DocumentSpan span) return false; return await span.TryNavigateToAsync(showInPreviewTab, activateTab, cancellationToken).ConfigureAwait(false); diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.cs index 8675cefb8e084..a58e3daff9a93 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Immutable; +using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Tags; @@ -110,6 +111,8 @@ internal abstract partial class DefinitionItem internal abstract bool IsExternal { get; } + protected readonly Workspace Workspace; + // F# uses this protected DefinitionItem( ImmutableArray tags, @@ -155,6 +158,8 @@ protected DefinitionItem( Contract.ThrowIfFalse(Properties.ContainsKey(MetadataSymbolOriginatingProjectIdGuid)); Contract.ThrowIfFalse(Properties.ContainsKey(MetadataSymbolOriginatingProjectIdDebugName)); } + + Workspace = sourceSpans.FirstOrDefault().Document?.Project.Solution.Workspace; } [Obsolete("Override CanNavigateToAsync instead", error: false)] From 312eff656e80a9dac46a911d80e3f8d5d2b4b775 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Aug 2021 09:24:25 -0700 Subject: [PATCH 18/42] Add docs --- .../InteractiveDocumentNavigationService.cs | 3 +++ .../Portable/Navigation/IDocumentNavigationService.cs | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/EditorFeatures/Core.Wpf/Interactive/InteractiveDocumentNavigationService.cs b/src/EditorFeatures/Core.Wpf/Interactive/InteractiveDocumentNavigationService.cs index e5757ed209041..17cd33f5c270c 100644 --- a/src/EditorFeatures/Core.Wpf/Interactive/InteractiveDocumentNavigationService.cs +++ b/src/EditorFeatures/Core.Wpf/Interactive/InteractiveDocumentNavigationService.cs @@ -30,6 +30,9 @@ public InteractiveDocumentNavigationService(IThreadingContext threadingContext) public async Task CanNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken) { + // This switch is technically not needed as the call to CanNavigateToSpan just returns 'true'. + // However, this abides by the contract that CanNavigateToSpan only be called on the UI thread. + // It also means if we ever update that method, this code will stay corrrect. await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); return CanNavigateToSpan(workspace, documentId, textSpan, cancellationToken); } diff --git a/src/Features/Core/Portable/Navigation/IDocumentNavigationService.cs b/src/Features/Core/Portable/Navigation/IDocumentNavigationService.cs index 7e97c6e33d165..b384ad2508203 100644 --- a/src/Features/Core/Portable/Navigation/IDocumentNavigationService.cs +++ b/src/Features/Core/Portable/Navigation/IDocumentNavigationService.cs @@ -17,21 +17,25 @@ internal interface IDocumentNavigationService : IWorkspaceService /// /// Determines whether it is possible to navigate to the given position in the specified document. /// + /// Only legal to call on the UI thread. bool CanNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken); /// /// Determines whether it is possible to navigate to the given position in the specified document. /// + /// Legal to call from any thread. Task CanNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken); /// /// Determines whether it is possible to navigate to the given line/offset in the specified document. /// + /// Only legal to call on the UI thread. bool CanNavigateToLineAndOffset(Workspace workspace, DocumentId documentId, int lineNumber, int offset, CancellationToken cancellationToken); /// /// Determines whether it is possible to navigate to the given virtual position in the specified document. /// + /// Only legal to call on the UI thread. bool CanNavigateToPosition(Workspace workspace, DocumentId documentId, int position, int virtualSpace, CancellationToken cancellationToken); /// @@ -47,6 +51,7 @@ internal interface IDocumentNavigationService : IWorkspaceService /// /// Navigates to the given line/offset in the specified document, opening it if necessary. /// + /// Only legal to call on the UI thread. bool TryNavigateToLineAndOffset(Workspace workspace, DocumentId documentId, int lineNumber, int offset, OptionSet options, CancellationToken cancellationToken); /// @@ -57,21 +62,27 @@ internal interface IDocumentNavigationService : IWorkspaceService internal static class IDocumentNavigationServiceExtensions { + /// Only legal to call on the UI thread. public static bool CanNavigateToPosition(this IDocumentNavigationService service, Workspace workspace, DocumentId documentId, int position, CancellationToken cancellationToken) => service.CanNavigateToPosition(workspace, documentId, position, virtualSpace: 0, cancellationToken); + /// Only legal to call on the UI thread. public static bool TryNavigateToSpan(this IDocumentNavigationService service, Workspace workspace, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken) => service.TryNavigateToSpan(workspace, documentId, textSpan, options: null, cancellationToken); + /// Only legal to call on the UI thread. public static bool TryNavigateToSpan(this IDocumentNavigationService service, Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options, CancellationToken cancellationToken) => service.TryNavigateToSpan(workspace, documentId, textSpan, options, allowInvalidSpan: false, cancellationToken); + /// Legal to call from any thread. public static Task TryNavigateToSpanAsync(this IDocumentNavigationService service, Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options, CancellationToken cancellationToken) => service.TryNavigateToSpanAsync(workspace, documentId, textSpan, options, allowInvalidSpan: false, cancellationToken); + /// Only legal to call on the UI thread. public static bool TryNavigateToLineAndOffset(this IDocumentNavigationService service, Workspace workspace, DocumentId documentId, int lineNumber, int offset, CancellationToken cancellationToken) => service.TryNavigateToLineAndOffset(workspace, documentId, lineNumber, offset, options: null, cancellationToken); + /// Only legal to call on the UI thread. public static bool TryNavigateToPosition(this IDocumentNavigationService service, Workspace workspace, DocumentId documentId, int position, CancellationToken cancellationToken) => service.TryNavigateToPosition(workspace, documentId, position, virtualSpace: 0, options: null, cancellationToken); } From 730289d07395b8509257ffc240d01e300955f6bc Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Aug 2021 09:26:55 -0700 Subject: [PATCH 19/42] Move all to ConfigurAwait(false) --- .../AbstractFindUsagesService_FindReferences.cs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs index e7290a5cb0577..b8dc943548fb3 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs @@ -24,27 +24,16 @@ async Task IFindUsagesService.FindReferencesAsync( { var definitionTrackingContext = new DefinitionTrackingContext(context); - // Need ConfigureAwait(true) here so we get back to the UI thread before calling - // GetThirdPartyDefinitions. We need to call that on the UI thread to match behavior - // of how the language service always worked in the past. - // - // Any async calls before GetThirdPartyDefinitions must be ConfigureAwait(true). await FindLiteralOrSymbolReferencesAsync( - document, position, definitionTrackingContext, cancellationToken).ConfigureAwait(true); + document, position, definitionTrackingContext, cancellationToken).ConfigureAwait(false); // After the FAR engine is done call into any third party extensions to see // if they want to add results. var thirdPartyDefinitions = await GetThirdPartyDefinitionsAsync( - document.Project.Solution, definitionTrackingContext.GetDefinitions(), cancellationToken).ConfigureAwait(true); - - // From this point on we can do ConfigureAwait(false) as we're not calling back - // into third parties anymore. + document.Project.Solution, definitionTrackingContext.GetDefinitions(), cancellationToken).ConfigureAwait(false); foreach (var definition in thirdPartyDefinitions) - { - // Don't need ConfigureAwait(true) here await context.OnDefinitionFoundAsync(document.Project.Solution, definition, cancellationToken).ConfigureAwait(false); - } } Task IFindUsagesLSPService.FindReferencesAsync( From 5b3570959a7e2d7fe79ef22b11baad36d4555c0c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Aug 2021 09:31:35 -0700 Subject: [PATCH 20/42] Switch to ConfigureAwait(true) --- .../Core/GoToDefinition/AbstractGoToDefinitionService.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs index 4c2e5015a5a6a..a21988b01f79d 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs @@ -122,12 +122,16 @@ private bool TryGoToAlternativeLocationIfAlreadyOnDefinition( using var _ = ArrayBuilder.GetInstance(out var definitions); foreach (var impl in interfaceImpls) { - foreach (var def in await GoToDefinitionHelpers.GetDefinitionsAsync(impl, solution, thirdPartyNavigationAllowed: false, cancellationToken).ConfigureAwait(false)) + // Use ConfigureAwait(true) here. Not for a correctness requirements, but because we're + // already blocking the UI thread by being in a JTF.Run call. So we might as well try to + // continue to use the blocking UI thread to do as much work as possible instead of making + // it wait for threadpool threads to be available to process the work. + foreach (var def in await GoToDefinitionHelpers.GetDefinitionsAsync(impl, solution, thirdPartyNavigationAllowed: false, cancellationToken).ConfigureAwait(true)) definitions.Add(def); } return await _streamingPresenter.TryNavigateToOrPresentItemsAsync( - _threadingContext, solution, title, definitions.ToImmutable(), cancellationToken).ConfigureAwait(false); + _threadingContext, solution, title, definitions.ToImmutable(), cancellationToken).ConfigureAwait(true); }); } From bc8632a9f61fe1f1f7b41e0cfdd9d2e54ae991ce Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Aug 2021 09:51:08 -0700 Subject: [PATCH 21/42] Make members obsolete --- src/Features/Core/Portable/DocumentSpanExtensions.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Features/Core/Portable/DocumentSpanExtensions.cs b/src/Features/Core/Portable/DocumentSpanExtensions.cs index 5f2ae2978df36..e68eb13c8f7f6 100644 --- a/src/Features/Core/Portable/DocumentSpanExtensions.cs +++ b/src/Features/Core/Portable/DocumentSpanExtensions.cs @@ -4,6 +4,7 @@ #nullable disable +using System; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Navigation; @@ -13,6 +14,7 @@ namespace Microsoft.CodeAnalysis { internal static class DocumentSpanExtensions { + [Obsolete("Use CanNavigateToAsync instead", error: false)] public static bool CanNavigateTo(this DocumentSpan documentSpan, CancellationToken cancellationToken) { var workspace = documentSpan.Document.Project.Solution.Workspace; @@ -40,6 +42,7 @@ private static (Workspace workspace, IDocumentNavigationService service, OptionS return (workspace, service, options); } + [Obsolete("Use TryNavigateToAsync instead", error: false)] public static bool TryNavigateTo(this DocumentSpan documentSpan, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) { var (workspace, service, options) = GetNavigationParts(documentSpan, showInPreviewTab, activateTab); From f2f34f7a81b79c4d9ce23fa193324de8c59cb60b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Aug 2021 09:53:56 -0700 Subject: [PATCH 22/42] Add comment --- .../DefinitionItem.DocumentLocationDefinitionItem.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs index 21b535c03db37..3733eb6551f0a 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs @@ -40,6 +40,11 @@ public DefaultDefinitionItem( private async Task TryGetDocumentSpanAsync(CancellationToken cancellationToken) { + // We explicitly do not use SerializableDefinitionItem.RehydrateAsync here. That method + // only is guaranteed to work if passed the original Solution that the definition item + // was created against (and it will throw if is passed a different solution that it can't + // find the document in). Because we are using .CurrentSolution here, we need to be resilient + // to the possibility that we may no longer be able to find/navigate to this document. var solution = Workspace.CurrentSolution; var documentId = SourceSpans[0].DocumentId; var document = solution.GetDocument(documentId) ?? From 69157f987634ef93b6d9d939a133e4f10f3ae479 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Aug 2021 10:01:19 -0700 Subject: [PATCH 23/42] Add comment --- src/Features/Core/Portable/FindUsages/DefinitionItem.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.cs index a58e3daff9a93..7c3657a04e0d4 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.cs @@ -111,6 +111,13 @@ internal abstract partial class DefinitionItem internal abstract bool IsExternal { get; } + /// + /// The workspace containing the location of the for this definition item. + /// Definitions may be in different workspaces, including a different workspace than where a command + /// was originally invoked from. For example, when using metadata-as-source symbols (and their definitions + /// and references) may be found in different workspaces (like the metadata-as-source-workspace and the + /// primary/vs workspace). + /// protected readonly Workspace Workspace; // F# uses this From a7f8ce9ab18a24692ed4021d2450324e6011bc69 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Aug 2021 11:47:13 -0700 Subject: [PATCH 24/42] Keep the workspace in the span we pass around --- .../FindBaseSymbolsCommandHandler.cs | 5 +-- .../FindDerivedSymbolsCommandHandler.cs | 7 ++-- .../FindExtensionMethodsCommandHandler.cs | 4 +- .../FindImplementingMembersCommandHandler.cs | 4 +- .../FindMemberOverloadsCommandHandler.cs | 7 ++-- ...FindReferencesOfOverloadsCommandHandler.cs | 2 +- .../Core.Wpf/Peek/PeekableItemFactory.cs | 2 +- .../AbstractGoToCommandHandler.cs | 2 +- .../VSTypeScriptFindUsagesService.cs | 16 +++---- .../FindReferencesCommandHandler.cs | 2 +- ...UsagesService.DefinitionTrackingContext.cs | 8 ++-- ...stractFindUsagesService.ProgressAdapter.cs | 5 +-- ...ctFindUsagesService_FindImplementations.cs | 2 +- ...bstractFindUsagesService_FindReferences.cs | 4 +- .../Core/FindUsages/FindUsagesContext.cs | 6 +-- .../FindUsages/SimpleFindUsagesContext.cs | 4 +- .../Core/GoToBase/AbstractGoToBaseService.cs | 4 +- .../AbstractGoToDefinitionService.cs | 2 +- .../GoToDefinition/GoToDefinitionHelpers.cs | 4 +- .../Host/IStreamingFindReferencesPresenter.cs | 7 ++-- .../FindReferencesCommandHandlerTests.cs | 2 +- .../InheritanceMarginTests.cs | 10 ++--- .../FindReferences/FindReferencesTests.vb | 30 ++++++------- .../GoToDefinition/GoToDefinitionTestsBase.vb | 4 +- .../Test2/GoToHelpers/GoToHelpers.vb | 4 +- .../MockSymbolNavigationService.vb | 2 +- .../MockSymbolNavigationServiceProvider.vb | 3 -- src/Features/Core/Portable/DocumentIdSpan.cs | 42 +++++++++++++++++++ ...tionItem.DocumentLocationDefinitionItem.cs | 5 ++- .../Portable/FindUsages/DefinitionItem.cs | 15 +------ .../Portable/FindUsages/IFindUsagesContext.cs | 4 +- .../FindUsages/IRemoteFindUsagesService.cs | 8 ++-- .../FindUsages/SourceReferenceItem.cs | 4 +- .../DefaultSymbolNavigationService.cs | 2 +- .../Navigation/ISymbolNavigationService.cs | 2 +- .../CustomProtocol/FindUsagesLSPContext.cs | 41 +++++++++--------- .../References/FindAllReferencesHandler.cs | 2 +- .../References/FindImplementationsHandler.cs | 10 +++-- .../Debugger/DebuggerFindReferencesService.cs | 2 +- .../FindUsages/FSharpFindUsagesContext.cs | 8 ++-- .../FindUsages/FSharpFindUsagesService.cs | 4 +- ...bstractTableDataSourceFindUsagesContext.cs | 34 ++++++++------- .../WithReferencesFindUsagesContext.cs | 33 ++++++--------- .../WithoutReferencesFindUsagesContext.cs | 24 ++++++----- ...alStudioDefinitionsAndReferencesFactory.cs | 2 +- .../AbstractObjectBrowserLibraryManager.cs | 2 +- .../VisualStudioSymbolNavigationService.cs | 22 ++++------ .../FindUsages/RemoteFindUsagesService.cs | 4 +- 48 files changed, 219 insertions(+), 203 deletions(-) create mode 100644 src/Features/Core/Portable/DocumentIdSpan.cs diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs index c5661a0f20e1d..2de345905f887 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs @@ -70,7 +70,6 @@ private async Task StreamingFindBaseSymbolsAsync( KeyValueLogMessage.Create(LogType.UserAction, m => m["type"] = "streaming"), cancellationToken)) { - var solution = document.Project.Solution; try { var relevantSymbol = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, cancellationToken).ConfigureAwait(false); @@ -84,7 +83,7 @@ private async Task StreamingFindBaseSymbolsAsync( } var definitionItem = overriddenSymbol.ToNonClassifiedDefinitionItem(document.Project.Solution, true); - await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); // try getting the next one overriddenSymbol = overriddenSymbol.GetOverriddenMember(); @@ -92,7 +91,7 @@ private async Task StreamingFindBaseSymbolsAsync( } finally { - await context.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs index 3e0bf771d6e98..2a2049af18f92 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs @@ -84,7 +84,6 @@ private static async Task> GatherSymbolsAsync(ISymbol symbo private async Task FindDerivedSymbolsAsync( Document document, int caretPosition, IStreamingFindUsagesPresenter presenter) { - var solution = document.Project.Solution; try { using var token = _asyncListener.BeginAsyncOperation(nameof(FindDerivedSymbolsAsync)); @@ -102,18 +101,18 @@ private async Task FindDerivedSymbolsAsync( return; var candidates = await GatherSymbolsAsync( - candidateSymbolProjectPair.Value.symbol, solution, cancellationToken).ConfigureAwait(false); + candidateSymbolProjectPair.Value.symbol, document.Project.Solution, cancellationToken).ConfigureAwait(false); foreach (var candidate in candidates) { var definitionItem = candidate.ToNonClassifiedDefinitionItem(document.Project.Solution, true); - await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); } } } finally { - await context.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs index 6aebb99319778..843a5cecea69f 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs @@ -111,7 +111,7 @@ private async Task FindExtensionMethodsAsync( var definitionItem = reducedMethod.ToNonClassifiedDefinitionItem(solution, true); - await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); } } } @@ -120,7 +120,7 @@ private async Task FindExtensionMethodsAsync( } finally { - await context.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs index c88de382641c4..7e8998cfff489 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs @@ -119,7 +119,7 @@ private async Task FindImplementingMembersAsync( } finally { - await context.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } } @@ -144,7 +144,7 @@ private static async Task InspectInterfaceAsync( continue; var definitionItem = impl.ToNonClassifiedDefinitionItem(project.Solution, true); - await context.OnDefinitionFoundAsync(project.Solution, definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs index 9d93ecfeb4dbd..2c6ac335cf584 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs @@ -70,7 +70,6 @@ private async Task FindMemberOverloadsAsync( KeyValueLogMessage.Create(LogType.UserAction, m => m["type"] = "streaming"), cancellationToken)) { - var solution = document.Project.Solution; try { var candidateSymbolProjectPair = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, cancellationToken).ConfigureAwait(false); @@ -85,13 +84,13 @@ private async Task FindMemberOverloadsAsync( foreach (var curSymbol in symbol.ContainingType.GetMembers() .Where(m => m.Kind == symbol.Kind && m.Name == symbol.Name)) { - var definitionItem = curSymbol.ToNonClassifiedDefinitionItem(solution, includeHiddenLocations: true); - await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); + var definitionItem = curSymbol.ToNonClassifiedDefinitionItem(document.Project.Solution, includeHiddenLocations: true); + await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); } } finally { - await context.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs index 962ff9d62f921..a0df9102cd7f9 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs @@ -138,7 +138,7 @@ private async Task StreamingFindReferencesAsync( // that means that a new search has started. We don't care about telling the // context it has completed. In the latter case something wrong has happened // and we don't want to run any more code in this particular context. - await context.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs b/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs index 3b95b6e5b8715..a771b697722fb 100644 --- a/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs +++ b/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs @@ -67,7 +67,7 @@ public async Task> GetPeekableItemsAsync( var symbolNavigationService = solution.Workspace.Services.GetService(); var definitionItem = symbol.ToNonClassifiedDefinitionItem(solution, includeHiddenLocations: true); - var result = await symbolNavigationService.WouldNavigateToSymbolAsync(definitionItem, solution, cancellationToken).ConfigureAwait(false); + var result = await symbolNavigationService.WouldNavigateToSymbolAsync(definitionItem, cancellationToken).ConfigureAwait(false); if (result is var (filePath, lineNumber, charOffset)) { var position = new LinePosition(lineNumber, charOffset); diff --git a/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs b/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs index 85ecef8ad836c..4ad732394b8dc 100644 --- a/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs +++ b/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs @@ -126,7 +126,7 @@ private void ExecuteCommand( return context.Message; await _streamingPresenter.TryNavigateToOrPresentItemsAsync( - _threadingContext, document.Project.Solution, context.SearchTitle, context.GetDefinitions(), cancellationToken).ConfigureAwait(false); + _threadingContext, document.Project.Solution.Workspace, context.SearchTitle, context.GetDefinitions(), cancellationToken).ConfigureAwait(false); return null; } } diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs index 5dfb35f773993..849e357564052 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs @@ -28,22 +28,18 @@ public VSTypeScriptFindUsagesService(IVSTypeScriptFindUsagesService underlyingSe } public Task FindReferencesAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _underlyingService.FindReferencesAsync(document, position, new VSTypeScriptFindUsagesContext(document.Project.Solution, context), cancellationToken); + => _underlyingService.FindReferencesAsync(document, position, new VSTypeScriptFindUsagesContext(context), cancellationToken); public Task FindImplementationsAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _underlyingService.FindImplementationsAsync(document, position, new VSTypeScriptFindUsagesContext(document.Project.Solution, context), cancellationToken); + => _underlyingService.FindImplementationsAsync(document, position, new VSTypeScriptFindUsagesContext(context), cancellationToken); private class VSTypeScriptFindUsagesContext : IVSTypeScriptFindUsagesContext { - private readonly Solution _solution; private readonly IFindUsagesContext _context; private readonly Dictionary _definitionItemMap = new(); - public VSTypeScriptFindUsagesContext(Solution solution, IFindUsagesContext context) - { - _solution = solution; - _context = context; - } + public VSTypeScriptFindUsagesContext(IFindUsagesContext context) + => _context = context; public IVSTypeScriptStreamingProgressTracker ProgressTracker => new VSTypeScriptStreamingProgressTracker(_context.ProgressTracker); @@ -77,13 +73,13 @@ private DefinitionItem GetOrCreateDefinitionItem(VSTypeScriptDefinitionItem item public ValueTask OnDefinitionFoundAsync(VSTypeScriptDefinitionItem definition, CancellationToken cancellationToken) { var item = GetOrCreateDefinitionItem(definition); - return _context.OnDefinitionFoundAsync(_solution, item, cancellationToken); + return _context.OnDefinitionFoundAsync(item, cancellationToken); } public ValueTask OnReferenceFoundAsync(VSTypeScriptSourceReferenceItem reference, CancellationToken cancellationToken) { var item = GetOrCreateDefinitionItem(reference.Definition); - return _context.OnReferenceFoundAsync(_solution, new SourceReferenceItem(item, reference.SourceSpan, reference.SymbolUsageInfo), cancellationToken); + return _context.OnReferenceFoundAsync(new SourceReferenceItem(item, reference.SourceSpan, reference.SymbolUsageInfo), cancellationToken); } } diff --git a/src/EditorFeatures/Core/FindReferences/FindReferencesCommandHandler.cs b/src/EditorFeatures/Core/FindReferences/FindReferencesCommandHandler.cs index 5d78122c90279..b7c79db5a3fd2 100644 --- a/src/EditorFeatures/Core/FindReferences/FindReferencesCommandHandler.cs +++ b/src/EditorFeatures/Core/FindReferences/FindReferencesCommandHandler.cs @@ -137,7 +137,7 @@ private async Task StreamingFindReferencesAsync( } finally { - await context.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs index 1868225df2c96..7aacd3d6f2dd8 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs @@ -39,17 +39,17 @@ public ValueTask ReportMessageAsync(string message, CancellationToken cancellati public ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) => _underlyingContext.SetSearchTitleAsync(title, cancellationToken); - public ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) - => _underlyingContext.OnReferenceFoundAsync(solution, reference, cancellationToken); + public ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) + => _underlyingContext.OnReferenceFoundAsync(reference, cancellationToken); - public ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) + public ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) { lock (_gate) { _definitions.Add(definition); } - return _underlyingContext.OnDefinitionFoundAsync(solution, definition, cancellationToken); + return _underlyingContext.OnDefinitionFoundAsync(definition, cancellationToken); } public ImmutableArray GetDefinitions() diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs index 64bbf2defe753..fcff3581a1432 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs @@ -43,7 +43,6 @@ public async ValueTask OnReferenceFoundAsync(Document document, TextSpan span, C var documentSpan = await ClassifiedSpansAndHighlightSpanFactory.GetClassifiedDocumentSpanAsync( document, span, cancellationToken).ConfigureAwait(false); await _context.OnReferenceFoundAsync( - document.Project.Solution, new SourceReferenceItem(_definition, documentSpan, SymbolUsageInfo.None), cancellationToken).ConfigureAwait(false); } @@ -117,7 +116,7 @@ private async ValueTask GetDefinitionItemAsync(SymbolGroup group public async ValueTask OnDefinitionFoundAsync(SymbolGroup group, CancellationToken cancellationToken) { var definitionItem = await GetDefinitionItemAsync(group, cancellationToken).ConfigureAwait(false); - await _context.OnDefinitionFoundAsync(_solution, definitionItem, cancellationToken).ConfigureAwait(false); + await _context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); } public async ValueTask OnReferenceFoundAsync(SymbolGroup group, ISymbol definition, ReferenceLocation location, CancellationToken cancellationToken) @@ -128,7 +127,7 @@ public async ValueTask OnReferenceFoundAsync(SymbolGroup group, ISymbol definiti cancellationToken).ConfigureAwait(false); if (referenceItem != null) - await _context.OnReferenceFoundAsync(_solution, referenceItem, cancellationToken).ConfigureAwait(false); + await _context.OnReferenceFoundAsync(referenceItem, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindImplementations.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindImplementations.cs index 2e7ef087b12b9..59e7fcf5ca57f 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindImplementations.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindImplementations.cs @@ -86,7 +86,7 @@ await context.SetSearchTitleAsync( var definitionItem = await implementation.ToClassifiedDefinitionItemAsync( solution, isPrimary: true, includeHiddenLocations: false, FindReferencesSearchOptions.Default, cancellationToken).ConfigureAwait(false); - await context.OnDefinitionFoundAsync(project.Solution, definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); } } diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs index b8dc943548fb3..7beb5b7899ace 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs @@ -33,7 +33,7 @@ await FindLiteralOrSymbolReferencesAsync( document.Project.Solution, definitionTrackingContext.GetDefinitions(), cancellationToken).ConfigureAwait(false); foreach (var definition in thirdPartyDefinitions) - await context.OnDefinitionFoundAsync(document.Project.Solution, definition, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definition, cancellationToken).ConfigureAwait(false); } Task IFindUsagesLSPService.FindReferencesAsync( @@ -222,7 +222,7 @@ private static async Task TryFindLiteralReferencesAsync( ImmutableArray.Create(TextTags.StringLiteral), ImmutableArray.Create(new TaggedText(TextTags.Text, searchTitle))); - await context.OnDefinitionFoundAsync(document.Project.Solution, definition, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definition, cancellationToken).ConfigureAwait(false); var progressAdapter = new FindLiteralsProgressAdapter(context, definition); diff --git a/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs b/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs index 08e0e2ba90986..a733a3d746aae 100644 --- a/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs +++ b/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs @@ -19,11 +19,11 @@ protected FindUsagesContext() public virtual ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) => default; - public virtual ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) => default; + public virtual ValueTask OnCompletedAsync(CancellationToken cancellationToken) => default; - public virtual ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) => default; + public virtual ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) => default; - public virtual ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) => default; + public virtual ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) => default; protected virtual ValueTask ReportProgressAsync(int current, int maximum, CancellationToken cancellationToken) => default; } diff --git a/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs b/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs index 70708b1b8768b..6adc1175310ee 100644 --- a/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs +++ b/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs @@ -60,7 +60,7 @@ public ImmutableArray GetReferences() } } - public override ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) + public override ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) { lock (_gate) { @@ -70,7 +70,7 @@ public override ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionIt return default; } - public override ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) + public override ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) { lock (_gate) { diff --git a/src/EditorFeatures/Core/GoToBase/AbstractGoToBaseService.cs b/src/EditorFeatures/Core/GoToBase/AbstractGoToBaseService.cs index 4cb8db56f2430..060fd12c467c9 100644 --- a/src/EditorFeatures/Core/GoToBase/AbstractGoToBaseService.cs +++ b/src/EditorFeatures/Core/GoToBase/AbstractGoToBaseService.cs @@ -51,14 +51,14 @@ await context.SetSearchTitleAsync( var definitionItem = await sourceDefinition.ToClassifiedDefinitionItemAsync( solution, isPrimary: true, includeHiddenLocations: false, FindReferencesSearchOptions.Default, cancellationToken: cancellationToken).ConfigureAwait(false); - await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); found = true; } else if (baseSymbol.Locations.Any(l => l.IsInMetadata)) { var definitionItem = baseSymbol.ToNonClassifiedDefinitionItem( solution, includeHiddenLocations: true); - await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); found = true; } } diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs index a21988b01f79d..5fdae0d10036a 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs @@ -131,7 +131,7 @@ private bool TryGoToAlternativeLocationIfAlreadyOnDefinition( } return await _streamingPresenter.TryNavigateToOrPresentItemsAsync( - _threadingContext, solution, title, definitions.ToImmutable(), cancellationToken).ConfigureAwait(true); + _threadingContext, solution.Workspace, title, definitions.ToImmutable(), cancellationToken).ConfigureAwait(true); }); } diff --git a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs index 7f7a05f1c94f4..1a3480e5be502 100644 --- a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs +++ b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs @@ -117,7 +117,7 @@ public static bool TryGoToDefinition( var definitions = await GetDefinitionsAsync(symbol, solution, thirdPartyNavigationAllowed, cancellationToken).ConfigureAwait(false); return await streamingPresenter.TryNavigateToOrPresentItemsAsync( - threadingContext, solution, title, definitions, cancellationToken).ConfigureAwait(false); + threadingContext, solution.Workspace, title, definitions, cancellationToken).ConfigureAwait(false); }); } @@ -134,7 +134,7 @@ public static bool TryGoToDefinition( return threadingContext.JoinableTaskFactory.Run(() => streamingPresenter.TryNavigateToOrPresentItemsAsync( - threadingContext, solution, title, definitions, cancellationToken)); + threadingContext, solution.Workspace, title, definitions, cancellationToken)); } } } diff --git a/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs b/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs index d846dfaafa801..b43b1bd9547ea 100644 --- a/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs +++ b/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs @@ -61,12 +61,11 @@ internal static class IStreamingFindUsagesPresenterExtensions public static async Task TryNavigateToOrPresentItemsAsync( this IStreamingFindUsagesPresenter presenter, IThreadingContext threadingContext, - Solution solution, + Workspace workspace, string title, ImmutableArray items, CancellationToken cancellationToken) { - var workspace = solution.Workspace; // Ignore any definitions that we can't navigate to. using var _ = ArrayBuilder.GetInstance(out var definitionsBuilder); @@ -120,11 +119,11 @@ public static async Task TryNavigateToOrPresentItemsAsync( try { foreach (var definition in nonExternalItems) - await context.OnDefinitionFoundAsync(solution, definition, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definition, cancellationToken).ConfigureAwait(false); } finally { - await context.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } diff --git a/src/EditorFeatures/Test/FindReferences/FindReferencesCommandHandlerTests.cs b/src/EditorFeatures/Test/FindReferences/FindReferencesCommandHandlerTests.cs index afae423000e15..38bcb96c02e7b 100644 --- a/src/EditorFeatures/Test/FindReferences/FindReferencesCommandHandlerTests.cs +++ b/src/EditorFeatures/Test/FindReferences/FindReferencesCommandHandlerTests.cs @@ -31,7 +31,7 @@ private class MockFindUsagesContext : FindUsagesContext { public readonly List Result = new List(); - public override ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) + public override ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) { lock (Result) { diff --git a/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs b/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs index 165b47127ea28..683b6ca5ec23f 100644 --- a/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs +++ b/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs @@ -98,11 +98,11 @@ private static async Task VerifyInheritanceMemberAsync(TestWorkspace testWorkspa .ToImmutableArray(); for (var i = 0; i < expectedTargets.Length; i++) { - await VerifyInheritanceTargetAsync(testWorkspace.CurrentSolution, expectedTargets[i], sortedActualTargets[i]); + await VerifyInheritanceTargetAsync(expectedTargets[i], sortedActualTargets[i]); } } - private static async Task VerifyInheritanceTargetAsync(Solution solution, TestInheritanceTargetItem expectedTarget, InheritanceTargetItem actualTarget) + private static async Task VerifyInheritanceTargetAsync(TestInheritanceTargetItem expectedTarget, InheritanceTargetItem actualTarget) { Assert.Equal(expectedTarget.TargetSymbolName, actualTarget.DefinitionItem.DisplayParts.JoinText()); Assert.Equal(expectedTarget.RelationshipToMember, actualTarget.RelationToMember); @@ -119,9 +119,9 @@ private static async Task VerifyInheritanceTargetAsync(Solution solution, TestIn Assert.Equal(expectedDocumentSpans.Length, actualDocumentSpans.Length); for (var i = 0; i < actualDocumentSpans.Length; i++) { - var docSpan = await actualDocumentSpans[i].RehydrateAsync(solution, CancellationToken.None); - Assert.Equal(expectedDocumentSpans[i].SourceSpan, docSpan.SourceSpan); - Assert.Equal(expectedDocumentSpans[i].Document.FilePath, docSpan.Document.FilePath); + var docSpan = await actualDocumentSpans[i].TryRehydrateAsync(CancellationToken.None); + Assert.Equal(expectedDocumentSpans[i].SourceSpan, docSpan.Value.SourceSpan); + Assert.Equal(expectedDocumentSpans[i].Document.FilePath, docSpan.Value.Document.FilePath); } } } diff --git a/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb b/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb index 3db1017743fd2..24ec3b0c3df0e 100644 --- a/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb +++ b/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb @@ -82,7 +82,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(d) New FileNameAndSpans( d.Name, d.AnnotatedSpans(DefinitionKey).ToList())).ToList() - Dim actualDefinitions = Await GetFileNamesAndSpansAsync(solution, + Dim actualDefinitions = Await GetFileNamesAndSpansAsync( context.Definitions.Where(AddressOf context.ShouldShow). SelectMany(Function(d) d.SourceSpans)) @@ -94,7 +94,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(d) New FileNameAndSpans( d.Name, d.SelectedSpans.ToList())).ToList() - Dim actualReferences = Await GetFileNamesAndSpansAsync(solution, + Dim actualReferences = Await GetFileNamesAndSpansAsync( context.References.Select(Function(r) r.SourceSpan)) Assert.Equal(expectedReferences, actualReferences) @@ -107,7 +107,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(d) New FileNameAndSpans( d.Name, d.AnnotatedSpans(key).ToList())).ToList() Dim valueUsageInfoField = key.Substring(ValueUsageInfoKey.Length) - Dim actual = Await GetFileNamesAndSpansAsync(solution, + Dim actual = Await GetFileNamesAndSpansAsync( context.References.Where(Function(r) r.SymbolUsageInfo.ValueUsageInfoOpt?.ToString() = valueUsageInfoField).Select(Function(r) r.SourceSpan)) Assert.Equal(expected, actual) @@ -121,7 +121,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(d) New FileNameAndSpans( d.Name, d.AnnotatedSpans(key).ToList())).ToList() Dim typeOrNamespaceUsageInfoFieldNames = key.Substring(TypeOrNamespaceUsageInfoKey.Length).Split(","c).Select(Function(s) s.Trim) - Dim actual = Await GetFileNamesAndSpansAsync(solution, + Dim actual = Await GetFileNamesAndSpansAsync( context.References.Where(Function(r) Return r.SymbolUsageInfo.TypeOrNamespaceUsageInfoOpt IsNot Nothing AndAlso r.SymbolUsageInfo.TypeOrNamespaceUsageInfoOpt.ToString().Split(","c).Select(Function(s) s.Trim).SetEquals(typeOrNamespaceUsageInfoFieldNames) @@ -140,7 +140,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences OrderBy(Function(d) d.Name). Select(Function(d) New FileNameAndSpans( d.Name, d.AnnotatedSpans(annotationKey).ToList())).ToList() - Dim actual = Await GetFileNamesAndSpansAsync(solution, + Dim actual = Await GetFileNamesAndSpansAsync( context.References.Where(Function(r) Dim actualValue As String = Nothing If r.AdditionalProperties.TryGetValue(propertyName, actualValue) Then @@ -177,16 +177,16 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Return additionalPropertiesMap End Function - Private Shared Async Function GetFileNamesAndSpansAsync(solution As Solution, items As IEnumerable(Of SerializableDocumentSpan)) As Task(Of List(Of FileNameAndSpans)) - Dim dict = New Dictionary(Of Document, List(Of SerializableDocumentSpan)) + Private Shared Async Function GetFileNamesAndSpansAsync(items As IEnumerable(Of DocumentIdSpan)) As Task(Of List(Of FileNameAndSpans)) + Dim dict = New Dictionary(Of Document, List(Of DocumentIdSpan)) For Each item In items - Dim docSpan = Await item.RehydrateAsync(solution, CancellationToken.None) + Dim docSpan = Await item.TryRehydrateAsync(CancellationToken.None) - Dim list As List(Of SerializableDocumentSpan) = Nothing - If Not dict.TryGetValue(docSpan.Document, list) Then - list = New List(Of SerializableDocumentSpan)() - dict.Add(docSpan.Document, list) + Dim list As List(Of DocumentIdSpan) = Nothing + If Not dict.TryGetValue(docSpan.Value.Document, list) Then + list = New List(Of DocumentIdSpan)() + dict.Add(docSpan.Value.Document, list) End If list.Add(item) @@ -196,7 +196,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(g) GetFileNameAndSpans(g.Key, g.Value)).ToList() End Function - Private Shared Function GetFileNameAndSpans(document As Document, items As List(Of SerializableDocumentSpan)) As FileNameAndSpans + Private Shared Function GetFileNameAndSpans(document As Document, items As List(Of DocumentIdSpan)) As FileNameAndSpans Return New FileNameAndSpans( document.Name, items.Select(Function(i) i.SourceSpan).OrderBy(Function(s) s.Start).Distinct().ToList()) @@ -244,7 +244,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Return definition.DisplayIfNoReferences End Function - Public Overrides Function OnDefinitionFoundAsync(solution As Solution, definition As DefinitionItem, cancellationToken As CancellationToken) As ValueTask + Public Overrides Function OnDefinitionFoundAsync(definition As DefinitionItem, cancellationToken As CancellationToken) As ValueTask SyncLock gate Me.Definitions.Add(definition) End SyncLock @@ -252,7 +252,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Return Nothing End Function - Public Overrides Function OnReferenceFoundAsync(solution As Solution, reference As SourceReferenceItem, cancellationToken As CancellationToken) As ValueTask + Public Overrides Function OnReferenceFoundAsync(reference As SourceReferenceItem, cancellationToken As CancellationToken) As ValueTask SyncLock gate References.Add(reference) End SyncLock diff --git a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb index a9bb26b18d608..f47e28735d89f 100644 --- a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb +++ b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb @@ -91,8 +91,8 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition For Each location In items For Each ss In location.SourceSpans - Dim docSpan = Await ss.RehydrateAsync(solution, CancellationToken.None) - actualLocations.Add(New FilePathAndSpan(docSpan.Document.FilePath, docSpan.SourceSpan)) + Dim docSpan = Await ss.TryRehydrateAsync(CancellationToken.None) + actualLocations.Add(New FilePathAndSpan(docSpan.Value.Document.FilePath, docSpan.Value.SourceSpan)) Next Next diff --git a/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb b/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb index 61eb62295da93..77edf70396bac 100644 --- a/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb +++ b/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb @@ -35,8 +35,8 @@ Friend Class GoToHelpers For Each definition In context.GetDefinitions() For Each sourceSpan In definition.SourceSpans - Dim docSpan = Await sourceSpan.RehydrateAsync(solution, CancellationToken.None) - actualDefinitions.Add(New FilePathAndSpan(docSpan.Document.FilePath, docSpan.SourceSpan)) + Dim docSpan = Await sourceSpan.TryRehydrateAsync(CancellationToken.None) + actualDefinitions.Add(New FilePathAndSpan(docSpan.Value.Document.FilePath, docSpan.Value.SourceSpan)) Next Next actualDefinitions.Sort() diff --git a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb index 321dcfdcf417d..de4c825d85281 100644 --- a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb +++ b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb @@ -26,7 +26,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers Return SpecializedTasks.True End Function - Public Function WouldNavigateToSymbolAsync(definitionItem As DefinitionItem, solution As Solution, cancellationToken As CancellationToken) As Task(Of (filePath As String, lineNumber As Integer, charOffset As Integer)?) Implements ISymbolNavigationService.WouldNavigateToSymbolAsync + Public Function WouldNavigateToSymbolAsync(definitionItem As DefinitionItem, cancellationToken As CancellationToken) As Task(Of (filePath As String, lineNumber As Integer, charOffset As Integer)?) Implements ISymbolNavigationService.WouldNavigateToSymbolAsync _wouldNavigateToSymbol = True Return Task.FromResult(Of (filePath As String, lineNumber As Integer, charOffset As Integer)?)(Nothing) End Function diff --git a/src/EditorFeatures/TestUtilities2/Utilities/MockSymbolNavigationServiceProvider.vb b/src/EditorFeatures/TestUtilities2/Utilities/MockSymbolNavigationServiceProvider.vb index 48362c32bcb6e..dc126a7372e26 100644 --- a/src/EditorFeatures/TestUtilities2/Utilities/MockSymbolNavigationServiceProvider.vb +++ b/src/EditorFeatures/TestUtilities2/Utilities/MockSymbolNavigationServiceProvider.vb @@ -40,7 +40,6 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities Public TrySymbolNavigationNotifyReturnValue As Boolean Public WouldNavigateToSymbolProvidedDefinitionItem As DefinitionItem - Public WouldNavigateToSymbolProvidedSolution As Solution Public NavigationFilePathReturnValue As String = String.Empty Public NavigationLineNumberReturnValue As Integer Public NavigationCharOffsetReturnValue As Integer @@ -64,10 +63,8 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities Public Function WouldNavigateToSymbolAsync( definitionItem As DefinitionItem, - solution As Solution, cancellationToken As CancellationToken) As Task(Of (filePath As String, lineNumber As Integer, charOffset As Integer)?) Implements ISymbolNavigationService.WouldNavigateToSymbolAsync Me.WouldNavigateToSymbolProvidedDefinitionItem = definitionItem - Me.WouldNavigateToSymbolProvidedSolution = solution Return Task.FromResult(Of (filePath As String, lineNumber As Integer, charOffset As Integer)?)((Me.NavigationFilePathReturnValue, Me.NavigationLineNumberReturnValue, Me.NavigationCharOffsetReturnValue)) End Function diff --git a/src/Features/Core/Portable/DocumentIdSpan.cs b/src/Features/Core/Portable/DocumentIdSpan.cs new file mode 100644 index 0000000000000..285d292e6e229 --- /dev/null +++ b/src/Features/Core/Portable/DocumentIdSpan.cs @@ -0,0 +1,42 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Text; + +namespace Microsoft.CodeAnalysis +{ + internal readonly struct DocumentIdSpan + { + public Workspace Workspace { get; } + public DocumentId DocumentId { get; } + public TextSpan SourceSpan { get; } + + public DocumentIdSpan(DocumentSpan documentSpan) + : this(documentSpan.Document, documentSpan.SourceSpan) + { + } + + public DocumentIdSpan(Document document, TextSpan sourceSpan) + : this(document.Project.Solution.Workspace, document.Id, sourceSpan) + { + } + + public DocumentIdSpan(Workspace workspace, DocumentId documentId, TextSpan sourceSpan) + { + Workspace = workspace; + DocumentId = documentId; + SourceSpan = sourceSpan; + } + + public async Task TryRehydrateAsync(CancellationToken cancellationToken) + { + var solution = Workspace.CurrentSolution; + var document = solution.GetDocument(DocumentId) ?? + await solution.GetSourceGeneratedDocumentAsync(DocumentId, cancellationToken).ConfigureAwait(false); + return document == null ? null : new DocumentSpan(document, SourceSpan); + } + } +} diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs index 3733eb6551f0a..fcb82a43e6d4b 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs @@ -45,8 +45,9 @@ public DefaultDefinitionItem( // was created against (and it will throw if is passed a different solution that it can't // find the document in). Because we are using .CurrentSolution here, we need to be resilient // to the possibility that we may no longer be able to find/navigate to this document. - var solution = Workspace.CurrentSolution; - var documentId = SourceSpans[0].DocumentId; + var span = SourceSpans[0]; + var solution = span.Workspace.CurrentSolution; + var documentId = span.DocumentId; var document = solution.GetDocument(documentId) ?? await solution.GetSourceGeneratedDocumentAsync(documentId, cancellationToken).ConfigureAwait(false); return document == null ? null : new DocumentSpan(document, SourceSpans[0].SourceSpan); diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.cs index 7c3657a04e0d4..5958cb7f40d10 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.cs @@ -95,7 +95,7 @@ internal abstract partial class DefinitionItem /// Additional locations to present in the UI. A definition may have multiple locations /// for cases like partial types/members. /// - public ImmutableArray SourceSpans { get; } + public ImmutableArray SourceSpans { get; } /// /// Whether or not this definition should be presented if we never found any references to @@ -111,15 +111,6 @@ internal abstract partial class DefinitionItem internal abstract bool IsExternal { get; } - /// - /// The workspace containing the location of the for this definition item. - /// Definitions may be in different workspaces, including a different workspace than where a command - /// was originally invoked from. For example, when using metadata-as-source symbols (and their definitions - /// and references) may be found in different workspaces (like the metadata-as-source-workspace and the - /// primary/vs workspace). - /// - protected readonly Workspace Workspace; - // F# uses this protected DefinitionItem( ImmutableArray tags, @@ -155,7 +146,7 @@ protected DefinitionItem( DisplayParts = displayParts; NameDisplayParts = nameDisplayParts.IsDefaultOrEmpty ? displayParts : nameDisplayParts; OriginationParts = originationParts.NullToEmpty(); - SourceSpans = sourceSpans.NullToEmpty().SelectAsArray(ss => SerializableDocumentSpan.Dehydrate(ss)); + SourceSpans = sourceSpans.NullToEmpty().SelectAsArray(ss => new DocumentIdSpan(ss)); Properties = properties ?? ImmutableDictionary.Empty; DisplayableProperties = displayableProperties ?? ImmutableDictionary.Empty; DisplayIfNoReferences = displayIfNoReferences; @@ -165,8 +156,6 @@ protected DefinitionItem( Contract.ThrowIfFalse(Properties.ContainsKey(MetadataSymbolOriginatingProjectIdGuid)); Contract.ThrowIfFalse(Properties.ContainsKey(MetadataSymbolOriginatingProjectIdDebugName)); } - - Workspace = sourceSpans.FirstOrDefault().Document?.Project.Solution.Workspace; } [Obsolete("Override CanNavigateToAsync instead", error: false)] diff --git a/src/Features/Core/Portable/FindUsages/IFindUsagesContext.cs b/src/Features/Core/Portable/FindUsages/IFindUsagesContext.cs index 40621c114592e..aa818a48152e9 100644 --- a/src/Features/Core/Portable/FindUsages/IFindUsagesContext.cs +++ b/src/Features/Core/Portable/FindUsages/IFindUsagesContext.cs @@ -27,7 +27,7 @@ internal interface IFindUsagesContext /// ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken); - ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken); - ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken); + ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken); + ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken); } } diff --git a/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs b/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs index be62670f4abd7..f60a71f6d71e0 100644 --- a/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs +++ b/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs @@ -108,14 +108,14 @@ public async ValueTask OnDefinitionFoundAsync(SerializableDefinitionItem definit _idToDefinition.Add(id, rehydrated); } - await _context.OnDefinitionFoundAsync(_solution, rehydrated, cancellationToken).ConfigureAwait(false); + await _context.OnDefinitionFoundAsync(rehydrated, cancellationToken).ConfigureAwait(false); } public async ValueTask OnReferenceFoundAsync(SerializableSourceReferenceItem reference, CancellationToken cancellationToken) { var rehydrated = await reference.RehydrateAsync(_solution, GetDefinition(reference.DefinitionId), cancellationToken).ConfigureAwait(false); - await _context.OnReferenceFoundAsync(_solution, rehydrated, cancellationToken).ConfigureAwait(false); + await _context.OnReferenceFoundAsync(rehydrated, cancellationToken).ConfigureAwait(false); } private DefinitionItem GetDefinition(int definitionId) @@ -214,7 +214,7 @@ public static SerializableDefinitionItem Dehydrate(int id, DefinitionItem item) item.DisplayParts, item.NameDisplayParts, item.OriginationParts, - item.SourceSpans, + item.SourceSpans.SelectAsArray(ss => new SerializableDocumentSpan(ss.DocumentId, ss.SourceSpan)), item.Properties, item.DisplayableProperties, item.DisplayIfNoReferences); @@ -264,7 +264,7 @@ public SerializableSourceReferenceItem( public static SerializableSourceReferenceItem Dehydrate(int definitionId, SourceReferenceItem item) => new(definitionId, - item.SourceSpan, + new SerializableDocumentSpan(item.SourceSpan.DocumentId, item.SourceSpan.SourceSpan), item.SymbolUsageInfo, item.AdditionalProperties); diff --git a/src/Features/Core/Portable/FindUsages/SourceReferenceItem.cs b/src/Features/Core/Portable/FindUsages/SourceReferenceItem.cs index 80a5c963f3a20..d0be9b9772497 100644 --- a/src/Features/Core/Portable/FindUsages/SourceReferenceItem.cs +++ b/src/Features/Core/Portable/FindUsages/SourceReferenceItem.cs @@ -22,7 +22,7 @@ internal sealed class SourceReferenceItem /// /// The location of the source item. /// - public SerializableDocumentSpan SourceSpan { get; } + public DocumentIdSpan SourceSpan { get; } /// /// If this reference is a location where the definition is written to. @@ -50,7 +50,7 @@ private SourceReferenceItem( bool isWrittenTo) { Definition = definition; - SourceSpan = SerializableDocumentSpan.Dehydrate(sourceSpan); + SourceSpan = new DocumentIdSpan(sourceSpan); SymbolUsageInfo = symbolUsageInfo; IsWrittenTo = isWrittenTo; AdditionalProperties = additionalProperties ?? ImmutableDictionary.Empty; diff --git a/src/Features/Core/Portable/Navigation/DefaultSymbolNavigationService.cs b/src/Features/Core/Portable/Navigation/DefaultSymbolNavigationService.cs index 88732fd717c39..b566ac9fff37f 100644 --- a/src/Features/Core/Portable/Navigation/DefaultSymbolNavigationService.cs +++ b/src/Features/Core/Portable/Navigation/DefaultSymbolNavigationService.cs @@ -20,7 +20,7 @@ public Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project project => SpecializedTasks.False; public Task<(string filePath, int lineNumber, int charOffset)?> WouldNavigateToSymbolAsync( - DefinitionItem definitionItem, Solution solution, CancellationToken cancellationToken) + DefinitionItem definitionItem, CancellationToken cancellationToken) { return Task.FromResult<(string filePath, int lineNumber, int charOffset)?>(null); } diff --git a/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs b/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs index 079d919b1046a..858af9260229e 100644 --- a/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs +++ b/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs @@ -29,6 +29,6 @@ internal interface ISymbolNavigationService : IWorkspaceService /// True if the navigation would be handled. Task<(string filePath, int lineNumber, int charOffset)?> WouldNavigateToSymbolAsync( - DefinitionItem definitionItem, Solution solution, CancellationToken cancellationToken); + DefinitionItem definitionItem, CancellationToken cancellationToken); } } diff --git a/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs b/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs index 84be390e4455e..df575fce6ace0 100644 --- a/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs +++ b/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs @@ -86,10 +86,10 @@ public FindUsagesLSPContext( } // After all definitions/references have been found, wait here until all results have been reported. - public override async ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) + public override async ValueTask OnCompletedAsync(CancellationToken cancellationToken) => await _workQueue.WaitUntilCurrentBatchCompletesAsync().ConfigureAwait(false); - public override async ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) + public override async ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) { using (await _semaphore.DisposableWaitAsync(cancellationToken).ConfigureAwait(false)) { @@ -124,7 +124,7 @@ public override async ValueTask OnDefinitionFoundAsync(Solution solution, Defini } } - public override async ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) + public override async ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) { using (await _semaphore.DisposableWaitAsync(cancellationToken).ConfigureAwait(false)) { @@ -133,8 +133,11 @@ public override async ValueTask OnReferenceFoundAsync(Solution solution, SourceR if (!_definitionToId.TryGetValue(reference.Definition, out var definitionId)) return; - var documentSpan = await reference.SourceSpan.RehydrateAsync(solution, cancellationToken).ConfigureAwait(false); - var document = documentSpan.Document; + var documentSpan = await reference.SourceSpan.TryRehydrateAsync(cancellationToken).ConfigureAwait(false); + if (documentSpan == null) + return; + + var document = documentSpan.Value.Document; // If this is reference to the same physical location we've already reported, just // filter this out. it will clutter the UI to show the same places. @@ -168,7 +171,7 @@ public override async ValueTask OnReferenceFoundAsync(Solution solution, SourceR int? definitionId, Document document, int position, - SerializableDocumentSpan? serializableDocumentSpan, + DocumentIdSpan? serializableDocumentSpan, ImmutableDictionary properties, IMetadataAsSourceFileService metadataAsSourceFileService, ClassifiedTextElement? definitionText, @@ -178,8 +181,8 @@ public override async ValueTask OnReferenceFoundAsync(Solution solution, SourceR CancellationToken cancellationToken) { var documentSpan = serializableDocumentSpan == null - ? default - : await serializableDocumentSpan.Value.RehydrateAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); + ? null + : await serializableDocumentSpan.Value.TryRehydrateAsync(cancellationToken).ConfigureAwait(false); var location = await ComputeLocationAsync(document, position, documentSpan, metadataAsSourceFileService, cancellationToken).ConfigureAwait(false); // Getting the text for the Text property. If we somehow can't compute the text, that means we're probably dealing with a metadata @@ -210,10 +213,10 @@ public override async ValueTask OnReferenceFoundAsync(Solution solution, SourceR result.Location = location; } - if (documentSpan.Document != null) + if (documentSpan != null) { - result.DocumentName = documentSpan.Document.Name; - result.ProjectName = documentSpan.Document.Project.Name; + result.DocumentName = documentSpan.Value.Document.Name; + result.ProjectName = documentSpan.Value.Document.Project.Name; } if (properties.TryGetValue(AbstractReferenceFinder.ContainingMemberInfoPropertyName, out var referenceContainingMember)) @@ -228,15 +231,15 @@ public override async ValueTask OnReferenceFoundAsync(Solution solution, SourceR static async Task ComputeLocationAsync( Document document, int position, - DocumentSpan documentSpan, + DocumentSpan? documentSpan, IMetadataAsSourceFileService metadataAsSourceFileService, CancellationToken cancellationToken) { // If we have no document span, our location may be in metadata. - if (documentSpan != default) + if (documentSpan != null) { // We do have a document span, so compute location normally. - return await ProtocolConversions.DocumentSpanToLocationAsync(documentSpan, cancellationToken).ConfigureAwait(false); + return await ProtocolConversions.DocumentSpanToLocationAsync(documentSpan.Value, cancellationToken).ConfigureAwait(false); } // If we have no document span, our location may be in metadata or may be a namespace. @@ -276,19 +279,19 @@ public override async ValueTask OnReferenceFoundAsync(Solution solution, SourceR static async Task ComputeTextAsync( int id, int? definitionId, - DocumentSpan documentSpan, + DocumentSpan? documentSpan, ClassifiedTextElement? definitionText, bool isWrittenTo, CancellationToken cancellationToken) { // General case - if (documentSpan != default) + if (documentSpan != null) { var classifiedSpansAndHighlightSpan = await ClassifiedSpansAndHighlightSpanFactory.ClassifyAsync( - documentSpan, cancellationToken).ConfigureAwait(false); + documentSpan.Value, cancellationToken).ConfigureAwait(false); var classifiedSpans = classifiedSpansAndHighlightSpan.ClassifiedSpans; - var docText = await documentSpan.Document.GetTextAsync(cancellationToken).ConfigureAwait(false); - var classifiedTextRuns = GetClassifiedTextRuns(id, definitionId, documentSpan, isWrittenTo, classifiedSpans, docText); + var docText = await documentSpan.Value.Document.GetTextAsync(cancellationToken).ConfigureAwait(false); + var classifiedTextRuns = GetClassifiedTextRuns(id, definitionId, documentSpan.Value, isWrittenTo, classifiedSpans, docText); return new ClassifiedTextElement(classifiedTextRuns.ToArray()); } diff --git a/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs b/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs index f9c2d6a47afe0..e36ac13036669 100644 --- a/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs @@ -63,7 +63,7 @@ public FindAllReferencesHandler( // Finds the references for the symbol at the specific position in the document, reporting them via streaming to the LSP client. await findUsagesService.FindReferencesAsync(document, position, findUsagesContext, cancellationToken).ConfigureAwait(false); - await findUsagesContext.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); + await findUsagesContext.OnCompletedAsync(cancellationToken).ConfigureAwait(false); return progress.GetValues(); } diff --git a/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs b/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs index 3bacd732576ca..80951dc42f670 100644 --- a/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs @@ -46,20 +46,22 @@ public FindImplementationsHandler() var findUsagesContext = new SimpleFindUsagesContext(); await FindImplementationsAsync(findUsagesService, document, position, findUsagesContext, cancellationToken).ConfigureAwait(false); - var solution = document.Project.Solution; foreach (var definition in findUsagesContext.GetDefinitions()) { var text = definition.GetClassifiedText(); foreach (var sourceSpan in definition.SourceSpans) { - var span = await sourceSpan.RehydrateAsync(solution, cancellationToken).ConfigureAwait(false); + var span = await sourceSpan.TryRehydrateAsync(cancellationToken).ConfigureAwait(false); + if (span == null) + continue; + if (context.ClientCapabilities?.HasVisualStudioLspCapability() == true) { - locations.AddIfNotNull(await ProtocolConversions.DocumentSpanToLocationWithTextAsync(span, text, cancellationToken).ConfigureAwait(false)); + locations.AddIfNotNull(await ProtocolConversions.DocumentSpanToLocationWithTextAsync(span.Value, text, cancellationToken).ConfigureAwait(false)); } else { - locations.AddIfNotNull(await ProtocolConversions.DocumentSpanToLocationAsync(span, cancellationToken).ConfigureAwait(false)); + locations.AddIfNotNull(await ProtocolConversions.DocumentSpanToLocationAsync(span.Value, cancellationToken).ConfigureAwait(false)); } } } diff --git a/src/Tools/ExternalAccess/Debugger/DebuggerFindReferencesService.cs b/src/Tools/ExternalAccess/Debugger/DebuggerFindReferencesService.cs index c1c2aa6661fde..c7526f1d34bc8 100644 --- a/src/Tools/ExternalAccess/Debugger/DebuggerFindReferencesService.cs +++ b/src/Tools/ExternalAccess/Debugger/DebuggerFindReferencesService.cs @@ -48,7 +48,7 @@ public async Task FindSymbolReferencesAsync(ISymbol symbol, Project project, Can } finally { - await context.OnCompletedAsync(project.Solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } } diff --git a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs index 6d5d0b1727d1f..e8bf8c1cb9041 100644 --- a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs +++ b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs @@ -11,13 +11,11 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.FSharp.Internal.Editor.FindUsage { internal class FSharpFindUsagesContext : IFSharpFindUsagesContext { - private readonly Solution _solution; private readonly IFindUsagesContext _context; private readonly CancellationToken _cancellationToken; - public FSharpFindUsagesContext(Solution solution, IFindUsagesContext context, CancellationToken cancellationToken) + public FSharpFindUsagesContext(IFindUsagesContext context, CancellationToken cancellationToken) { - _solution = solution; _context = context; _cancellationToken = cancellationToken; } @@ -26,12 +24,12 @@ public FSharpFindUsagesContext(Solution solution, IFindUsagesContext context, Ca public Task OnDefinitionFoundAsync(FSharp.FindUsages.FSharpDefinitionItem definition) { - return _context.OnDefinitionFoundAsync(_solution, definition.RoslynDefinitionItem, _cancellationToken).AsTask(); + return _context.OnDefinitionFoundAsync(definition.RoslynDefinitionItem, _cancellationToken).AsTask(); } public Task OnReferenceFoundAsync(FSharp.FindUsages.FSharpSourceReferenceItem reference) { - return _context.OnReferenceFoundAsync(_solution, reference.RoslynSourceReferenceItem, _cancellationToken).AsTask(); + return _context.OnReferenceFoundAsync(reference.RoslynSourceReferenceItem, _cancellationToken).AsTask(); } public Task ReportMessageAsync(string message) diff --git a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesService.cs b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesService.cs index 8a3ccefe71b52..623dda3cb550c 100644 --- a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesService.cs +++ b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesService.cs @@ -25,9 +25,9 @@ public FSharpFindUsagesService(IFSharpFindUsagesService service) => _service = service; public Task FindImplementationsAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _service.FindImplementationsAsync(document, position, new FSharpFindUsagesContext(document.Project.Solution, context, cancellationToken)); + => _service.FindImplementationsAsync(document, position, new FSharpFindUsagesContext(context, cancellationToken)); public Task FindReferencesAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _service.FindReferencesAsync(document, position, new FSharpFindUsagesContext(document.Project.Solution, context, cancellationToken)); + => _service.FindReferencesAsync(document, position, new FSharpFindUsagesContext(context, cancellationToken)); } } diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs index 6e78491cf7c36..95fe86c834930 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs @@ -303,42 +303,44 @@ public sealed override ValueTask SetSearchTitleAsync(string title, CancellationT return default; } - public sealed override async ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) + public sealed override async ValueTask OnCompletedAsync(CancellationToken cancellationToken) { - await OnCompletedAsyncWorkerAsync(solution, cancellationToken).ConfigureAwait(false); + await OnCompletedAsyncWorkerAsync(cancellationToken).ConfigureAwait(false); _tableDataSink.IsStable = true; } - protected abstract Task OnCompletedAsyncWorkerAsync(Solution solution, CancellationToken cancellationToken); + protected abstract Task OnCompletedAsyncWorkerAsync(CancellationToken cancellationToken); - public sealed override ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) + public sealed override ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) { lock (Gate) { Definitions.Add(definition); } - return OnDefinitionFoundWorkerAsync(solution, definition, cancellationToken); + return OnDefinitionFoundWorkerAsync(definition, cancellationToken); } - protected abstract ValueTask OnDefinitionFoundWorkerAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken); + protected abstract ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem definition, CancellationToken cancellationToken); protected async Task TryCreateDocumentSpanEntryAsync( - Solution solution, RoslynDefinitionBucket definitionBucket, - SerializableDocumentSpan serializableDocumentSpan, + DocumentIdSpan idSpan, HighlightSpanKind spanKind, SymbolUsageInfo symbolUsageInfo, ImmutableDictionary additionalProperties, CancellationToken cancellationToken) { - var documentSpan = await serializableDocumentSpan.RehydrateAsync(solution, cancellationToken).ConfigureAwait(false); - var document = documentSpan.Document; + var documentSpan = await idSpan.TryRehydrateAsync(cancellationToken).ConfigureAwait(false); + if (documentSpan == null) + return null; + + var document = documentSpan.Value.Document; var sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); - var (excerptResult, lineText) = await ExcerptAsync(sourceText, documentSpan, cancellationToken).ConfigureAwait(false); + var (excerptResult, lineText) = await ExcerptAsync(sourceText, documentSpan.Value, cancellationToken).ConfigureAwait(false); - var mappedDocumentSpan = await AbstractDocumentSpanEntry.TryMapAndGetFirstAsync(documentSpan, sourceText, cancellationToken).ConfigureAwait(false); + var mappedDocumentSpan = await AbstractDocumentSpanEntry.TryMapAndGetFirstAsync(documentSpan.Value, sourceText, cancellationToken).ConfigureAwait(false); if (mappedDocumentSpan == null) { // this will be removed from the result @@ -354,7 +356,7 @@ public sealed override ValueTask OnDefinitionFoundAsync(Solution solution, Defin projectName, projectFlavor, document.FilePath, - documentSpan.SourceSpan, + documentSpan.Value.SourceSpan, spanKind, mappedDocumentSpan.Value, excerptResult, @@ -389,10 +391,10 @@ public sealed override ValueTask OnDefinitionFoundAsync(Solution solution, Defin return (excerptResult, AbstractDocumentSpanEntry.GetLineContainingPosition(sourceText, documentSpan.SourceSpan.Start)); } - public sealed override ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) - => OnReferenceFoundWorkerAsync(solution, reference, cancellationToken); + public sealed override ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) + => OnReferenceFoundWorkerAsync(reference, cancellationToken); - protected abstract ValueTask OnReferenceFoundWorkerAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken); + protected abstract ValueTask OnReferenceFoundWorkerAsync(SourceReferenceItem reference, CancellationToken cancellationToken); protected RoslynDefinitionBucket GetOrCreateDefinitionBucket(DefinitionItem definition, bool expandedByDefault) { diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs index c89af14a7c953..c9163e101ae38 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs @@ -38,16 +38,16 @@ public WithReferencesFindUsagesContext( { } - protected override async ValueTask OnDefinitionFoundWorkerAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) + protected override async ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem definition, CancellationToken cancellationToken) { // If this is a definition we always want to show, then create entries for all the declaration locations // immediately. Otherwise, we'll create them on demand when we hear about references for this // definition. if (definition.DisplayIfNoReferences) - await AddDeclarationEntriesAsync(solution, definition, expandedByDefault: true, cancellationToken).ConfigureAwait(false); + await AddDeclarationEntriesAsync(definition, expandedByDefault: true, cancellationToken).ConfigureAwait(false); } - private async Task AddDeclarationEntriesAsync(Solution solution, DefinitionItem definition, bool expandedByDefault, CancellationToken cancellationToken) + private async Task AddDeclarationEntriesAsync(DefinitionItem definition, bool expandedByDefault, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -70,7 +70,6 @@ private async Task AddDeclarationEntriesAsync(Solution solution, DefinitionItem foreach (var declarationLocation in definition.SourceSpans) { var definitionEntry = await TryCreateDocumentSpanEntryAsync( - solution, definitionBucket, declarationLocation, HighlightSpanKind.Definition, @@ -110,15 +109,13 @@ private bool HasDeclarationEntries(DefinitionItem definition) } } - protected override ValueTask OnReferenceFoundWorkerAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) + protected override ValueTask OnReferenceFoundWorkerAsync(SourceReferenceItem reference, CancellationToken cancellationToken) { // Normal references go into both sets of entries. We ensure an entry for the definition, and an entry // for the reference itself. return OnEntryFoundAsync( - solution, reference.Definition, bucket => TryCreateDocumentSpanEntryAsync( - solution, bucket, reference.SourceSpan, reference.IsWrittenTo ? HighlightSpanKind.WrittenReference : HighlightSpanKind.Reference, @@ -132,7 +129,6 @@ protected override ValueTask OnReferenceFoundWorkerAsync(Solution solution, Sour } private async ValueTask OnEntryFoundAsync( - Solution solution, DefinitionItem definition, Func> createEntryAsync, bool addToEntriesWhenGroupingByDefinition, @@ -147,7 +143,7 @@ private async ValueTask OnEntryFoundAsync( // that we haven't created any declaration entries for (i.e. because it had DisplayIfNoReferences = // false). Because we've now found a reference, we want to make sure all its declaration entries are // added. - await AddDeclarationEntriesAsync(solution, definition, expandedByDefault, cancellationToken).ConfigureAwait(false); + await AddDeclarationEntriesAsync(definition, expandedByDefault, cancellationToken).ConfigureAwait(false); // First find the bucket corresponding to our definition. var definitionBucket = GetOrCreateDefinitionBucket(definition, expandedByDefault); @@ -175,22 +171,22 @@ private async ValueTask OnEntryFoundAsync( NotifyChange(); } - protected override async Task OnCompletedAsyncWorkerAsync(Solution solution, CancellationToken cancellationToken) + protected override async Task OnCompletedAsyncWorkerAsync(CancellationToken cancellationToken) { // Now that we know the search is over, create and display any error messages // for definitions that were not found. - await CreateMissingReferenceEntriesIfNecessaryAsync(solution, cancellationToken).ConfigureAwait(false); - await CreateNoResultsFoundEntryIfNecessaryAsync(solution, cancellationToken).ConfigureAwait(false); + await CreateMissingReferenceEntriesIfNecessaryAsync(cancellationToken).ConfigureAwait(false); + await CreateNoResultsFoundEntryIfNecessaryAsync(cancellationToken).ConfigureAwait(false); } - private async Task CreateMissingReferenceEntriesIfNecessaryAsync(Solution solution, CancellationToken cancellationToken) + private async Task CreateMissingReferenceEntriesIfNecessaryAsync(CancellationToken cancellationToken) { - await CreateMissingReferenceEntriesIfNecessaryAsync(solution, whenGroupingByDefinition: true, cancellationToken).ConfigureAwait(false); - await CreateMissingReferenceEntriesIfNecessaryAsync(solution, whenGroupingByDefinition: false, cancellationToken).ConfigureAwait(false); + await CreateMissingReferenceEntriesIfNecessaryAsync(whenGroupingByDefinition: true, cancellationToken).ConfigureAwait(false); + await CreateMissingReferenceEntriesIfNecessaryAsync(whenGroupingByDefinition: false, cancellationToken).ConfigureAwait(false); } private async Task CreateMissingReferenceEntriesIfNecessaryAsync( - Solution solution, bool whenGroupingByDefinition, CancellationToken cancellationToken) + bool whenGroupingByDefinition, CancellationToken cancellationToken) { // Go through and add dummy entries for any definitions that // that we didn't find any references for. @@ -201,7 +197,6 @@ private async Task CreateMissingReferenceEntriesIfNecessaryAsync( if (definition.IsExternal) { await OnEntryFoundAsync( - solution, definition, bucket => SimpleMessageEntry.CreateAsync(bucket, bucket, ServicesVSResources.External_reference_found)!, addToEntriesWhenGroupingByDefinition: whenGroupingByDefinition, @@ -216,7 +211,6 @@ await OnEntryFoundAsync( // We'll place this under a single bucket called "Symbols without references" and we'll allow // the user to navigate on that text entry to that definition if possible. await OnEntryFoundAsync( - solution, SymbolsWithoutReferencesDefinitionItem, bucket => SimpleMessageEntry.CreateAsync( definitionBucket: bucket, @@ -268,7 +262,7 @@ private ImmutableArray GetDefinitionsToCreateMissingReferenceIte } } - private async Task CreateNoResultsFoundEntryIfNecessaryAsync(Solution solution, CancellationToken cancellationToken) + private async Task CreateNoResultsFoundEntryIfNecessaryAsync(CancellationToken cancellationToken) { bool noDefinitions; lock (Gate) @@ -280,7 +274,6 @@ private async Task CreateNoResultsFoundEntryIfNecessaryAsync(Solution solution, { // Create a fake definition/reference called "search found no results" await OnEntryFoundAsync( - solution, NoResultsDefinitionItem, bucket => SimpleMessageEntry.CreateAsync(bucket, null, ServicesVSResources.Search_found_no_results)!, addToEntriesWhenGroupingByDefinition: true, diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs index 073d5b326eac5..587c55aa81d07 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs @@ -36,14 +36,14 @@ public WithoutReferencesFindUsagesContext( } // We should never be called in a context where we get references. - protected override ValueTask OnReferenceFoundWorkerAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) + protected override ValueTask OnReferenceFoundWorkerAsync(SourceReferenceItem reference, CancellationToken cancellationToken) => throw new InvalidOperationException(); // Nothing to do on completion. - protected override Task OnCompletedAsyncWorkerAsync(Solution solution, CancellationToken cancellationToken) + protected override Task OnCompletedAsyncWorkerAsync(CancellationToken cancellationToken) => Task.CompletedTask; - protected override async ValueTask OnDefinitionFoundWorkerAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) + protected override async ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem definition, CancellationToken cancellationToken) { var definitionBucket = GetOrCreateDefinitionBucket(definition, expandedByDefault: true); @@ -55,7 +55,7 @@ protected override async ValueTask OnDefinitionFoundWorkerAsync(Solution solutio // definition as what to show. That way we show enough information for things // methods. i.e. we'll show "void TypeName.MethodName(args...)" allowing // the user to see the type the method was created in. - var entry = await TryCreateEntryAsync(solution, definitionBucket, definition, cancellationToken).ConfigureAwait(false); + var entry = await TryCreateEntryAsync(definitionBucket, definition, cancellationToken).ConfigureAwait(false); entries.AddIfNotNull(entry); } else if (definition.SourceSpans.Length == 0) @@ -73,7 +73,6 @@ protected override async ValueTask OnDefinitionFoundWorkerAsync(Solution solutio foreach (var sourceSpan in definition.SourceSpans) { var entry = await TryCreateDocumentSpanEntryAsync( - solution, definitionBucket, sourceSpan, HighlightSpanKind.Definition, @@ -97,14 +96,17 @@ protected override async ValueTask OnDefinitionFoundWorkerAsync(Solution solutio } private async Task TryCreateEntryAsync( - Solution solution, RoslynDefinitionBucket definitionBucket, DefinitionItem definition, CancellationToken cancellationToken) + RoslynDefinitionBucket definitionBucket, DefinitionItem definition, CancellationToken cancellationToken) { - var documentSpan = await definition.SourceSpans[0].RehydrateAsync(solution, cancellationToken).ConfigureAwait(false); - var (guid, projectName, _) = GetGuidAndProjectInfo(documentSpan.Document); - var sourceText = await documentSpan.Document.GetTextAsync(cancellationToken).ConfigureAwait(false); + var documentSpan = await definition.SourceSpans[0].TryRehydrateAsync(cancellationToken).ConfigureAwait(false); + if (documentSpan == null) + return null; + + var (guid, projectName, _) = GetGuidAndProjectInfo(documentSpan.Value.Document); + var sourceText = await documentSpan.Value.Document.GetTextAsync(cancellationToken).ConfigureAwait(false); - var lineText = AbstractDocumentSpanEntry.GetLineContainingPosition(sourceText, documentSpan.SourceSpan.Start); - var mappedDocumentSpan = await AbstractDocumentSpanEntry.TryMapAndGetFirstAsync(documentSpan, sourceText, cancellationToken).ConfigureAwait(false); + var lineText = AbstractDocumentSpanEntry.GetLineContainingPosition(sourceText, documentSpan.Value.SourceSpan.Start); + var mappedDocumentSpan = await AbstractDocumentSpanEntry.TryMapAndGetFirstAsync(documentSpan.Value, sourceText, cancellationToken).ConfigureAwait(false); if (mappedDocumentSpan == null) { // this will be removed from the result diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs index e315b65e3a988..c37ac9c07fccd 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs @@ -46,7 +46,7 @@ public VisualStudioDefinitionsAndReferencesFactory( Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken) { var symbolNavigationService = solution.Workspace.Services.GetRequiredService(); - var result = await symbolNavigationService.WouldNavigateToSymbolAsync(definitionItem, solution, cancellationToken).ConfigureAwait(false); + var result = await symbolNavigationService.WouldNavigateToSymbolAsync(definitionItem, cancellationToken).ConfigureAwait(false); if (result is not var (filePath, lineNumber, charOffset)) return null; diff --git a/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs b/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs index 181b903fc1e0b..5bca469a14289 100644 --- a/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs +++ b/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs @@ -525,7 +525,7 @@ await Task.Run( } finally { - await context.OnCompletedAsync(project.Solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs index a2e1cef8fb8f6..6f0bf4a302fe0 100644 --- a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs +++ b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs @@ -168,13 +168,10 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p AssertIsForeground(); - var solution = project.Solution; - - var definitionItem = symbol.ToNonClassifiedDefinitionItem(solution, includeHiddenLocations: true); + var definitionItem = symbol.ToNonClassifiedDefinitionItem(project.Solution, includeHiddenLocations: true); definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey1, out var rqName); - var result = await TryGetNavigationAPIRequiredArgumentsAsync( - solution, definitionItem, rqName, cancellationToken).ConfigureAwait(true); + var result = await TryGetNavigationAPIRequiredArgumentsAsync(definitionItem, rqName, cancellationToken).ConfigureAwait(true); if (result is not var (hierarchy, itemID, navigationNotify)) return false; @@ -188,23 +185,23 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p } public async Task<(string filePath, int lineNumber, int charOffset)?> WouldNavigateToSymbolAsync( - DefinitionItem definitionItem, Solution solution, CancellationToken cancellationToken) + DefinitionItem definitionItem, CancellationToken cancellationToken) { definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey1, out var rqName1); definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey2, out var rqName2); - return await WouldNotifyToSpecificSymbolAsync(solution, definitionItem, rqName1, cancellationToken).ConfigureAwait(false) ?? - await WouldNotifyToSpecificSymbolAsync(solution, definitionItem, rqName2, cancellationToken).ConfigureAwait(false); + return await WouldNotifyToSpecificSymbolAsync(definitionItem, rqName1, cancellationToken).ConfigureAwait(false) ?? + await WouldNotifyToSpecificSymbolAsync(definitionItem, rqName2, cancellationToken).ConfigureAwait(false); } public async Task<(string filePath, int lineNumber, int charOffset)?> WouldNotifyToSpecificSymbolAsync( - Solution solution, DefinitionItem definitionItem, string? rqName, CancellationToken cancellationToken) + DefinitionItem definitionItem, string? rqName, CancellationToken cancellationToken) { if (rqName == null) return null; var values = await TryGetNavigationAPIRequiredArgumentsAsync( - solution, definitionItem, rqName, cancellationToken).ConfigureAwait(false); + definitionItem, rqName, cancellationToken).ConfigureAwait(false); if (values is not var (hierarchy, itemID, navigationNotify)) return null; @@ -232,7 +229,6 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p } private async Task<(IVsHierarchy hierarchy, uint itemId, IVsSymbolicNavigationNotify navigationNotify)?> TryGetNavigationAPIRequiredArgumentsAsync( - Solution solution, DefinitionItem definitionItem, string? rqName, CancellationToken cancellationToken) @@ -247,8 +243,8 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p using var _ = ArrayBuilder.GetInstance(out var documentsBuilder); foreach (var loc in sourceLocations) { - var docSpan = await loc.RehydrateAsync(solution, cancellationToken).ConfigureAwait(false); - documentsBuilder.AddIfNotNull(docSpan.Document); + var docSpan = await loc.TryRehydrateAsync(cancellationToken).ConfigureAwait(false); + documentsBuilder.AddIfNotNull(docSpan?.Document); } var documents = documentsBuilder.ToImmutable(); diff --git a/src/Workspaces/Remote/ServiceHub/Services/FindUsages/RemoteFindUsagesService.cs b/src/Workspaces/Remote/ServiceHub/Services/FindUsages/RemoteFindUsagesService.cs index ba3fc3b7d4e9b..8ec4923b98d2c 100644 --- a/src/Workspaces/Remote/ServiceHub/Services/FindUsages/RemoteFindUsagesService.cs +++ b/src/Workspaces/Remote/ServiceHub/Services/FindUsages/RemoteFindUsagesService.cs @@ -108,7 +108,7 @@ public ValueTask ReportMessageAsync(string message, CancellationToken cancellati public ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) => _callback.InvokeAsync((callback, cancellationToken) => callback.SetSearchTitleAsync(_callbackId, title, cancellationToken), cancellationToken); - public ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) + public ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) { var id = GetOrAddDefinitionItemId(definition); var dehydratedDefinition = SerializableDefinitionItem.Dehydrate(id, definition); @@ -129,7 +129,7 @@ private int GetOrAddDefinitionItemId(DefinitionItem item) } } - public ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) + public ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) { var definitionItem = GetOrAddDefinitionItemId(reference.Definition); var dehydratedReference = SerializableSourceReferenceItem.Dehydrate(definitionItem, reference); From 023a89ab96045e0f925aa7df97b8d61b4807bb07 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Aug 2021 12:00:02 -0700 Subject: [PATCH 25/42] revert --- .../FindBaseSymbolsCommandHandler.cs | 1 + .../FindDerivedSymbolsCommandHandler.cs | 4 ++-- .../FindReferencesOfOverloadsCommandHandler.cs | 3 +-- .../VSTypeScript/VSTypeScriptFindUsagesService.cs | 4 +++- .../AbstractFindUsagesService.ProgressAdapter.cs | 7 +++---- .../FindReferences/FindReferencesSearchEngine.cs | 2 +- .../FindReferences/NoOpStreamingFindReferencesProgress.cs | 2 +- .../FindReferences/StreamingFindReferencesProgress.cs | 2 +- .../FindSymbols/IStreamingFindReferencesProgress.cs | 2 +- .../Portable/FindSymbols/StreamingProgressCollector.cs | 4 ++-- .../SymbolFinder.FindReferencesServerCallback.cs | 2 +- 11 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs index 2de345905f887..5e2185b61c07a 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs @@ -75,6 +75,7 @@ private async Task StreamingFindBaseSymbolsAsync( var relevantSymbol = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, cancellationToken).ConfigureAwait(false); var overriddenSymbol = relevantSymbol?.symbol.GetOverriddenMember(); + while (overriddenSymbol != null) { if (cancellationToken.IsCancellationRequested) diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs index 2a2049af18f92..6577d0200543a 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs @@ -100,8 +100,8 @@ private async Task FindDerivedSymbolsAsync( if (candidateSymbolProjectPair?.symbol == null) return; - var candidates = await GatherSymbolsAsync( - candidateSymbolProjectPair.Value.symbol, document.Project.Solution, cancellationToken).ConfigureAwait(false); + var candidates = await GatherSymbolsAsync(candidateSymbolProjectPair.Value.symbol, + document.Project.Solution, cancellationToken).ConfigureAwait(false); foreach (var candidate in candidates) { diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs index a0df9102cd7f9..5006710ae5adb 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs @@ -108,7 +108,6 @@ private async Task StreamingFindReferencesAsync( KeyValueLogMessage.Create(LogType.UserAction, m => m["type"] = "streaming"), cancellationToken)) { - var solution = document.Project.Solution; var symbolsToLookup = new List(); foreach (var curSymbol in symbol.ContainingType.GetMembers() @@ -123,7 +122,7 @@ private async Task StreamingFindReferencesAsync( foreach (var sym in SymbolFinder.FindSimilarSymbols(curSymbol, compilation, cancellationToken)) { // assumption here is, that FindSimilarSymbols returns symbols inside same project - var symbolsToAdd = await GatherSymbolsAsync(sym, solution, cancellationToken).ConfigureAwait(false); + var symbolsToAdd = await GatherSymbolsAsync(sym, document.Project.Solution, cancellationToken).ConfigureAwait(false); symbolsToLookup.AddRange(symbolsToAdd); } } diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs index 849e357564052..caa32af454098 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs @@ -39,7 +39,9 @@ private class VSTypeScriptFindUsagesContext : IVSTypeScriptFindUsagesContext private readonly Dictionary _definitionItemMap = new(); public VSTypeScriptFindUsagesContext(IFindUsagesContext context) - => _context = context; + { + _context = context; + } public IVSTypeScriptStreamingProgressTracker ProgressTracker => new VSTypeScriptStreamingProgressTracker(_context.ProgressTracker); diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs index fcff3581a1432..886564d876238 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs @@ -42,9 +42,8 @@ public async ValueTask OnReferenceFoundAsync(Document document, TextSpan span, C { var documentSpan = await ClassifiedSpansAndHighlightSpanFactory.GetClassifiedDocumentSpanAsync( document, span, cancellationToken).ConfigureAwait(false); - await _context.OnReferenceFoundAsync( - new SourceReferenceItem(_definition, documentSpan, SymbolUsageInfo.None), - cancellationToken).ConfigureAwait(false); + await _context.OnReferenceFoundAsync(new SourceReferenceItem( + _definition, documentSpan, SymbolUsageInfo.None), cancellationToken).ConfigureAwait(false); } } @@ -85,7 +84,7 @@ public FindReferencesProgressAdapter( // Do nothing functions. The streaming far service doesn't care about // any of these. public ValueTask OnStartedAsync(CancellationToken cancellationToken) => default; - public ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) => default; + public ValueTask OnCompletedAsync(CancellationToken cancellationToken) => default; public ValueTask OnFindInDocumentStartedAsync(Document document, CancellationToken cancellationToken) => default; public ValueTask OnFindInDocumentCompletedAsync(Document document, CancellationToken cancellationToken) => default; diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs index e986586ff3d28..b31f26d59a01b 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/FindReferencesSearchEngine.cs @@ -113,7 +113,7 @@ public async Task FindReferencesAsync(ISymbol symbol, CancellationToken cancella } finally { - await _progress.OnCompletedAsync(_solution, cancellationToken).ConfigureAwait(false); + await _progress.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/NoOpStreamingFindReferencesProgress.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/NoOpStreamingFindReferencesProgress.cs index 266a038607d65..9dfc71ad26461 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/NoOpStreamingFindReferencesProgress.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/NoOpStreamingFindReferencesProgress.cs @@ -29,7 +29,7 @@ private NoOpStreamingFindReferencesProgress() public static Task ReportProgressAsync(int current, int maximum) => Task.CompletedTask; #pragma warning restore IDE0060 // Remove unused parameter - public ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) => default; + public ValueTask OnCompletedAsync(CancellationToken cancellationToken) => default; public ValueTask OnStartedAsync(CancellationToken cancellationToken) => default; public ValueTask OnDefinitionFoundAsync(SymbolGroup group, CancellationToken cancellationToken) => default; public ValueTask OnReferenceFoundAsync(SymbolGroup group, ISymbol symbol, ReferenceLocation location, CancellationToken cancellationToken) => default; diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/StreamingFindReferencesProgress.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/StreamingFindReferencesProgress.cs index d60a8f931dc49..0dc8f2679485c 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/StreamingFindReferencesProgress.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/StreamingFindReferencesProgress.cs @@ -30,7 +30,7 @@ public StreamingFindReferencesProgressAdapter(IFindReferencesProgress progress) }); } - public ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) + public ValueTask OnCompletedAsync(CancellationToken cancellationToken) { _progress.OnCompleted(); return default; diff --git a/src/Workspaces/Core/Portable/FindSymbols/IStreamingFindReferencesProgress.cs b/src/Workspaces/Core/Portable/FindSymbols/IStreamingFindReferencesProgress.cs index 28c67beb09b8e..ba5c90f6ea97e 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/IStreamingFindReferencesProgress.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/IStreamingFindReferencesProgress.cs @@ -66,7 +66,7 @@ internal interface IStreamingFindReferencesProgress IStreamingProgressTracker ProgressTracker { get; } ValueTask OnStartedAsync(CancellationToken cancellationToken); - ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken); + ValueTask OnCompletedAsync(CancellationToken cancellationToken); ValueTask OnFindInDocumentStartedAsync(Document document, CancellationToken cancellationToken); ValueTask OnFindInDocumentCompletedAsync(Document document, CancellationToken cancellationToken); diff --git a/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs b/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs index 22422ca016d02..da0c396b49916 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs @@ -57,8 +57,8 @@ public ImmutableArray GetReferencedSymbols() public ValueTask OnStartedAsync(CancellationToken cancellationToken) => _underlyingProgress.OnStartedAsync(cancellationToken); - public ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) - => _underlyingProgress.OnCompletedAsync(solution, cancellationToken); + public ValueTask OnCompletedAsync(CancellationToken cancellationToken) + => _underlyingProgress.OnCompletedAsync(cancellationToken); public ValueTask OnFindInDocumentCompletedAsync(Document document, CancellationToken cancellationToken) => _underlyingProgress.OnFindInDocumentCompletedAsync(document, cancellationToken); public ValueTask OnFindInDocumentStartedAsync(Document document, CancellationToken cancellationToken) => _underlyingProgress.OnFindInDocumentStartedAsync(document, cancellationToken); diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.FindReferencesServerCallback.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.FindReferencesServerCallback.cs index e10ae4002608b..77d5c5640eb39 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.FindReferencesServerCallback.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.FindReferencesServerCallback.cs @@ -47,7 +47,7 @@ public ValueTask OnStartedAsync(CancellationToken cancellationToken) => _progress.OnStartedAsync(cancellationToken); public ValueTask OnCompletedAsync(CancellationToken cancellationToken) - => _progress.OnCompletedAsync(_solution, cancellationToken); + => _progress.OnCompletedAsync(cancellationToken); public ValueTask OnFindInDocumentStartedAsync(DocumentId documentId, CancellationToken cancellationToken) { From 8d6bf9ef7cc28b83d52ba0848cd3d7b01b8c9b80 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Aug 2021 12:03:39 -0700 Subject: [PATCH 26/42] Add comment --- src/Features/Core/Portable/DocumentIdSpan.cs | 4 ++++ .../ValueTracking/ValueTracker.FindReferencesProgress.cs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Features/Core/Portable/DocumentIdSpan.cs b/src/Features/Core/Portable/DocumentIdSpan.cs index 285d292e6e229..0e8d6ca340139 100644 --- a/src/Features/Core/Portable/DocumentIdSpan.cs +++ b/src/Features/Core/Portable/DocumentIdSpan.cs @@ -8,6 +8,10 @@ namespace Microsoft.CodeAnalysis { + /// + /// Similar to but can be held without rooting a particular + /// snapshot indefinitely. + /// internal readonly struct DocumentIdSpan { public Workspace Workspace { get; } diff --git a/src/Features/Core/Portable/ValueTracking/ValueTracker.FindReferencesProgress.cs b/src/Features/Core/Portable/ValueTracking/ValueTracker.FindReferencesProgress.cs index 9b31e64c42cb6..017373779b62a 100644 --- a/src/Features/Core/Portable/ValueTracking/ValueTracker.FindReferencesProgress.cs +++ b/src/Features/Core/Portable/ValueTracking/ValueTracker.FindReferencesProgress.cs @@ -28,7 +28,7 @@ public FindReferencesProgress(OperationCollector valueTrackingProgressCollector) public ValueTask ItemCompletedAsync(CancellationToken _) => new(); - public ValueTask OnCompletedAsync(Solution solution, CancellationToken _) => new(); + public ValueTask OnCompletedAsync(CancellationToken _) => new(); public ValueTask OnDefinitionFoundAsync(SymbolGroup symbolGroup, CancellationToken _) => new(); From d3704ae8268bc31345a7203eedd4d7032c17bff3 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Aug 2021 12:05:19 -0700 Subject: [PATCH 27/42] remove method --- ...tionItem.DocumentLocationDefinitionItem.cs | 19 ++----------------- .../SymbolFinder/RemoteSymbolFinderService.cs | 4 ++-- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs index fcb82a43e6d4b..3758cb3e087e0 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs @@ -38,21 +38,6 @@ public DefaultDefinitionItem( { } - private async Task TryGetDocumentSpanAsync(CancellationToken cancellationToken) - { - // We explicitly do not use SerializableDefinitionItem.RehydrateAsync here. That method - // only is guaranteed to work if passed the original Solution that the definition item - // was created against (and it will throw if is passed a different solution that it can't - // find the document in). Because we are using .CurrentSolution here, we need to be resilient - // to the possibility that we may no longer be able to find/navigate to this document. - var span = SourceSpans[0]; - var solution = span.Workspace.CurrentSolution; - var documentId = span.DocumentId; - var document = solution.GetDocument(documentId) ?? - await solution.GetSourceGeneratedDocumentAsync(documentId, cancellationToken).ConfigureAwait(false); - return document == null ? null : new DocumentSpan(document, SourceSpans[0].SourceSpan); - } - [Obsolete] public override bool CanNavigateTo(Workspace workspace, CancellationToken cancellationToken) => throw ExceptionUtilities.Unreachable; @@ -69,7 +54,7 @@ public override async Task CanNavigateToAsync(Workspace workspace, Cancell if (Properties.TryGetValue(MetadataSymbolKey, out var symbolKey)) return CanNavigateToMetadataSymbol(workspace, symbolKey); - if (await TryGetDocumentSpanAsync(cancellationToken).ConfigureAwait(false) is not DocumentSpan span) + if (await this.SourceSpans[0].TryRehydrateAsync(cancellationToken).ConfigureAwait(false) is not DocumentSpan span) return false; return await span.CanNavigateToAsync(cancellationToken).ConfigureAwait(false); @@ -83,7 +68,7 @@ public override async Task TryNavigateToAsync(Workspace workspace, bool sh if (Properties.TryGetValue(MetadataSymbolKey, out var symbolKey)) return TryNavigateToMetadataSymbol(workspace, symbolKey); - if (await TryGetDocumentSpanAsync(cancellationToken).ConfigureAwait(false) is not DocumentSpan span) + if (await this.SourceSpans[0].TryRehydrateAsync(cancellationToken).ConfigureAwait(false) is not DocumentSpan span) return false; return await span.TryNavigateToAsync(showInPreviewTab, activateTab, cancellationToken).ConfigureAwait(false); diff --git a/src/Workspaces/Remote/ServiceHub/Services/SymbolFinder/RemoteSymbolFinderService.cs b/src/Workspaces/Remote/ServiceHub/Services/SymbolFinder/RemoteSymbolFinderService.cs index 306f708c95933..d1fe987bbfb55 100644 --- a/src/Workspaces/Remote/ServiceHub/Services/SymbolFinder/RemoteSymbolFinderService.cs +++ b/src/Workspaces/Remote/ServiceHub/Services/SymbolFinder/RemoteSymbolFinderService.cs @@ -53,7 +53,7 @@ public ValueTask FindReferencesAsync( if (symbol == null) { await progressCallback.OnStartedAsync(cancellationToken).ConfigureAwait(false); - await progressCallback.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); + await progressCallback.OnCompletedAsync(cancellationToken).ConfigureAwait(false); return; } @@ -224,7 +224,7 @@ public FindReferencesProgressCallback(Solution solution, RemoteCallback _callback.InvokeAsync((callback, cancellationToken) => callback.OnStartedAsync(_callbackId, cancellationToken), cancellationToken); - public ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) + public ValueTask OnCompletedAsync(CancellationToken cancellationToken) => _callback.InvokeAsync((callback, cancellationToken) => callback.OnCompletedAsync(_callbackId, cancellationToken), cancellationToken); public ValueTask OnFindInDocumentStartedAsync(Document document, CancellationToken cancellationToken) From 3c6f68a8c6c554fe48b8d489d0b5d3de2845b2e0 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Aug 2021 12:09:21 -0700 Subject: [PATCH 28/42] Make static local --- .../FindUsages/IRemoteFindUsagesService.cs | 5 ++-- .../Navigation/ISymbolNavigationService.cs | 2 +- .../WithReferencesFindUsagesContext.cs | 20 +++++--------- ...encesTableControlEventProcessorProvider.cs | 27 +++++++++++-------- 4 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs b/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs index f60a71f6d71e0..b0c65fdc25221 100644 --- a/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs +++ b/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs @@ -139,7 +139,6 @@ internal readonly struct SerializableDocumentSpan public SerializableDocumentSpan(DocumentId documentId, TextSpan sourceSpan) { - Contract.ThrowIfNull(documentId); DocumentId = documentId; SourceSpan = sourceSpan; } @@ -214,7 +213,7 @@ public static SerializableDefinitionItem Dehydrate(int id, DefinitionItem item) item.DisplayParts, item.NameDisplayParts, item.OriginationParts, - item.SourceSpans.SelectAsArray(ss => new SerializableDocumentSpan(ss.DocumentId, ss.SourceSpan)), + item.SourceSpans.SelectAsArray(ss => SerializableDocumentSpan.Dehydrate(ss)), item.Properties, item.DisplayableProperties, item.DisplayIfNoReferences); @@ -264,7 +263,7 @@ public SerializableSourceReferenceItem( public static SerializableSourceReferenceItem Dehydrate(int definitionId, SourceReferenceItem item) => new(definitionId, - new SerializableDocumentSpan(item.SourceSpan.DocumentId, item.SourceSpan.SourceSpan), + SerializableDocumentSpan.Dehydrate(item.SourceSpan), item.SymbolUsageInfo, item.AdditionalProperties); diff --git a/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs b/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs index 858af9260229e..adc276d6ac08a 100644 --- a/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs +++ b/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs @@ -27,7 +27,7 @@ internal interface ISymbolNavigationService : IWorkspaceService /// perform the navigation. Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project project, CancellationToken cancellationToken); - /// True if the navigation would be handled. + /// Non-null if the navigation would be handled. Task<(string filePath, int lineNumber, int charOffset)?> WouldNavigateToSymbolAsync( DefinitionItem definitionItem, CancellationToken cancellationToken); } diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs index c9163e101ae38..d4b3be1456835 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs @@ -70,12 +70,8 @@ private async Task AddDeclarationEntriesAsync(DefinitionItem definition, bool ex foreach (var declarationLocation in definition.SourceSpans) { var definitionEntry = await TryCreateDocumentSpanEntryAsync( - definitionBucket, - declarationLocation, - HighlightSpanKind.Definition, - SymbolUsageInfo.None, - definition.DisplayableProperties, - cancellationToken).ConfigureAwait(false); + definitionBucket, declarationLocation, HighlightSpanKind.Definition, SymbolUsageInfo.None, + additionalProperties: definition.DisplayableProperties, cancellationToken).ConfigureAwait(false); declarations.AddIfNotNull(definitionEntry); } @@ -116,8 +112,7 @@ protected override ValueTask OnReferenceFoundWorkerAsync(SourceReferenceItem ref return OnEntryFoundAsync( reference.Definition, bucket => TryCreateDocumentSpanEntryAsync( - bucket, - reference.SourceSpan, + bucket, reference.SourceSpan, reference.IsWrittenTo ? HighlightSpanKind.WrittenReference : HighlightSpanKind.Reference, reference.SymbolUsageInfo, reference.AdditionalProperties, @@ -196,8 +191,7 @@ private async Task CreateMissingReferenceEntriesIfNecessaryAsync( { if (definition.IsExternal) { - await OnEntryFoundAsync( - definition, + await OnEntryFoundAsync(definition, bucket => SimpleMessageEntry.CreateAsync(bucket, bucket, ServicesVSResources.External_reference_found)!, addToEntriesWhenGroupingByDefinition: whenGroupingByDefinition, addToEntriesWhenNotGroupingByDefinition: !whenGroupingByDefinition, @@ -210,8 +204,7 @@ await OnEntryFoundAsync( // // We'll place this under a single bucket called "Symbols without references" and we'll allow // the user to navigate on that text entry to that definition if possible. - await OnEntryFoundAsync( - SymbolsWithoutReferencesDefinitionItem, + await OnEntryFoundAsync(SymbolsWithoutReferencesDefinitionItem, bucket => SimpleMessageEntry.CreateAsync( definitionBucket: bucket, navigationBucket: RoslynDefinitionBucket.Create(Presenter, this, definition, expandedByDefault: false), @@ -273,8 +266,7 @@ private async Task CreateNoResultsFoundEntryIfNecessaryAsync(CancellationToken c if (noDefinitions) { // Create a fake definition/reference called "search found no results" - await OnEntryFoundAsync( - NoResultsDefinitionItem, + await OnEntryFoundAsync(NoResultsDefinitionItem, bucket => SimpleMessageEntry.CreateAsync(bucket, null, ServicesVSResources.Search_found_no_results)!, addToEntriesWhenGroupingByDefinition: true, addToEntriesWhenNotGroupingByDefinition: true, diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/FindReferencesTableControlEventProcessorProvider.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/FindReferencesTableControlEventProcessorProvider.cs index 4c1fd2ecf14b3..d0f704671f7e8 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/FindReferencesTableControlEventProcessorProvider.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/FindReferencesTableControlEventProcessorProvider.cs @@ -67,19 +67,24 @@ public override void PreprocessNavigate(ITableEntryHandle entry, TableEntryNavig // Fire and forget e.Handled = true; - _ = ProcessNavigateAsync(supportsNavigation, e); - } + _ = ProcessNavigateAsync(supportsNavigation, e, _listener, _operationExecutor); - private async Task ProcessNavigateAsync(ISupportsNavigation supportsNavigation, TableEntryNavigateEventArgs e) - { - using var token = _listener.BeginAsyncOperation(nameof(ProcessNavigateAsync)); - using var context = _operationExecutor.BeginExecute( - ServicesVSResources.IntelliSense, - EditorFeaturesResources.Navigating, - allowCancellation: true, - showProgress: false); + return; - await supportsNavigation.TryNavigateToAsync(e.IsPreview, context.UserCancellationToken).ConfigureAwait(false); + async static Task ProcessNavigateAsync( + ISupportsNavigation supportsNavigation, TableEntryNavigateEventArgs e, + IAsynchronousOperationListener listener, + IUIThreadOperationExecutor operationExecutor) + { + using var token = listener.BeginAsyncOperation(nameof(ProcessNavigateAsync)); + using var context = operationExecutor.BeginExecute( + ServicesVSResources.IntelliSense, + EditorFeaturesResources.Navigating, + allowCancellation: true, + showProgress: false); + + await supportsNavigation.TryNavigateToAsync(e.IsPreview, context.UserCancellationToken).ConfigureAwait(false); + } } } } From 7517e32a050d65711ad3efca0274c2d3d4a553b4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Aug 2021 12:11:18 -0700 Subject: [PATCH 29/42] Switch to UIthread --- .../VisualStudioDefinitionsAndReferencesFactory.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs index c37ac9c07fccd..070c650ffe0cc 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs @@ -50,17 +50,18 @@ public VisualStudioDefinitionsAndReferencesFactory( if (result is not var (filePath, lineNumber, charOffset)) return null; - var displayParts = GetDisplayParts(filePath, lineNumber, charOffset); + await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + var displayParts = GetDisplayParts_MustCallOnUIThread(filePath, lineNumber, charOffset); return new ExternalDefinitionItem( definitionItem.Tags, displayParts, _serviceProvider, _threadingContext, filePath, lineNumber, charOffset); } - private ImmutableArray GetDisplayParts( + private ImmutableArray GetDisplayParts_MustCallOnUIThread( string filePath, int lineNumber, int charOffset) { - var sourceLine = GetSourceLine(filePath, lineNumber).Trim(' ', '\t'); + var sourceLine = GetSourceLine_MustCallOnUIThread(filePath, lineNumber).Trim(' ', '\t'); // Put the line in 1-based for the presentation of this item. var formatted = $"{filePath} - ({lineNumber + 1}, {charOffset + 1}) : {sourceLine}"; @@ -68,7 +69,7 @@ private ImmutableArray GetDisplayParts( return ImmutableArray.Create(new TaggedText(TextTags.Text, formatted)); } - private string GetSourceLine(string filePath, int lineNumber) + private string GetSourceLine_MustCallOnUIThread(string filePath, int lineNumber) { using var invisibleEditor = new InvisibleEditor( _serviceProvider, filePath, hierarchy: null, needsSave: false, needsUndoDisabled: false); From be47bf05a738a8fb150b8cc7061b129485181ceb Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Aug 2021 12:12:01 -0700 Subject: [PATCH 30/42] Revert --- .../Portable/FindSymbols/StreamingProgressCollector.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs b/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs index da0c396b49916..fcc4e5d2c12f7 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/StreamingProgressCollector.cs @@ -54,11 +54,8 @@ public ImmutableArray GetReferencedSymbols() } } - public ValueTask OnStartedAsync(CancellationToken cancellationToken) - => _underlyingProgress.OnStartedAsync(cancellationToken); - - public ValueTask OnCompletedAsync(CancellationToken cancellationToken) - => _underlyingProgress.OnCompletedAsync(cancellationToken); + public ValueTask OnStartedAsync(CancellationToken cancellationToken) => _underlyingProgress.OnStartedAsync(cancellationToken); + public ValueTask OnCompletedAsync(CancellationToken cancellationToken) => _underlyingProgress.OnCompletedAsync(cancellationToken); public ValueTask OnFindInDocumentCompletedAsync(Document document, CancellationToken cancellationToken) => _underlyingProgress.OnFindInDocumentCompletedAsync(document, cancellationToken); public ValueTask OnFindInDocumentStartedAsync(Document document, CancellationToken cancellationToken) => _underlyingProgress.OnFindInDocumentStartedAsync(document, cancellationToken); From 99e8ce1f5ae683cc93b73de0c7c05d48e4357b2d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Aug 2021 18:10:30 -0700 Subject: [PATCH 31/42] Fix --- .../Core/Portable/FindUsages/IRemoteFindUsagesService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs b/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs index b0c65fdc25221..9f0663ee391da 100644 --- a/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs +++ b/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs @@ -143,8 +143,8 @@ public SerializableDocumentSpan(DocumentId documentId, TextSpan sourceSpan) SourceSpan = sourceSpan; } - public static SerializableDocumentSpan Dehydrate(DocumentSpan documentSpan) - => new(documentSpan.Document.Id, documentSpan.SourceSpan); + public static SerializableDocumentSpan Dehydrate(DocumentIdSpan documentSpan) + => new(documentSpan.DocumentId, documentSpan.SourceSpan); public async ValueTask RehydrateAsync(Solution solution, CancellationToken cancellationToken) { From b60a74e4dcf92e01f7fbbce7d75ea26d248a7395 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Aug 2021 21:54:42 -0700 Subject: [PATCH 32/42] Pass solutions along --- .../FindBaseSymbolsCommandHandler.cs | 4 +- .../FindDerivedSymbolsCommandHandler.cs | 4 +- .../FindExtensionMethodsCommandHandler.cs | 4 +- .../FindImplementingMembersCommandHandler.cs | 4 +- .../FindMemberOverloadsCommandHandler.cs | 4 +- ...FindReferencesOfOverloadsCommandHandler.cs | 2 +- .../Core.Wpf/Peek/PeekableItemFactory.cs | 2 +- .../AbstractGoToCommandHandler.cs | 2 +- .../VSTypeScriptFindUsagesService.cs | 12 +++--- .../FindReferencesCommandHandler.cs | 2 +- ...UsagesService.DefinitionTrackingContext.cs | 8 ++-- ...stractFindUsagesService.ProgressAdapter.cs | 9 ++-- ...ctFindUsagesService_FindImplementations.cs | 2 +- ...bstractFindUsagesService_FindReferences.cs | 4 +- .../Core/FindUsages/FindUsagesContext.cs | 6 +-- .../FindUsages/SimpleFindUsagesContext.cs | 4 +- .../Core/GoToBase/AbstractGoToBaseService.cs | 4 +- .../AbstractGoToDefinitionService.cs | 2 +- .../AbstractGoToSymbolService.cs | 2 +- .../GoToDefinition/GoToDefinitionHelpers.cs | 4 +- .../Host/IStreamingFindReferencesPresenter.cs | 12 +++--- .../FindReferencesCommandHandlerTests.cs | 2 +- .../InheritanceMarginTests.cs | 6 +-- .../FindReferences/FindReferencesTests.vb | 13 ++++-- .../GoToDefinition/GoToDefinitionTestsBase.vb | 2 +- .../Test2/GoToHelpers/GoToHelpers.vb | 2 +- .../MockSymbolNavigationService.vb | 2 +- .../MockSymbolNavigationServiceProvider.vb | 1 + src/Features/Core/Portable/DocumentIdSpan.cs | 9 ++-- ...tionItem.DocumentLocationDefinitionItem.cs | 12 +++--- .../Portable/FindUsages/DefinitionItem.cs | 8 ++-- .../Portable/FindUsages/IFindUsagesContext.cs | 4 +- .../FindUsages/IRemoteFindUsagesService.cs | 4 +- .../DefaultSymbolNavigationService.cs | 3 +- .../Navigation/ISymbolNavigationService.cs | 2 +- .../CustomProtocol/FindUsagesLSPContext.cs | 10 ++--- .../References/FindAllReferencesHandler.cs | 2 +- .../References/FindImplementationsHandler.cs | 2 +- .../Debugger/DebuggerFindReferencesService.cs | 2 +- .../FindUsages/FSharpFindUsagesContext.cs | 8 ++-- .../FindUsages/FSharpFindUsagesService.cs | 4 +- ...bstractTableDataSourceFindUsagesContext.cs | 22 +++++----- .../WithReferencesFindUsagesContext.cs | 43 +++++++++++-------- .../WithoutReferencesFindUsagesContext.cs | 13 +++--- .../Entries/MetadataDefinitionItemEntry.cs | 2 +- .../FindReferences/RoslynDefinitionBucket.cs | 2 +- ...alStudioDefinitionsAndReferencesFactory.cs | 6 +-- .../AbstractObjectBrowserLibraryManager.cs | 2 +- .../VisualStudioSymbolNavigationService.cs | 15 ++++--- .../FindUsages/RemoteFindUsagesService.cs | 4 +- 50 files changed, 161 insertions(+), 143 deletions(-) diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs index 5e2185b61c07a..6038e79c9e4a2 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs @@ -84,7 +84,7 @@ private async Task StreamingFindBaseSymbolsAsync( } var definitionItem = overriddenSymbol.ToNonClassifiedDefinitionItem(document.Project.Solution, true); - await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(document.Project.Solution, definitionItem, cancellationToken).ConfigureAwait(false); // try getting the next one overriddenSymbol = overriddenSymbol.GetOverriddenMember(); @@ -92,7 +92,7 @@ private async Task StreamingFindBaseSymbolsAsync( } finally { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs index 6577d0200543a..87d98576aa333 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs @@ -106,13 +106,13 @@ private async Task FindDerivedSymbolsAsync( foreach (var candidate in candidates) { var definitionItem = candidate.ToNonClassifiedDefinitionItem(document.Project.Solution, true); - await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(document.Project.Solution, definitionItem, cancellationToken).ConfigureAwait(false); } } } finally { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs index 843a5cecea69f..6aebb99319778 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs @@ -111,7 +111,7 @@ private async Task FindExtensionMethodsAsync( var definitionItem = reducedMethod.ToNonClassifiedDefinitionItem(solution, true); - await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); } } } @@ -120,7 +120,7 @@ private async Task FindExtensionMethodsAsync( } finally { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs index 7e8998cfff489..c88de382641c4 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs @@ -119,7 +119,7 @@ private async Task FindImplementingMembersAsync( } finally { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); } } } @@ -144,7 +144,7 @@ private static async Task InspectInterfaceAsync( continue; var definitionItem = impl.ToNonClassifiedDefinitionItem(project.Solution, true); - await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(project.Solution, definitionItem, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs index 2c6ac335cf584..c05148638ee55 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs @@ -85,12 +85,12 @@ private async Task FindMemberOverloadsAsync( .Where(m => m.Kind == symbol.Kind && m.Name == symbol.Name)) { var definitionItem = curSymbol.ToNonClassifiedDefinitionItem(document.Project.Solution, includeHiddenLocations: true); - await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(document.Project.Solution, definitionItem, cancellationToken).ConfigureAwait(false); } } finally { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs index 5006710ae5adb..eb97f9f398a94 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs @@ -137,7 +137,7 @@ private async Task StreamingFindReferencesAsync( // that means that a new search has started. We don't care about telling the // context it has completed. In the latter case something wrong has happened // and we don't want to run any more code in this particular context. - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs b/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs index a771b697722fb..7a668be48b526 100644 --- a/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs +++ b/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs @@ -67,7 +67,7 @@ public async Task> GetPeekableItemsAsync( var symbolNavigationService = solution.Workspace.Services.GetService(); var definitionItem = symbol.ToNonClassifiedDefinitionItem(solution, includeHiddenLocations: true); - var result = await symbolNavigationService.WouldNavigateToSymbolAsync(definitionItem, cancellationToken).ConfigureAwait(false); + var result = await symbolNavigationService.WouldNavigateToSymbolAsync(project.Solution, definitionItem, cancellationToken).ConfigureAwait(false); if (result is var (filePath, lineNumber, charOffset)) { var position = new LinePosition(lineNumber, charOffset); diff --git a/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs b/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs index 4ad732394b8dc..85ecef8ad836c 100644 --- a/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs +++ b/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs @@ -126,7 +126,7 @@ private void ExecuteCommand( return context.Message; await _streamingPresenter.TryNavigateToOrPresentItemsAsync( - _threadingContext, document.Project.Solution.Workspace, context.SearchTitle, context.GetDefinitions(), cancellationToken).ConfigureAwait(false); + _threadingContext, document.Project.Solution, context.SearchTitle, context.GetDefinitions(), cancellationToken).ConfigureAwait(false); return null; } } diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs index caa32af454098..5dfb35f773993 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs @@ -28,18 +28,20 @@ public VSTypeScriptFindUsagesService(IVSTypeScriptFindUsagesService underlyingSe } public Task FindReferencesAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _underlyingService.FindReferencesAsync(document, position, new VSTypeScriptFindUsagesContext(context), cancellationToken); + => _underlyingService.FindReferencesAsync(document, position, new VSTypeScriptFindUsagesContext(document.Project.Solution, context), cancellationToken); public Task FindImplementationsAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _underlyingService.FindImplementationsAsync(document, position, new VSTypeScriptFindUsagesContext(context), cancellationToken); + => _underlyingService.FindImplementationsAsync(document, position, new VSTypeScriptFindUsagesContext(document.Project.Solution, context), cancellationToken); private class VSTypeScriptFindUsagesContext : IVSTypeScriptFindUsagesContext { + private readonly Solution _solution; private readonly IFindUsagesContext _context; private readonly Dictionary _definitionItemMap = new(); - public VSTypeScriptFindUsagesContext(IFindUsagesContext context) + public VSTypeScriptFindUsagesContext(Solution solution, IFindUsagesContext context) { + _solution = solution; _context = context; } @@ -75,13 +77,13 @@ private DefinitionItem GetOrCreateDefinitionItem(VSTypeScriptDefinitionItem item public ValueTask OnDefinitionFoundAsync(VSTypeScriptDefinitionItem definition, CancellationToken cancellationToken) { var item = GetOrCreateDefinitionItem(definition); - return _context.OnDefinitionFoundAsync(item, cancellationToken); + return _context.OnDefinitionFoundAsync(_solution, item, cancellationToken); } public ValueTask OnReferenceFoundAsync(VSTypeScriptSourceReferenceItem reference, CancellationToken cancellationToken) { var item = GetOrCreateDefinitionItem(reference.Definition); - return _context.OnReferenceFoundAsync(new SourceReferenceItem(item, reference.SourceSpan, reference.SymbolUsageInfo), cancellationToken); + return _context.OnReferenceFoundAsync(_solution, new SourceReferenceItem(item, reference.SourceSpan, reference.SymbolUsageInfo), cancellationToken); } } diff --git a/src/EditorFeatures/Core/FindReferences/FindReferencesCommandHandler.cs b/src/EditorFeatures/Core/FindReferences/FindReferencesCommandHandler.cs index b7c79db5a3fd2..5d78122c90279 100644 --- a/src/EditorFeatures/Core/FindReferences/FindReferencesCommandHandler.cs +++ b/src/EditorFeatures/Core/FindReferences/FindReferencesCommandHandler.cs @@ -137,7 +137,7 @@ private async Task StreamingFindReferencesAsync( } finally { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs index 7aacd3d6f2dd8..1868225df2c96 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs @@ -39,17 +39,17 @@ public ValueTask ReportMessageAsync(string message, CancellationToken cancellati public ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) => _underlyingContext.SetSearchTitleAsync(title, cancellationToken); - public ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) - => _underlyingContext.OnReferenceFoundAsync(reference, cancellationToken); + public ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) + => _underlyingContext.OnReferenceFoundAsync(solution, reference, cancellationToken); - public ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) + public ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) { lock (_gate) { _definitions.Add(definition); } - return _underlyingContext.OnDefinitionFoundAsync(definition, cancellationToken); + return _underlyingContext.OnDefinitionFoundAsync(solution, definition, cancellationToken); } public ImmutableArray GetDefinitions() diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs index 886564d876238..a6254b6233ae9 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs @@ -42,8 +42,9 @@ public async ValueTask OnReferenceFoundAsync(Document document, TextSpan span, C { var documentSpan = await ClassifiedSpansAndHighlightSpanFactory.GetClassifiedDocumentSpanAsync( document, span, cancellationToken).ConfigureAwait(false); - await _context.OnReferenceFoundAsync(new SourceReferenceItem( - _definition, documentSpan, SymbolUsageInfo.None), cancellationToken).ConfigureAwait(false); + await _context.OnReferenceFoundAsync( + document.Project.Solution, + new SourceReferenceItem(_definition, documentSpan, SymbolUsageInfo.None), cancellationToken).ConfigureAwait(false); } } @@ -115,7 +116,7 @@ private async ValueTask GetDefinitionItemAsync(SymbolGroup group public async ValueTask OnDefinitionFoundAsync(SymbolGroup group, CancellationToken cancellationToken) { var definitionItem = await GetDefinitionItemAsync(group, cancellationToken).ConfigureAwait(false); - await _context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + await _context.OnDefinitionFoundAsync(_solution, definitionItem, cancellationToken).ConfigureAwait(false); } public async ValueTask OnReferenceFoundAsync(SymbolGroup group, ISymbol definition, ReferenceLocation location, CancellationToken cancellationToken) @@ -126,7 +127,7 @@ public async ValueTask OnReferenceFoundAsync(SymbolGroup group, ISymbol definiti cancellationToken).ConfigureAwait(false); if (referenceItem != null) - await _context.OnReferenceFoundAsync(referenceItem, cancellationToken).ConfigureAwait(false); + await _context.OnReferenceFoundAsync(_solution, referenceItem, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindImplementations.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindImplementations.cs index 59e7fcf5ca57f..568229ce9d102 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindImplementations.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindImplementations.cs @@ -86,7 +86,7 @@ await context.SetSearchTitleAsync( var definitionItem = await implementation.ToClassifiedDefinitionItemAsync( solution, isPrimary: true, includeHiddenLocations: false, FindReferencesSearchOptions.Default, cancellationToken).ConfigureAwait(false); - await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); } } diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs index 7beb5b7899ace..e32b022f4796a 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs @@ -33,7 +33,7 @@ await FindLiteralOrSymbolReferencesAsync( document.Project.Solution, definitionTrackingContext.GetDefinitions(), cancellationToken).ConfigureAwait(false); foreach (var definition in thirdPartyDefinitions) - await context.OnDefinitionFoundAsync(definition, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(document.Project.Solution, definition, cancellationToken).ConfigureAwait(false); } Task IFindUsagesLSPService.FindReferencesAsync( @@ -222,7 +222,7 @@ private static async Task TryFindLiteralReferencesAsync( ImmutableArray.Create(TextTags.StringLiteral), ImmutableArray.Create(new TaggedText(TextTags.Text, searchTitle))); - await context.OnDefinitionFoundAsync(definition, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(solution, definition, cancellationToken).ConfigureAwait(false); var progressAdapter = new FindLiteralsProgressAdapter(context, definition); diff --git a/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs b/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs index a733a3d746aae..08e0e2ba90986 100644 --- a/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs +++ b/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs @@ -19,11 +19,11 @@ protected FindUsagesContext() public virtual ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) => default; - public virtual ValueTask OnCompletedAsync(CancellationToken cancellationToken) => default; + public virtual ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) => default; - public virtual ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) => default; + public virtual ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) => default; - public virtual ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) => default; + public virtual ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) => default; protected virtual ValueTask ReportProgressAsync(int current, int maximum, CancellationToken cancellationToken) => default; } diff --git a/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs b/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs index 6adc1175310ee..70708b1b8768b 100644 --- a/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs +++ b/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs @@ -60,7 +60,7 @@ public ImmutableArray GetReferences() } } - public override ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) + public override ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) { lock (_gate) { @@ -70,7 +70,7 @@ public override ValueTask OnDefinitionFoundAsync(DefinitionItem definition, Canc return default; } - public override ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) + public override ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) { lock (_gate) { diff --git a/src/EditorFeatures/Core/GoToBase/AbstractGoToBaseService.cs b/src/EditorFeatures/Core/GoToBase/AbstractGoToBaseService.cs index 060fd12c467c9..4cb8db56f2430 100644 --- a/src/EditorFeatures/Core/GoToBase/AbstractGoToBaseService.cs +++ b/src/EditorFeatures/Core/GoToBase/AbstractGoToBaseService.cs @@ -51,14 +51,14 @@ await context.SetSearchTitleAsync( var definitionItem = await sourceDefinition.ToClassifiedDefinitionItemAsync( solution, isPrimary: true, includeHiddenLocations: false, FindReferencesSearchOptions.Default, cancellationToken: cancellationToken).ConfigureAwait(false); - await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); found = true; } else if (baseSymbol.Locations.Any(l => l.IsInMetadata)) { var definitionItem = baseSymbol.ToNonClassifiedDefinitionItem( solution, includeHiddenLocations: true); - await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); found = true; } } diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs index 5fdae0d10036a..a21988b01f79d 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs @@ -131,7 +131,7 @@ private bool TryGoToAlternativeLocationIfAlreadyOnDefinition( } return await _streamingPresenter.TryNavigateToOrPresentItemsAsync( - _threadingContext, solution.Workspace, title, definitions.ToImmutable(), cancellationToken).ConfigureAwait(true); + _threadingContext, solution, title, definitions.ToImmutable(), cancellationToken).ConfigureAwait(true); }); } diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs index d0fdb8795a250..147a5027fe978 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs @@ -39,7 +39,7 @@ public async Task GetSymbolsAsync(GoToSymbolContext context) foreach (var def in definitions) { - if (await def.CanNavigateToAsync(solution.Workspace, cancellationToken).ConfigureAwait(false)) + if (await def.CanNavigateToAsync(solution, cancellationToken).ConfigureAwait(false)) context.AddItem(WellKnownSymbolTypes.Definition, def); } diff --git a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs index 1a3480e5be502..7f7a05f1c94f4 100644 --- a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs +++ b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs @@ -117,7 +117,7 @@ public static bool TryGoToDefinition( var definitions = await GetDefinitionsAsync(symbol, solution, thirdPartyNavigationAllowed, cancellationToken).ConfigureAwait(false); return await streamingPresenter.TryNavigateToOrPresentItemsAsync( - threadingContext, solution.Workspace, title, definitions, cancellationToken).ConfigureAwait(false); + threadingContext, solution, title, definitions, cancellationToken).ConfigureAwait(false); }); } @@ -134,7 +134,7 @@ public static bool TryGoToDefinition( return threadingContext.JoinableTaskFactory.Run(() => streamingPresenter.TryNavigateToOrPresentItemsAsync( - threadingContext, solution.Workspace, title, definitions, cancellationToken)); + threadingContext, solution, title, definitions, cancellationToken)); } } } diff --git a/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs b/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs index b43b1bd9547ea..3672322758006 100644 --- a/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs +++ b/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs @@ -61,7 +61,7 @@ internal static class IStreamingFindUsagesPresenterExtensions public static async Task TryNavigateToOrPresentItemsAsync( this IStreamingFindUsagesPresenter presenter, IThreadingContext threadingContext, - Workspace workspace, + Solution solution, string title, ImmutableArray items, CancellationToken cancellationToken) @@ -71,7 +71,7 @@ public static async Task TryNavigateToOrPresentItemsAsync( using var _ = ArrayBuilder.GetInstance(out var definitionsBuilder); foreach (var item in items) { - if (await item.CanNavigateToAsync(workspace, cancellationToken).ConfigureAwait(false)) + if (await item.CanNavigateToAsync(solution, cancellationToken).ConfigureAwait(false)) definitionsBuilder.Add(item); } @@ -85,7 +85,7 @@ public static async Task TryNavigateToOrPresentItemsAsync( // If we're directly going to a location we need to activate the preview so // that focus follows to the new cursor position. This behavior is expected // because we are only going to navigate once successfully - if (await item.TryNavigateToAsync(workspace, showInPreviewTab: true, activateTab: true, cancellationToken).ConfigureAwait(false)) + if (await item.TryNavigateToAsync(solution, showInPreviewTab: true, activateTab: true, cancellationToken).ConfigureAwait(false)) return true; } @@ -102,7 +102,7 @@ public static async Task TryNavigateToOrPresentItemsAsync( // going to a location we need to activate the preview so that focus follows to the new cursor position. return await nonExternalItems[0].TryNavigateToAsync( - workspace, showInPreviewTab: true, activateTab: true, cancellationToken).ConfigureAwait(false); + solution, showInPreviewTab: true, activateTab: true, cancellationToken).ConfigureAwait(false); } if (presenter != null) @@ -119,11 +119,11 @@ public static async Task TryNavigateToOrPresentItemsAsync( try { foreach (var definition in nonExternalItems) - await context.OnDefinitionFoundAsync(definition, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(solution, definition, cancellationToken).ConfigureAwait(false); } finally { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); } } diff --git a/src/EditorFeatures/Test/FindReferences/FindReferencesCommandHandlerTests.cs b/src/EditorFeatures/Test/FindReferences/FindReferencesCommandHandlerTests.cs index 38bcb96c02e7b..afae423000e15 100644 --- a/src/EditorFeatures/Test/FindReferences/FindReferencesCommandHandlerTests.cs +++ b/src/EditorFeatures/Test/FindReferences/FindReferencesCommandHandlerTests.cs @@ -31,7 +31,7 @@ private class MockFindUsagesContext : FindUsagesContext { public readonly List Result = new List(); - public override ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) + public override ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) { lock (Result) { diff --git a/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs b/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs index 683b6ca5ec23f..2831f498b0da6 100644 --- a/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs +++ b/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs @@ -98,11 +98,11 @@ private static async Task VerifyInheritanceMemberAsync(TestWorkspace testWorkspa .ToImmutableArray(); for (var i = 0; i < expectedTargets.Length; i++) { - await VerifyInheritanceTargetAsync(expectedTargets[i], sortedActualTargets[i]); + await VerifyInheritanceTargetAsync(testWorkspace.CurrentSolution, expectedTargets[i], sortedActualTargets[i]); } } - private static async Task VerifyInheritanceTargetAsync(TestInheritanceTargetItem expectedTarget, InheritanceTargetItem actualTarget) + private static async Task VerifyInheritanceTargetAsync(Solution solution, TestInheritanceTargetItem expectedTarget, InheritanceTargetItem actualTarget) { Assert.Equal(expectedTarget.TargetSymbolName, actualTarget.DefinitionItem.DisplayParts.JoinText()); Assert.Equal(expectedTarget.RelationshipToMember, actualTarget.RelationToMember); @@ -119,7 +119,7 @@ private static async Task VerifyInheritanceTargetAsync(TestInheritanceTargetItem Assert.Equal(expectedDocumentSpans.Length, actualDocumentSpans.Length); for (var i = 0; i < actualDocumentSpans.Length; i++) { - var docSpan = await actualDocumentSpans[i].TryRehydrateAsync(CancellationToken.None); + var docSpan = await actualDocumentSpans[i].TryRehydrateAsync(solution, CancellationToken.None); Assert.Equal(expectedDocumentSpans[i].SourceSpan, docSpan.Value.SourceSpan); Assert.Equal(expectedDocumentSpans[i].Document.FilePath, docSpan.Value.Document.FilePath); } diff --git a/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb b/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb index 24ec3b0c3df0e..305867318ae4d 100644 --- a/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb +++ b/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb @@ -83,6 +83,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences d.Name, d.AnnotatedSpans(DefinitionKey).ToList())).ToList() Dim actualDefinitions = Await GetFileNamesAndSpansAsync( + solution, context.Definitions.Where(AddressOf context.ShouldShow). SelectMany(Function(d) d.SourceSpans)) @@ -95,6 +96,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences d.Name, d.SelectedSpans.ToList())).ToList() Dim actualReferences = Await GetFileNamesAndSpansAsync( + solution, context.References.Select(Function(r) r.SourceSpan)) Assert.Equal(expectedReferences, actualReferences) @@ -108,6 +110,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences d.Name, d.AnnotatedSpans(key).ToList())).ToList() Dim valueUsageInfoField = key.Substring(ValueUsageInfoKey.Length) Dim actual = Await GetFileNamesAndSpansAsync( + solution, context.References.Where(Function(r) r.SymbolUsageInfo.ValueUsageInfoOpt?.ToString() = valueUsageInfoField).Select(Function(r) r.SourceSpan)) Assert.Equal(expected, actual) @@ -122,6 +125,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences d.Name, d.AnnotatedSpans(key).ToList())).ToList() Dim typeOrNamespaceUsageInfoFieldNames = key.Substring(TypeOrNamespaceUsageInfoKey.Length).Split(","c).Select(Function(s) s.Trim) Dim actual = Await GetFileNamesAndSpansAsync( + solution, context.References.Where(Function(r) Return r.SymbolUsageInfo.TypeOrNamespaceUsageInfoOpt IsNot Nothing AndAlso r.SymbolUsageInfo.TypeOrNamespaceUsageInfoOpt.ToString().Split(","c).Select(Function(s) s.Trim).SetEquals(typeOrNamespaceUsageInfoFieldNames) @@ -141,6 +145,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(d) New FileNameAndSpans( d.Name, d.AnnotatedSpans(annotationKey).ToList())).ToList() Dim actual = Await GetFileNamesAndSpansAsync( + solution, context.References.Where(Function(r) Dim actualValue As String = Nothing If r.AdditionalProperties.TryGetValue(propertyName, actualValue) Then @@ -177,11 +182,11 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Return additionalPropertiesMap End Function - Private Shared Async Function GetFileNamesAndSpansAsync(items As IEnumerable(Of DocumentIdSpan)) As Task(Of List(Of FileNameAndSpans)) + Private Shared Async Function GetFileNamesAndSpansAsync(solution As Solution, items As IEnumerable(Of DocumentIdSpan)) As Task(Of List(Of FileNameAndSpans)) Dim dict = New Dictionary(Of Document, List(Of DocumentIdSpan)) For Each item In items - Dim docSpan = Await item.TryRehydrateAsync(CancellationToken.None) + Dim docSpan = Await item.TryRehydrateAsync(solution, CancellationToken.None) Dim list As List(Of DocumentIdSpan) = Nothing If Not dict.TryGetValue(docSpan.Value.Document, list) Then @@ -244,7 +249,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Return definition.DisplayIfNoReferences End Function - Public Overrides Function OnDefinitionFoundAsync(definition As DefinitionItem, cancellationToken As CancellationToken) As ValueTask + Public Overrides Function OnDefinitionFoundAsync(solution As Solution, definition As DefinitionItem, cancellationToken As CancellationToken) As ValueTask SyncLock gate Me.Definitions.Add(definition) End SyncLock @@ -252,7 +257,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Return Nothing End Function - Public Overrides Function OnReferenceFoundAsync(reference As SourceReferenceItem, cancellationToken As CancellationToken) As ValueTask + Public Overrides Function OnReferenceFoundAsync(solution As Solution, reference As SourceReferenceItem, cancellationToken As CancellationToken) As ValueTask SyncLock gate References.Add(reference) End SyncLock diff --git a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb index f47e28735d89f..284c6ffa9dfb4 100644 --- a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb +++ b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb @@ -91,7 +91,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition For Each location In items For Each ss In location.SourceSpans - Dim docSpan = Await ss.TryRehydrateAsync(CancellationToken.None) + Dim docSpan = Await ss.TryRehydrateAsync(document.Project.Solution, CancellationToken.None) actualLocations.Add(New FilePathAndSpan(docSpan.Value.Document.FilePath, docSpan.Value.SourceSpan)) Next Next diff --git a/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb b/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb index 77edf70396bac..26a325d409ada 100644 --- a/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb +++ b/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb @@ -35,7 +35,7 @@ Friend Class GoToHelpers For Each definition In context.GetDefinitions() For Each sourceSpan In definition.SourceSpans - Dim docSpan = Await sourceSpan.TryRehydrateAsync(CancellationToken.None) + Dim docSpan = Await sourceSpan.TryRehydrateAsync(solution, CancellationToken.None) actualDefinitions.Add(New FilePathAndSpan(docSpan.Value.Document.FilePath, docSpan.Value.SourceSpan)) Next Next diff --git a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb index de4c825d85281..db83d65093ea4 100644 --- a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb +++ b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb @@ -26,7 +26,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers Return SpecializedTasks.True End Function - Public Function WouldNavigateToSymbolAsync(definitionItem As DefinitionItem, cancellationToken As CancellationToken) As Task(Of (filePath As String, lineNumber As Integer, charOffset As Integer)?) Implements ISymbolNavigationService.WouldNavigateToSymbolAsync + Public Function WouldNavigateToSymbolAsync(solution As Solution, definitionItem As DefinitionItem, cancellationToken As CancellationToken) As Task(Of (filePath As String, lineNumber As Integer, charOffset As Integer)?) Implements ISymbolNavigationService.WouldNavigateToSymbolAsync _wouldNavigateToSymbol = True Return Task.FromResult(Of (filePath As String, lineNumber As Integer, charOffset As Integer)?)(Nothing) End Function diff --git a/src/EditorFeatures/TestUtilities2/Utilities/MockSymbolNavigationServiceProvider.vb b/src/EditorFeatures/TestUtilities2/Utilities/MockSymbolNavigationServiceProvider.vb index dc126a7372e26..a3851a5366d92 100644 --- a/src/EditorFeatures/TestUtilities2/Utilities/MockSymbolNavigationServiceProvider.vb +++ b/src/EditorFeatures/TestUtilities2/Utilities/MockSymbolNavigationServiceProvider.vb @@ -62,6 +62,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities End Function Public Function WouldNavigateToSymbolAsync( + solution As Solution, definitionItem As DefinitionItem, cancellationToken As CancellationToken) As Task(Of (filePath As String, lineNumber As Integer, charOffset As Integer)?) Implements ISymbolNavigationService.WouldNavigateToSymbolAsync Me.WouldNavigateToSymbolProvidedDefinitionItem = definitionItem diff --git a/src/Features/Core/Portable/DocumentIdSpan.cs b/src/Features/Core/Portable/DocumentIdSpan.cs index 0e8d6ca340139..0819eb7405a46 100644 --- a/src/Features/Core/Portable/DocumentIdSpan.cs +++ b/src/Features/Core/Portable/DocumentIdSpan.cs @@ -14,7 +14,6 @@ namespace Microsoft.CodeAnalysis /// internal readonly struct DocumentIdSpan { - public Workspace Workspace { get; } public DocumentId DocumentId { get; } public TextSpan SourceSpan { get; } @@ -24,20 +23,18 @@ public DocumentIdSpan(DocumentSpan documentSpan) } public DocumentIdSpan(Document document, TextSpan sourceSpan) - : this(document.Project.Solution.Workspace, document.Id, sourceSpan) + : this(document.Id, sourceSpan) { } - public DocumentIdSpan(Workspace workspace, DocumentId documentId, TextSpan sourceSpan) + public DocumentIdSpan(DocumentId documentId, TextSpan sourceSpan) { - Workspace = workspace; DocumentId = documentId; SourceSpan = sourceSpan; } - public async Task TryRehydrateAsync(CancellationToken cancellationToken) + public async Task TryRehydrateAsync(Solution solution, CancellationToken cancellationToken) { - var solution = Workspace.CurrentSolution; var document = solution.GetDocument(DocumentId) ?? await solution.GetSourceGeneratedDocumentAsync(DocumentId, cancellationToken).ConfigureAwait(false); return document == null ? null : new DocumentSpan(document, SourceSpan); diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs index 3758cb3e087e0..db7e73b45d049 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.DocumentLocationDefinitionItem.cs @@ -46,29 +46,29 @@ public override bool CanNavigateTo(Workspace workspace, CancellationToken cancel public override bool TryNavigateTo(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) => throw ExceptionUtilities.Unreachable; - public override async Task CanNavigateToAsync(Workspace workspace, CancellationToken cancellationToken) + public override async Task CanNavigateToAsync(Solution solution, CancellationToken cancellationToken) { if (Properties.ContainsKey(NonNavigable)) return false; if (Properties.TryGetValue(MetadataSymbolKey, out var symbolKey)) - return CanNavigateToMetadataSymbol(workspace, symbolKey); + return CanNavigateToMetadataSymbol(solution.Workspace, symbolKey); - if (await this.SourceSpans[0].TryRehydrateAsync(cancellationToken).ConfigureAwait(false) is not DocumentSpan span) + if (await this.SourceSpans[0].TryRehydrateAsync(solution, cancellationToken).ConfigureAwait(false) is not DocumentSpan span) return false; return await span.CanNavigateToAsync(cancellationToken).ConfigureAwait(false); } - public override async Task TryNavigateToAsync(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) + public override async Task TryNavigateToAsync(Solution solution, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) { if (Properties.ContainsKey(NonNavigable)) return false; if (Properties.TryGetValue(MetadataSymbolKey, out var symbolKey)) - return TryNavigateToMetadataSymbol(workspace, symbolKey); + return TryNavigateToMetadataSymbol(solution.Workspace, symbolKey); - if (await this.SourceSpans[0].TryRehydrateAsync(cancellationToken).ConfigureAwait(false) is not DocumentSpan span) + if (await this.SourceSpans[0].TryRehydrateAsync(solution, cancellationToken).ConfigureAwait(false) is not DocumentSpan span) return false; return await span.TryNavigateToAsync(showInPreviewTab, activateTab, cancellationToken).ConfigureAwait(false); diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.cs index 5958cb7f40d10..662bdb8f470e8 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.cs @@ -163,17 +163,17 @@ protected DefinitionItem( [Obsolete("Override TryNavigateToAsync instead", error: false)] public abstract bool TryNavigateTo(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken); - public virtual Task CanNavigateToAsync(Workspace workspace, CancellationToken cancellationToken) + public virtual Task CanNavigateToAsync(Solution solution, CancellationToken cancellationToken) { #pragma warning disable CS0618 // Type or member is obsolete - return Task.FromResult(CanNavigateTo(workspace, cancellationToken)); + return Task.FromResult(CanNavigateTo(solution.Workspace, cancellationToken)); #pragma warning restore CS0618 // Type or member is obsolete } - public virtual Task TryNavigateToAsync(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) + public virtual Task TryNavigateToAsync(Solution solution, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) { #pragma warning disable CS0618 // Type or member is obsolete - return Task.FromResult(TryNavigateTo(workspace, showInPreviewTab, activateTab, cancellationToken)); + return Task.FromResult(TryNavigateTo(solution.Workspace, showInPreviewTab, activateTab, cancellationToken)); #pragma warning restore CS0618 // Type or member is obsolete } diff --git a/src/Features/Core/Portable/FindUsages/IFindUsagesContext.cs b/src/Features/Core/Portable/FindUsages/IFindUsagesContext.cs index aa818a48152e9..40621c114592e 100644 --- a/src/Features/Core/Portable/FindUsages/IFindUsagesContext.cs +++ b/src/Features/Core/Portable/FindUsages/IFindUsagesContext.cs @@ -27,7 +27,7 @@ internal interface IFindUsagesContext /// ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken); - ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken); - ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken); + ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken); + ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken); } } diff --git a/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs b/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs index 9f0663ee391da..3db5e40a3d809 100644 --- a/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs +++ b/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs @@ -108,14 +108,14 @@ public async ValueTask OnDefinitionFoundAsync(SerializableDefinitionItem definit _idToDefinition.Add(id, rehydrated); } - await _context.OnDefinitionFoundAsync(rehydrated, cancellationToken).ConfigureAwait(false); + await _context.OnDefinitionFoundAsync(_solution, rehydrated, cancellationToken).ConfigureAwait(false); } public async ValueTask OnReferenceFoundAsync(SerializableSourceReferenceItem reference, CancellationToken cancellationToken) { var rehydrated = await reference.RehydrateAsync(_solution, GetDefinition(reference.DefinitionId), cancellationToken).ConfigureAwait(false); - await _context.OnReferenceFoundAsync(rehydrated, cancellationToken).ConfigureAwait(false); + await _context.OnReferenceFoundAsync(_solution, rehydrated, cancellationToken).ConfigureAwait(false); } private DefinitionItem GetDefinition(int definitionId) diff --git a/src/Features/Core/Portable/Navigation/DefaultSymbolNavigationService.cs b/src/Features/Core/Portable/Navigation/DefaultSymbolNavigationService.cs index b566ac9fff37f..5fed9d8a4b8e7 100644 --- a/src/Features/Core/Portable/Navigation/DefaultSymbolNavigationService.cs +++ b/src/Features/Core/Portable/Navigation/DefaultSymbolNavigationService.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.FindUsages; @@ -20,7 +19,7 @@ public Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project project => SpecializedTasks.False; public Task<(string filePath, int lineNumber, int charOffset)?> WouldNavigateToSymbolAsync( - DefinitionItem definitionItem, CancellationToken cancellationToken) + Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken) { return Task.FromResult<(string filePath, int lineNumber, int charOffset)?>(null); } diff --git a/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs b/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs index adc276d6ac08a..03354f84985cd 100644 --- a/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs +++ b/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs @@ -29,6 +29,6 @@ internal interface ISymbolNavigationService : IWorkspaceService /// Non-null if the navigation would be handled. Task<(string filePath, int lineNumber, int charOffset)?> WouldNavigateToSymbolAsync( - DefinitionItem definitionItem, CancellationToken cancellationToken); + Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken); } } diff --git a/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs b/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs index df575fce6ace0..2919b1d5f9804 100644 --- a/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs +++ b/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs @@ -86,10 +86,10 @@ public FindUsagesLSPContext( } // After all definitions/references have been found, wait here until all results have been reported. - public override async ValueTask OnCompletedAsync(CancellationToken cancellationToken) + public override async ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) => await _workQueue.WaitUntilCurrentBatchCompletesAsync().ConfigureAwait(false); - public override async ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) + public override async ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) { using (await _semaphore.DisposableWaitAsync(cancellationToken).ConfigureAwait(false)) { @@ -124,7 +124,7 @@ public override async ValueTask OnDefinitionFoundAsync(DefinitionItem definition } } - public override async ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) + public override async ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) { using (await _semaphore.DisposableWaitAsync(cancellationToken).ConfigureAwait(false)) { @@ -133,7 +133,7 @@ public override async ValueTask OnReferenceFoundAsync(SourceReferenceItem refere if (!_definitionToId.TryGetValue(reference.Definition, out var definitionId)) return; - var documentSpan = await reference.SourceSpan.TryRehydrateAsync(cancellationToken).ConfigureAwait(false); + var documentSpan = await reference.SourceSpan.TryRehydrateAsync(solution, cancellationToken).ConfigureAwait(false); if (documentSpan == null) return; @@ -182,7 +182,7 @@ public override async ValueTask OnReferenceFoundAsync(SourceReferenceItem refere { var documentSpan = serializableDocumentSpan == null ? null - : await serializableDocumentSpan.Value.TryRehydrateAsync(cancellationToken).ConfigureAwait(false); + : await serializableDocumentSpan.Value.TryRehydrateAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); var location = await ComputeLocationAsync(document, position, documentSpan, metadataAsSourceFileService, cancellationToken).ConfigureAwait(false); // Getting the text for the Text property. If we somehow can't compute the text, that means we're probably dealing with a metadata diff --git a/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs b/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs index e36ac13036669..f9c2d6a47afe0 100644 --- a/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs @@ -63,7 +63,7 @@ public FindAllReferencesHandler( // Finds the references for the symbol at the specific position in the document, reporting them via streaming to the LSP client. await findUsagesService.FindReferencesAsync(document, position, findUsagesContext, cancellationToken).ConfigureAwait(false); - await findUsagesContext.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await findUsagesContext.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); return progress.GetValues(); } diff --git a/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs b/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs index 80951dc42f670..862059bf253a8 100644 --- a/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs @@ -51,7 +51,7 @@ public FindImplementationsHandler() var text = definition.GetClassifiedText(); foreach (var sourceSpan in definition.SourceSpans) { - var span = await sourceSpan.TryRehydrateAsync(cancellationToken).ConfigureAwait(false); + var span = await sourceSpan.TryRehydrateAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); if (span == null) continue; diff --git a/src/Tools/ExternalAccess/Debugger/DebuggerFindReferencesService.cs b/src/Tools/ExternalAccess/Debugger/DebuggerFindReferencesService.cs index c7526f1d34bc8..c1c2aa6661fde 100644 --- a/src/Tools/ExternalAccess/Debugger/DebuggerFindReferencesService.cs +++ b/src/Tools/ExternalAccess/Debugger/DebuggerFindReferencesService.cs @@ -48,7 +48,7 @@ public async Task FindSymbolReferencesAsync(ISymbol symbol, Project project, Can } finally { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(project.Solution, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs index e8bf8c1cb9041..6d5d0b1727d1f 100644 --- a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs +++ b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs @@ -11,11 +11,13 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.FSharp.Internal.Editor.FindUsage { internal class FSharpFindUsagesContext : IFSharpFindUsagesContext { + private readonly Solution _solution; private readonly IFindUsagesContext _context; private readonly CancellationToken _cancellationToken; - public FSharpFindUsagesContext(IFindUsagesContext context, CancellationToken cancellationToken) + public FSharpFindUsagesContext(Solution solution, IFindUsagesContext context, CancellationToken cancellationToken) { + _solution = solution; _context = context; _cancellationToken = cancellationToken; } @@ -24,12 +26,12 @@ public FSharpFindUsagesContext(IFindUsagesContext context, CancellationToken can public Task OnDefinitionFoundAsync(FSharp.FindUsages.FSharpDefinitionItem definition) { - return _context.OnDefinitionFoundAsync(definition.RoslynDefinitionItem, _cancellationToken).AsTask(); + return _context.OnDefinitionFoundAsync(_solution, definition.RoslynDefinitionItem, _cancellationToken).AsTask(); } public Task OnReferenceFoundAsync(FSharp.FindUsages.FSharpSourceReferenceItem reference) { - return _context.OnReferenceFoundAsync(reference.RoslynSourceReferenceItem, _cancellationToken).AsTask(); + return _context.OnReferenceFoundAsync(_solution, reference.RoslynSourceReferenceItem, _cancellationToken).AsTask(); } public Task ReportMessageAsync(string message) diff --git a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesService.cs b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesService.cs index 623dda3cb550c..8a3ccefe71b52 100644 --- a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesService.cs +++ b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesService.cs @@ -25,9 +25,9 @@ public FSharpFindUsagesService(IFSharpFindUsagesService service) => _service = service; public Task FindImplementationsAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _service.FindImplementationsAsync(document, position, new FSharpFindUsagesContext(context, cancellationToken)); + => _service.FindImplementationsAsync(document, position, new FSharpFindUsagesContext(document.Project.Solution, context, cancellationToken)); public Task FindReferencesAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _service.FindReferencesAsync(document, position, new FSharpFindUsagesContext(context, cancellationToken)); + => _service.FindReferencesAsync(document, position, new FSharpFindUsagesContext(document.Project.Solution, context, cancellationToken)); } } diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs index 95fe86c834930..d44ccb1fde635 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs @@ -303,28 +303,28 @@ public sealed override ValueTask SetSearchTitleAsync(string title, CancellationT return default; } - public sealed override async ValueTask OnCompletedAsync(CancellationToken cancellationToken) + public sealed override async ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) { - await OnCompletedAsyncWorkerAsync(cancellationToken).ConfigureAwait(false); - + await OnCompletedAsyncWorkerAsync(solution, cancellationToken).ConfigureAwait(false); _tableDataSink.IsStable = true; } - protected abstract Task OnCompletedAsyncWorkerAsync(CancellationToken cancellationToken); + protected abstract Task OnCompletedAsyncWorkerAsync(Solution solution, CancellationToken cancellationToken); - public sealed override ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) + public sealed override ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) { lock (Gate) { Definitions.Add(definition); } - return OnDefinitionFoundWorkerAsync(definition, cancellationToken); + return OnDefinitionFoundWorkerAsync(solution, definition, cancellationToken); } - protected abstract ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem definition, CancellationToken cancellationToken); + protected abstract ValueTask OnDefinitionFoundWorkerAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken); protected async Task TryCreateDocumentSpanEntryAsync( + Solution solution, RoslynDefinitionBucket definitionBucket, DocumentIdSpan idSpan, HighlightSpanKind spanKind, @@ -332,7 +332,7 @@ public sealed override ValueTask OnDefinitionFoundAsync(DefinitionItem definitio ImmutableDictionary additionalProperties, CancellationToken cancellationToken) { - var documentSpan = await idSpan.TryRehydrateAsync(cancellationToken).ConfigureAwait(false); + var documentSpan = await idSpan.TryRehydrateAsync(solution, cancellationToken).ConfigureAwait(false); if (documentSpan == null) return null; @@ -391,10 +391,10 @@ public sealed override ValueTask OnDefinitionFoundAsync(DefinitionItem definitio return (excerptResult, AbstractDocumentSpanEntry.GetLineContainingPosition(sourceText, documentSpan.SourceSpan.Start)); } - public sealed override ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) - => OnReferenceFoundWorkerAsync(reference, cancellationToken); + public sealed override ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) + => OnReferenceFoundWorkerAsync(solution, reference, cancellationToken); - protected abstract ValueTask OnReferenceFoundWorkerAsync(SourceReferenceItem reference, CancellationToken cancellationToken); + protected abstract ValueTask OnReferenceFoundWorkerAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken); protected RoslynDefinitionBucket GetOrCreateDefinitionBucket(DefinitionItem definition, bool expandedByDefault) { diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs index d4b3be1456835..f32839fd85e17 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs @@ -38,16 +38,16 @@ public WithReferencesFindUsagesContext( { } - protected override async ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem definition, CancellationToken cancellationToken) + protected override async ValueTask OnDefinitionFoundWorkerAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) { // If this is a definition we always want to show, then create entries for all the declaration locations // immediately. Otherwise, we'll create them on demand when we hear about references for this // definition. if (definition.DisplayIfNoReferences) - await AddDeclarationEntriesAsync(definition, expandedByDefault: true, cancellationToken).ConfigureAwait(false); + await AddDeclarationEntriesAsync(solution, definition, expandedByDefault: true, cancellationToken).ConfigureAwait(false); } - private async Task AddDeclarationEntriesAsync(DefinitionItem definition, bool expandedByDefault, CancellationToken cancellationToken) + private async Task AddDeclarationEntriesAsync(Solution solution, DefinitionItem definition, bool expandedByDefault, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -70,7 +70,7 @@ private async Task AddDeclarationEntriesAsync(DefinitionItem definition, bool ex foreach (var declarationLocation in definition.SourceSpans) { var definitionEntry = await TryCreateDocumentSpanEntryAsync( - definitionBucket, declarationLocation, HighlightSpanKind.Definition, SymbolUsageInfo.None, + solution, definitionBucket, declarationLocation, HighlightSpanKind.Definition, SymbolUsageInfo.None, additionalProperties: definition.DisplayableProperties, cancellationToken).ConfigureAwait(false); declarations.AddIfNotNull(definitionEntry); } @@ -105,13 +105,15 @@ private bool HasDeclarationEntries(DefinitionItem definition) } } - protected override ValueTask OnReferenceFoundWorkerAsync(SourceReferenceItem reference, CancellationToken cancellationToken) + protected override ValueTask OnReferenceFoundWorkerAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) { // Normal references go into both sets of entries. We ensure an entry for the definition, and an entry // for the reference itself. return OnEntryFoundAsync( + solution, reference.Definition, bucket => TryCreateDocumentSpanEntryAsync( + solution, bucket, reference.SourceSpan, reference.IsWrittenTo ? HighlightSpanKind.WrittenReference : HighlightSpanKind.Reference, reference.SymbolUsageInfo, @@ -124,6 +126,7 @@ protected override ValueTask OnReferenceFoundWorkerAsync(SourceReferenceItem ref } private async ValueTask OnEntryFoundAsync( + Solution solution, DefinitionItem definition, Func> createEntryAsync, bool addToEntriesWhenGroupingByDefinition, @@ -138,7 +141,7 @@ private async ValueTask OnEntryFoundAsync( // that we haven't created any declaration entries for (i.e. because it had DisplayIfNoReferences = // false). Because we've now found a reference, we want to make sure all its declaration entries are // added. - await AddDeclarationEntriesAsync(definition, expandedByDefault, cancellationToken).ConfigureAwait(false); + await AddDeclarationEntriesAsync(solution, definition, expandedByDefault, cancellationToken).ConfigureAwait(false); // First find the bucket corresponding to our definition. var definitionBucket = GetOrCreateDefinitionBucket(definition, expandedByDefault); @@ -166,22 +169,22 @@ private async ValueTask OnEntryFoundAsync( NotifyChange(); } - protected override async Task OnCompletedAsyncWorkerAsync(CancellationToken cancellationToken) + protected override async Task OnCompletedAsyncWorkerAsync(Solution solution, CancellationToken cancellationToken) { // Now that we know the search is over, create and display any error messages // for definitions that were not found. - await CreateMissingReferenceEntriesIfNecessaryAsync(cancellationToken).ConfigureAwait(false); - await CreateNoResultsFoundEntryIfNecessaryAsync(cancellationToken).ConfigureAwait(false); + await CreateMissingReferenceEntriesIfNecessaryAsync(solution, cancellationToken).ConfigureAwait(false); + await CreateNoResultsFoundEntryIfNecessaryAsync(solution, cancellationToken).ConfigureAwait(false); } - private async Task CreateMissingReferenceEntriesIfNecessaryAsync(CancellationToken cancellationToken) + private async Task CreateMissingReferenceEntriesIfNecessaryAsync(Solution solution, CancellationToken cancellationToken) { - await CreateMissingReferenceEntriesIfNecessaryAsync(whenGroupingByDefinition: true, cancellationToken).ConfigureAwait(false); - await CreateMissingReferenceEntriesIfNecessaryAsync(whenGroupingByDefinition: false, cancellationToken).ConfigureAwait(false); + await CreateMissingReferenceEntriesIfNecessaryAsync(solution, whenGroupingByDefinition: true, cancellationToken).ConfigureAwait(false); + await CreateMissingReferenceEntriesIfNecessaryAsync(solution, whenGroupingByDefinition: false, cancellationToken).ConfigureAwait(false); } private async Task CreateMissingReferenceEntriesIfNecessaryAsync( - bool whenGroupingByDefinition, CancellationToken cancellationToken) + Solution solution, bool whenGroupingByDefinition, CancellationToken cancellationToken) { // Go through and add dummy entries for any definitions that // that we didn't find any references for. @@ -191,7 +194,9 @@ private async Task CreateMissingReferenceEntriesIfNecessaryAsync( { if (definition.IsExternal) { - await OnEntryFoundAsync(definition, + await OnEntryFoundAsync( + solution, + definition, bucket => SimpleMessageEntry.CreateAsync(bucket, bucket, ServicesVSResources.External_reference_found)!, addToEntriesWhenGroupingByDefinition: whenGroupingByDefinition, addToEntriesWhenNotGroupingByDefinition: !whenGroupingByDefinition, @@ -204,7 +209,9 @@ await OnEntryFoundAsync(definition, // // We'll place this under a single bucket called "Symbols without references" and we'll allow // the user to navigate on that text entry to that definition if possible. - await OnEntryFoundAsync(SymbolsWithoutReferencesDefinitionItem, + await OnEntryFoundAsync( + solution, + SymbolsWithoutReferencesDefinitionItem, bucket => SimpleMessageEntry.CreateAsync( definitionBucket: bucket, navigationBucket: RoslynDefinitionBucket.Create(Presenter, this, definition, expandedByDefault: false), @@ -255,7 +262,7 @@ private ImmutableArray GetDefinitionsToCreateMissingReferenceIte } } - private async Task CreateNoResultsFoundEntryIfNecessaryAsync(CancellationToken cancellationToken) + private async Task CreateNoResultsFoundEntryIfNecessaryAsync(Solution solution, CancellationToken cancellationToken) { bool noDefinitions; lock (Gate) @@ -266,7 +273,9 @@ private async Task CreateNoResultsFoundEntryIfNecessaryAsync(CancellationToken c if (noDefinitions) { // Create a fake definition/reference called "search found no results" - await OnEntryFoundAsync(NoResultsDefinitionItem, + await OnEntryFoundAsync( + solution, + NoResultsDefinitionItem, bucket => SimpleMessageEntry.CreateAsync(bucket, null, ServicesVSResources.Search_found_no_results)!, addToEntriesWhenGroupingByDefinition: true, addToEntriesWhenNotGroupingByDefinition: true, diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs index 587c55aa81d07..c5f4ae03c9a29 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs @@ -36,14 +36,14 @@ public WithoutReferencesFindUsagesContext( } // We should never be called in a context where we get references. - protected override ValueTask OnReferenceFoundWorkerAsync(SourceReferenceItem reference, CancellationToken cancellationToken) + protected override ValueTask OnReferenceFoundWorkerAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) => throw new InvalidOperationException(); // Nothing to do on completion. - protected override Task OnCompletedAsyncWorkerAsync(CancellationToken cancellationToken) + protected override Task OnCompletedAsyncWorkerAsync(Solution solution, CancellationToken cancellationToken) => Task.CompletedTask; - protected override async ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem definition, CancellationToken cancellationToken) + protected override async ValueTask OnDefinitionFoundWorkerAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) { var definitionBucket = GetOrCreateDefinitionBucket(definition, expandedByDefault: true); @@ -55,7 +55,7 @@ protected override async ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem d // definition as what to show. That way we show enough information for things // methods. i.e. we'll show "void TypeName.MethodName(args...)" allowing // the user to see the type the method was created in. - var entry = await TryCreateEntryAsync(definitionBucket, definition, cancellationToken).ConfigureAwait(false); + var entry = await TryCreateEntryAsync(solution, definitionBucket, definition, cancellationToken).ConfigureAwait(false); entries.AddIfNotNull(entry); } else if (definition.SourceSpans.Length == 0) @@ -73,6 +73,7 @@ protected override async ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem d foreach (var sourceSpan in definition.SourceSpans) { var entry = await TryCreateDocumentSpanEntryAsync( + solution, definitionBucket, sourceSpan, HighlightSpanKind.Definition, @@ -96,9 +97,9 @@ protected override async ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem d } private async Task TryCreateEntryAsync( - RoslynDefinitionBucket definitionBucket, DefinitionItem definition, CancellationToken cancellationToken) + Solution solution, RoslynDefinitionBucket definitionBucket, DefinitionItem definition, CancellationToken cancellationToken) { - var documentSpan = await definition.SourceSpans[0].TryRehydrateAsync(cancellationToken).ConfigureAwait(false); + var documentSpan = await definition.SourceSpans[0].TryRehydrateAsync(solution, cancellationToken).ConfigureAwait(false); if (documentSpan == null) return null; diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/MetadataDefinitionItemEntry.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/MetadataDefinitionItemEntry.cs index 6895c3a9d8c6f..519b37fd51534 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/MetadataDefinitionItemEntry.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/MetadataDefinitionItemEntry.cs @@ -36,7 +36,7 @@ public MetadataDefinitionItemEntry( Task ISupportsNavigation.TryNavigateToAsync(bool isPreview, CancellationToken cancellationToken) => DefinitionBucket.DefinitionItem.TryNavigateToAsync( - Presenter._workspace, showInPreviewTab: isPreview, activateTab: !isPreview, cancellationToken); // Only activate the tab if not opening in preview + Presenter._workspace.CurrentSolution, showInPreviewTab: isPreview, activateTab: !isPreview, cancellationToken); // Only activate the tab if not opening in preview protected override IList CreateLineTextInlines() => DefinitionBucket.DefinitionItem.DisplayParts diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/RoslynDefinitionBucket.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/RoslynDefinitionBucket.cs index 1f7e02bfaefae..7731e9339cb74 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/RoslynDefinitionBucket.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/RoslynDefinitionBucket.cs @@ -65,7 +65,7 @@ public static RoslynDefinitionBucket Create( public Task TryNavigateToAsync(bool isPreview, CancellationToken cancellationToken) => DefinitionItem.TryNavigateToAsync( - _presenter._workspace, showInPreviewTab: isPreview, activateTab: !isPreview, cancellationToken); // Only activate the tab if not opening in preview + _presenter._workspace.CurrentSolution, showInPreviewTab: isPreview, activateTab: !isPreview, cancellationToken); // Only activate the tab if not opening in preview public override bool TryGetValue(string key, out object? content) { diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs index 070c650ffe0cc..48ffa71a737d4 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs @@ -46,7 +46,7 @@ public VisualStudioDefinitionsAndReferencesFactory( Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken) { var symbolNavigationService = solution.Workspace.Services.GetRequiredService(); - var result = await symbolNavigationService.WouldNavigateToSymbolAsync(definitionItem, cancellationToken).ConfigureAwait(false); + var result = await symbolNavigationService.WouldNavigateToSymbolAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); if (result is not var (filePath, lineNumber, charOffset)) return null; @@ -117,10 +117,10 @@ public ExternalDefinitionItem( _charOffset = charOffset; } - public override Task CanNavigateToAsync(Workspace workspace, CancellationToken cancellationToken) + public override Task CanNavigateToAsync(Solution solution, CancellationToken cancellationToken) => SpecializedTasks.True; - public override async Task TryNavigateToAsync(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) + public override async Task TryNavigateToAsync(Solution solution, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) { await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); return TryOpenFile() && TryNavigateToPosition(); diff --git a/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs b/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs index 5bca469a14289..181b903fc1e0b 100644 --- a/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs +++ b/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs @@ -525,7 +525,7 @@ await Task.Run( } finally { - await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(project.Solution, cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs index 6f0bf4a302fe0..ee17febe0f957 100644 --- a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs +++ b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs @@ -171,7 +171,7 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p var definitionItem = symbol.ToNonClassifiedDefinitionItem(project.Solution, includeHiddenLocations: true); definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey1, out var rqName); - var result = await TryGetNavigationAPIRequiredArgumentsAsync(definitionItem, rqName, cancellationToken).ConfigureAwait(true); + var result = await TryGetNavigationAPIRequiredArgumentsAsync(project.Solution, definitionItem, rqName, cancellationToken).ConfigureAwait(true); if (result is not var (hierarchy, itemID, navigationNotify)) return false; @@ -185,23 +185,23 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p } public async Task<(string filePath, int lineNumber, int charOffset)?> WouldNavigateToSymbolAsync( - DefinitionItem definitionItem, CancellationToken cancellationToken) + Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken) { definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey1, out var rqName1); definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey2, out var rqName2); - return await WouldNotifyToSpecificSymbolAsync(definitionItem, rqName1, cancellationToken).ConfigureAwait(false) ?? - await WouldNotifyToSpecificSymbolAsync(definitionItem, rqName2, cancellationToken).ConfigureAwait(false); + return await WouldNotifyToSpecificSymbolAsync(solution, definitionItem, rqName1, cancellationToken).ConfigureAwait(false) ?? + await WouldNotifyToSpecificSymbolAsync(solution, definitionItem, rqName2, cancellationToken).ConfigureAwait(false); } public async Task<(string filePath, int lineNumber, int charOffset)?> WouldNotifyToSpecificSymbolAsync( - DefinitionItem definitionItem, string? rqName, CancellationToken cancellationToken) + Solution solution, DefinitionItem definitionItem, string? rqName, CancellationToken cancellationToken) { if (rqName == null) return null; var values = await TryGetNavigationAPIRequiredArgumentsAsync( - definitionItem, rqName, cancellationToken).ConfigureAwait(false); + solution, definitionItem, rqName, cancellationToken).ConfigureAwait(false); if (values is not var (hierarchy, itemID, navigationNotify)) return null; @@ -229,6 +229,7 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p } private async Task<(IVsHierarchy hierarchy, uint itemId, IVsSymbolicNavigationNotify navigationNotify)?> TryGetNavigationAPIRequiredArgumentsAsync( + Solution solution, DefinitionItem definitionItem, string? rqName, CancellationToken cancellationToken) @@ -243,7 +244,7 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p using var _ = ArrayBuilder.GetInstance(out var documentsBuilder); foreach (var loc in sourceLocations) { - var docSpan = await loc.TryRehydrateAsync(cancellationToken).ConfigureAwait(false); + var docSpan = await loc.TryRehydrateAsync(solution, cancellationToken).ConfigureAwait(false); documentsBuilder.AddIfNotNull(docSpan?.Document); } diff --git a/src/Workspaces/Remote/ServiceHub/Services/FindUsages/RemoteFindUsagesService.cs b/src/Workspaces/Remote/ServiceHub/Services/FindUsages/RemoteFindUsagesService.cs index 8ec4923b98d2c..ba3fc3b7d4e9b 100644 --- a/src/Workspaces/Remote/ServiceHub/Services/FindUsages/RemoteFindUsagesService.cs +++ b/src/Workspaces/Remote/ServiceHub/Services/FindUsages/RemoteFindUsagesService.cs @@ -108,7 +108,7 @@ public ValueTask ReportMessageAsync(string message, CancellationToken cancellati public ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) => _callback.InvokeAsync((callback, cancellationToken) => callback.SetSearchTitleAsync(_callbackId, title, cancellationToken), cancellationToken); - public ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) + public ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) { var id = GetOrAddDefinitionItemId(definition); var dehydratedDefinition = SerializableDefinitionItem.Dehydrate(id, definition); @@ -129,7 +129,7 @@ private int GetOrAddDefinitionItemId(DefinitionItem item) } } - public ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) + public ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) { var definitionItem = GetOrAddDefinitionItemId(reference.Definition); var dehydratedReference = SerializableSourceReferenceItem.Dehydrate(definitionItem, reference); From 4225f079a0d64ca84309d16d806c732e9fa6ea79 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Aug 2021 22:15:24 -0700 Subject: [PATCH 33/42] Map goto impl calls --- .../CommandHandlers/AbstractGoToCommandHandler.cs | 4 +++- .../Core/GoToBase/GoToBaseCommandHandler.cs | 3 +++ .../GoToImplementationCommandHandler.cs | 8 ++++++++ .../MetadataAsSource/MetadataAsSourceFileService.cs | 12 +++++++----- .../MetadataAsSource/SymbolMappingServiceFactory.cs | 10 ++++++++++ .../Portable/SymbolMapping/ISymbolMappingService.cs | 7 +++++++ .../SymbolMapping/SymbolMappingServiceFactory.cs | 3 +++ 7 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs b/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs index 85ecef8ad836c..2f90755fcf976 100644 --- a/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs +++ b/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs @@ -37,6 +37,7 @@ public AbstractGoToCommandHandler( protected abstract string ScopeDescription { get; } protected abstract FunctionId FunctionId { get; } protected abstract Task FindActionAsync(TLanguageService service, Document document, int caretPosition, IFindUsagesContext context, CancellationToken cancellationToken); + protected abstract Task GetSolutionAsync(Document document, CancellationToken cancellationToken); public CommandState GetCommandState(TCommandArgs args) { @@ -125,8 +126,9 @@ private void ExecuteCommand( if (context.Message != null) return context.Message; + var solution = await GetSolutionAsync(document, cancellationToken).ConfigureAwait(false); await _streamingPresenter.TryNavigateToOrPresentItemsAsync( - _threadingContext, document.Project.Solution, context.SearchTitle, context.GetDefinitions(), cancellationToken).ConfigureAwait(false); + _threadingContext, solution, context.SearchTitle, context.GetDefinitions(), cancellationToken).ConfigureAwait(false); return null; } } diff --git a/src/EditorFeatures/Core/GoToBase/GoToBaseCommandHandler.cs b/src/EditorFeatures/Core/GoToBase/GoToBaseCommandHandler.cs index 2e9b12769efd8..b0e77c1b69742 100644 --- a/src/EditorFeatures/Core/GoToBase/GoToBaseCommandHandler.cs +++ b/src/EditorFeatures/Core/GoToBase/GoToBaseCommandHandler.cs @@ -45,5 +45,8 @@ protected override IGoToBaseService GetService(Document document) protected override Task FindActionAsync(IGoToBaseService service, Document document, int caretPosition, IFindUsagesContext context, CancellationToken cancellationToken) => service.FindBasesAsync(document, caretPosition, context, cancellationToken); + + protected override Task GetSolutionAsync(Document document, CancellationToken cancellationToken) + => Task.FromResult(document.Project.Solution); } } diff --git a/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs b/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs index a5a72d47229bd..38ae68cb72f3b 100644 --- a/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs +++ b/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs @@ -15,6 +15,7 @@ using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.Internal.Log; using Microsoft.CodeAnalysis.Shared.Extensions; +using Microsoft.CodeAnalysis.SymbolMapping; using Microsoft.VisualStudio.Commanding; using Microsoft.VisualStudio.Utilities; @@ -44,5 +45,12 @@ protected override Task FindActionAsync(IFindUsagesService service, Document doc protected override IFindUsagesService? GetService(Document? document) => document?.GetLanguageService(); + + protected override async Task GetSolutionAsync(Document document, CancellationToken cancellationToken) + { + var mappingService = document.Project.Solution.Workspace.Services.GetRequiredService(); + var mappedProject = await mappingService.MapDocumentAsync(document, cancellationToken).ConfigureAwait(false); + return mappedProject?.Solution ?? document.Project.Solution; + } } } diff --git a/src/Features/Core/Portable/MetadataAsSource/MetadataAsSourceFileService.cs b/src/Features/Core/Portable/MetadataAsSource/MetadataAsSourceFileService.cs index b05633d3cf97f..31a6feb4a1c69 100644 --- a/src/Features/Core/Portable/MetadataAsSource/MetadataAsSourceFileService.cs +++ b/src/Features/Core/Portable/MetadataAsSource/MetadataAsSourceFileService.cs @@ -297,7 +297,7 @@ private void InitializeWorkspace(Project project) } } - internal async Task MapSymbolAsync(Document document, SymbolKey symbolId, CancellationToken cancellationToken) + internal async Task MapDocumentAsync(Document document, CancellationToken cancellationToken) { MetadataAsSourceGeneratedFileInfo? fileInfo; @@ -312,17 +312,19 @@ private void InitializeWorkspace(Project project) // WARNING: do not touch any state fields outside the lock. var solution = fileInfo.Workspace.CurrentSolution; var project = solution.GetProject(fileInfo.SourceProjectId); + return project; + } + + internal async Task MapSymbolAsync(Document document, SymbolKey symbolId, CancellationToken cancellationToken) + { + var project = await MapDocumentAsync(document, cancellationToken).ConfigureAwait(false); if (project == null) - { return null; - } var compilation = await project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false); var resolutionResult = symbolId.Resolve(compilation, ignoreAssemblyKey: true, cancellationToken: cancellationToken); if (resolutionResult.Symbol == null) - { return null; - } return new SymbolMappingResult(project, resolutionResult.Symbol); } diff --git a/src/Features/Core/Portable/MetadataAsSource/SymbolMappingServiceFactory.cs b/src/Features/Core/Portable/MetadataAsSource/SymbolMappingServiceFactory.cs index e4c5d32488f63..488e04a94c1ec 100644 --- a/src/Features/Core/Portable/MetadataAsSource/SymbolMappingServiceFactory.cs +++ b/src/Features/Core/Portable/MetadataAsSource/SymbolMappingServiceFactory.cs @@ -41,6 +41,16 @@ private sealed class SymbolMappingService : ISymbolMappingService { return await MapSymbolAsync(document, SymbolKey.Create(symbol, cancellationToken), cancellationToken).ConfigureAwait(false); } + + public Task MapDocumentAsync(Document document, CancellationToken cancellationToken) + { + if (document.Project.Solution.Workspace is not MetadataAsSourceWorkspace workspace) + { + throw new ArgumentException(FeaturesResources.Document_must_be_contained_in_the_workspace_that_created_this_service, nameof(document)); + } + + return workspace.FileService.MapDocumentAsync(document, cancellationToken); + } } } } diff --git a/src/Features/Core/Portable/SymbolMapping/ISymbolMappingService.cs b/src/Features/Core/Portable/SymbolMapping/ISymbolMappingService.cs index 13d443a5ed8aa..50c5578ff50b2 100644 --- a/src/Features/Core/Portable/SymbolMapping/ISymbolMappingService.cs +++ b/src/Features/Core/Portable/SymbolMapping/ISymbolMappingService.cs @@ -31,5 +31,12 @@ internal interface ISymbolMappingService : IWorkspaceService /// To cancel symbol resolution /// The matching symbol from the correct solution or null Task MapSymbolAsync(Document document, ISymbol symbol, CancellationToken cancellationToken = default); + + /// + /// Given an the document that a particular + /// came from, locate the project in the correct solution that contained the symbol + /// this document was created for. + /// + Task MapDocumentAsync(Document document, CancellationToken cancellationToken); } } diff --git a/src/Features/Core/Portable/SymbolMapping/SymbolMappingServiceFactory.cs b/src/Features/Core/Portable/SymbolMapping/SymbolMappingServiceFactory.cs index cd4e863db139e..b4ba6d8ca1899 100644 --- a/src/Features/Core/Portable/SymbolMapping/SymbolMappingServiceFactory.cs +++ b/src/Features/Core/Portable/SymbolMapping/SymbolMappingServiceFactory.cs @@ -35,5 +35,8 @@ public async Task MapSymbolAsync(Document document, SymbolK public Task MapSymbolAsync(Document document, ISymbol symbol, CancellationToken cancellationToken) => Task.FromResult(new SymbolMappingResult(document.Project, symbol)); + + public Task MapDocumentAsync(Document document, CancellationToken cancellationToken) + => Task.FromResult(document.Project); } } From 78fc808db6055d1790369a5b21f60c6223d749be Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Aug 2021 22:19:40 -0700 Subject: [PATCH 34/42] Add comment --- .../GoToImplementation/GoToImplementationCommandHandler.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs b/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs index 38ae68cb72f3b..b9087bb895481 100644 --- a/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs +++ b/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs @@ -48,6 +48,9 @@ protected override Task FindActionAsync(IFindUsagesService service, Document doc protected override async Task GetSolutionAsync(Document document, CancellationToken cancellationToken) { + // The original document we may be starting with might be in a metadata-as-source workspace. + // Ensure that we map back to the real primary workspace to present symbols in so we can + // navigate back to source implementations there. var mappingService = document.Project.Solution.Workspace.Services.GetRequiredService(); var mappedProject = await mappingService.MapDocumentAsync(document, cancellationToken).ConfigureAwait(false); return mappedProject?.Solution ?? document.Project.Solution; From 2ab649698ea8e7eed50ffdb45783fa43c61371b1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 25 Aug 2021 11:43:48 -0700 Subject: [PATCH 35/42] Revert --- .../FindBaseSymbolsCommandHandler.cs | 4 +-- .../FindDerivedSymbolsCommandHandler.cs | 4 +-- .../FindExtensionMethodsCommandHandler.cs | 4 +-- .../FindImplementingMembersCommandHandler.cs | 4 +-- .../FindMemberOverloadsCommandHandler.cs | 4 +-- ...FindReferencesOfOverloadsCommandHandler.cs | 2 +- .../Core.Wpf/Peek/PeekableItemFactory.cs | 2 +- .../VSTypeScriptFindUsagesService.cs | 12 +++---- .../FindReferencesCommandHandler.cs | 2 +- ...UsagesService.DefinitionTrackingContext.cs | 8 ++--- ...stractFindUsagesService.ProgressAdapter.cs | 5 ++- ...ctFindUsagesService_FindImplementations.cs | 2 +- ...bstractFindUsagesService_FindReferences.cs | 4 +-- .../Core/FindUsages/FindUsagesContext.cs | 6 ++-- .../FindUsages/SimpleFindUsagesContext.cs | 4 +-- .../Core/GoToBase/AbstractGoToBaseService.cs | 4 +-- .../AbstractGoToSymbolService.cs | 2 +- .../Host/IStreamingFindReferencesPresenter.cs | 10 +++--- .../FindReferencesCommandHandlerTests.cs | 2 +- .../InheritanceMarginTests.cs | 17 +--------- .../FindReferences/FindReferencesTests.vb | 24 ++++++------- .../GoToDefinition/GoToDefinitionTestsBase.vb | 6 ++-- .../Test2/GoToHelpers/GoToHelpers.vb | 3 +- .../MockSymbolNavigationService.vb | 2 +- .../MockSymbolNavigationServiceProvider.vb | 1 - .../DefinitionItem.DefaultDefinitionItem.cs | 26 +++++++------- .../Portable/FindUsages/DefinitionItem.cs | 12 +++---- .../Portable/FindUsages/IFindUsagesContext.cs | 4 +-- .../FindUsages/IRemoteFindUsagesService.cs | 8 ++--- .../FindUsages/SourceReferenceItem.cs | 4 +-- .../DefaultSymbolNavigationService.cs | 2 +- .../Navigation/ISymbolNavigationService.cs | 2 +- .../CustomProtocol/FindUsagesLSPContext.cs | 18 ++++------ .../References/FindAllReferencesHandler.cs | 2 +- .../References/FindImplementationsHandler.cs | 8 ++--- .../Debugger/DebuggerFindReferencesService.cs | 2 +- .../FindUsages/FSharpFindUsagesContext.cs | 8 ++--- .../FindUsages/FSharpFindUsagesService.cs | 4 +-- ...bstractTableDataSourceFindUsagesContext.cs | 33 ++++++++---------- .../WithReferencesFindUsagesContext.cs | 34 ++++++++----------- .../WithoutReferencesFindUsagesContext.cs | 23 ++++++------- .../Entries/MetadataDefinitionItemEntry.cs | 2 +- .../FindReferences/RoslynDefinitionBucket.cs | 2 +- ...alStudioDefinitionsAndReferencesFactory.cs | 6 ++-- .../AbstractObjectBrowserLibraryManager.cs | 2 +- .../VisualStudioSymbolNavigationService.cs | 18 ++++------ .../FindUsages/RemoteFindUsagesService.cs | 4 +-- 47 files changed, 156 insertions(+), 206 deletions(-) diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs index 6038e79c9e4a2..5e2185b61c07a 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindBaseSymbolsCommandHandler.cs @@ -84,7 +84,7 @@ private async Task StreamingFindBaseSymbolsAsync( } var definitionItem = overriddenSymbol.ToNonClassifiedDefinitionItem(document.Project.Solution, true); - await context.OnDefinitionFoundAsync(document.Project.Solution, definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); // try getting the next one overriddenSymbol = overriddenSymbol.GetOverriddenMember(); @@ -92,7 +92,7 @@ private async Task StreamingFindBaseSymbolsAsync( } finally { - await context.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs index 87d98576aa333..6577d0200543a 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindDerivedSymbolsCommandHandler.cs @@ -106,13 +106,13 @@ private async Task FindDerivedSymbolsAsync( foreach (var candidate in candidates) { var definitionItem = candidate.ToNonClassifiedDefinitionItem(document.Project.Solution, true); - await context.OnDefinitionFoundAsync(document.Project.Solution, definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); } } } finally { - await context.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs index 6aebb99319778..843a5cecea69f 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindExtensionMethodsCommandHandler.cs @@ -111,7 +111,7 @@ private async Task FindExtensionMethodsAsync( var definitionItem = reducedMethod.ToNonClassifiedDefinitionItem(solution, true); - await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); } } } @@ -120,7 +120,7 @@ private async Task FindExtensionMethodsAsync( } finally { - await context.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs index c88de382641c4..7e8998cfff489 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindImplementingMembersCommandHandler.cs @@ -119,7 +119,7 @@ private async Task FindImplementingMembersAsync( } finally { - await context.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } } @@ -144,7 +144,7 @@ private static async Task InspectInterfaceAsync( continue; var definitionItem = impl.ToNonClassifiedDefinitionItem(project.Solution, true); - await context.OnDefinitionFoundAsync(project.Solution, definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs index c05148638ee55..2c6ac335cf584 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindMemberOverloadsCommandHandler.cs @@ -85,12 +85,12 @@ private async Task FindMemberOverloadsAsync( .Where(m => m.Kind == symbol.Kind && m.Name == symbol.Name)) { var definitionItem = curSymbol.ToNonClassifiedDefinitionItem(document.Project.Solution, includeHiddenLocations: true); - await context.OnDefinitionFoundAsync(document.Project.Solution, definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); } } finally { - await context.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs index eb97f9f398a94..5006710ae5adb 100644 --- a/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs +++ b/src/EditorFeatures/Core.Cocoa/NavigationCommandHandlers/FindReferencesOfOverloadsCommandHandler.cs @@ -137,7 +137,7 @@ private async Task StreamingFindReferencesAsync( // that means that a new search has started. We don't care about telling the // context it has completed. In the latter case something wrong has happened // and we don't want to run any more code in this particular context. - await context.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs b/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs index 7a668be48b526..a771b697722fb 100644 --- a/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs +++ b/src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs @@ -67,7 +67,7 @@ public async Task> GetPeekableItemsAsync( var symbolNavigationService = solution.Workspace.Services.GetService(); var definitionItem = symbol.ToNonClassifiedDefinitionItem(solution, includeHiddenLocations: true); - var result = await symbolNavigationService.WouldNavigateToSymbolAsync(project.Solution, definitionItem, cancellationToken).ConfigureAwait(false); + var result = await symbolNavigationService.WouldNavigateToSymbolAsync(definitionItem, cancellationToken).ConfigureAwait(false); if (result is var (filePath, lineNumber, charOffset)) { var position = new LinePosition(lineNumber, charOffset); diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs index 5dfb35f773993..caa32af454098 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptFindUsagesService.cs @@ -28,20 +28,18 @@ public VSTypeScriptFindUsagesService(IVSTypeScriptFindUsagesService underlyingSe } public Task FindReferencesAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _underlyingService.FindReferencesAsync(document, position, new VSTypeScriptFindUsagesContext(document.Project.Solution, context), cancellationToken); + => _underlyingService.FindReferencesAsync(document, position, new VSTypeScriptFindUsagesContext(context), cancellationToken); public Task FindImplementationsAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _underlyingService.FindImplementationsAsync(document, position, new VSTypeScriptFindUsagesContext(document.Project.Solution, context), cancellationToken); + => _underlyingService.FindImplementationsAsync(document, position, new VSTypeScriptFindUsagesContext(context), cancellationToken); private class VSTypeScriptFindUsagesContext : IVSTypeScriptFindUsagesContext { - private readonly Solution _solution; private readonly IFindUsagesContext _context; private readonly Dictionary _definitionItemMap = new(); - public VSTypeScriptFindUsagesContext(Solution solution, IFindUsagesContext context) + public VSTypeScriptFindUsagesContext(IFindUsagesContext context) { - _solution = solution; _context = context; } @@ -77,13 +75,13 @@ private DefinitionItem GetOrCreateDefinitionItem(VSTypeScriptDefinitionItem item public ValueTask OnDefinitionFoundAsync(VSTypeScriptDefinitionItem definition, CancellationToken cancellationToken) { var item = GetOrCreateDefinitionItem(definition); - return _context.OnDefinitionFoundAsync(_solution, item, cancellationToken); + return _context.OnDefinitionFoundAsync(item, cancellationToken); } public ValueTask OnReferenceFoundAsync(VSTypeScriptSourceReferenceItem reference, CancellationToken cancellationToken) { var item = GetOrCreateDefinitionItem(reference.Definition); - return _context.OnReferenceFoundAsync(_solution, new SourceReferenceItem(item, reference.SourceSpan, reference.SymbolUsageInfo), cancellationToken); + return _context.OnReferenceFoundAsync(new SourceReferenceItem(item, reference.SourceSpan, reference.SymbolUsageInfo), cancellationToken); } } diff --git a/src/EditorFeatures/Core/FindReferences/FindReferencesCommandHandler.cs b/src/EditorFeatures/Core/FindReferences/FindReferencesCommandHandler.cs index 5d78122c90279..b7c79db5a3fd2 100644 --- a/src/EditorFeatures/Core/FindReferences/FindReferencesCommandHandler.cs +++ b/src/EditorFeatures/Core/FindReferences/FindReferencesCommandHandler.cs @@ -137,7 +137,7 @@ private async Task StreamingFindReferencesAsync( } finally { - await context.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs index 1868225df2c96..7aacd3d6f2dd8 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.DefinitionTrackingContext.cs @@ -39,17 +39,17 @@ public ValueTask ReportMessageAsync(string message, CancellationToken cancellati public ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) => _underlyingContext.SetSearchTitleAsync(title, cancellationToken); - public ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) - => _underlyingContext.OnReferenceFoundAsync(solution, reference, cancellationToken); + public ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) + => _underlyingContext.OnReferenceFoundAsync(reference, cancellationToken); - public ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) + public ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) { lock (_gate) { _definitions.Add(definition); } - return _underlyingContext.OnDefinitionFoundAsync(solution, definition, cancellationToken); + return _underlyingContext.OnDefinitionFoundAsync(definition, cancellationToken); } public ImmutableArray GetDefinitions() diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs index a6254b6233ae9..55bf00bc58dbd 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs @@ -43,7 +43,6 @@ public async ValueTask OnReferenceFoundAsync(Document document, TextSpan span, C var documentSpan = await ClassifiedSpansAndHighlightSpanFactory.GetClassifiedDocumentSpanAsync( document, span, cancellationToken).ConfigureAwait(false); await _context.OnReferenceFoundAsync( - document.Project.Solution, new SourceReferenceItem(_definition, documentSpan, SymbolUsageInfo.None), cancellationToken).ConfigureAwait(false); } } @@ -116,7 +115,7 @@ private async ValueTask GetDefinitionItemAsync(SymbolGroup group public async ValueTask OnDefinitionFoundAsync(SymbolGroup group, CancellationToken cancellationToken) { var definitionItem = await GetDefinitionItemAsync(group, cancellationToken).ConfigureAwait(false); - await _context.OnDefinitionFoundAsync(_solution, definitionItem, cancellationToken).ConfigureAwait(false); + await _context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); } public async ValueTask OnReferenceFoundAsync(SymbolGroup group, ISymbol definition, ReferenceLocation location, CancellationToken cancellationToken) @@ -127,7 +126,7 @@ public async ValueTask OnReferenceFoundAsync(SymbolGroup group, ISymbol definiti cancellationToken).ConfigureAwait(false); if (referenceItem != null) - await _context.OnReferenceFoundAsync(_solution, referenceItem, cancellationToken).ConfigureAwait(false); + await _context.OnReferenceFoundAsync(referenceItem, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindImplementations.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindImplementations.cs index 568229ce9d102..59e7fcf5ca57f 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindImplementations.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindImplementations.cs @@ -86,7 +86,7 @@ await context.SetSearchTitleAsync( var definitionItem = await implementation.ToClassifiedDefinitionItemAsync( solution, isPrimary: true, includeHiddenLocations: false, FindReferencesSearchOptions.Default, cancellationToken).ConfigureAwait(false); - await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); } } diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs index e32b022f4796a..7beb5b7899ace 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService_FindReferences.cs @@ -33,7 +33,7 @@ await FindLiteralOrSymbolReferencesAsync( document.Project.Solution, definitionTrackingContext.GetDefinitions(), cancellationToken).ConfigureAwait(false); foreach (var definition in thirdPartyDefinitions) - await context.OnDefinitionFoundAsync(document.Project.Solution, definition, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definition, cancellationToken).ConfigureAwait(false); } Task IFindUsagesLSPService.FindReferencesAsync( @@ -222,7 +222,7 @@ private static async Task TryFindLiteralReferencesAsync( ImmutableArray.Create(TextTags.StringLiteral), ImmutableArray.Create(new TaggedText(TextTags.Text, searchTitle))); - await context.OnDefinitionFoundAsync(solution, definition, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definition, cancellationToken).ConfigureAwait(false); var progressAdapter = new FindLiteralsProgressAdapter(context, definition); diff --git a/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs b/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs index 08e0e2ba90986..a733a3d746aae 100644 --- a/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs +++ b/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs @@ -19,11 +19,11 @@ protected FindUsagesContext() public virtual ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) => default; - public virtual ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) => default; + public virtual ValueTask OnCompletedAsync(CancellationToken cancellationToken) => default; - public virtual ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) => default; + public virtual ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) => default; - public virtual ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) => default; + public virtual ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) => default; protected virtual ValueTask ReportProgressAsync(int current, int maximum, CancellationToken cancellationToken) => default; } diff --git a/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs b/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs index 70708b1b8768b..6adc1175310ee 100644 --- a/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs +++ b/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs @@ -60,7 +60,7 @@ public ImmutableArray GetReferences() } } - public override ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) + public override ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) { lock (_gate) { @@ -70,7 +70,7 @@ public override ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionIt return default; } - public override ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) + public override ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) { lock (_gate) { diff --git a/src/EditorFeatures/Core/GoToBase/AbstractGoToBaseService.cs b/src/EditorFeatures/Core/GoToBase/AbstractGoToBaseService.cs index 4cb8db56f2430..060fd12c467c9 100644 --- a/src/EditorFeatures/Core/GoToBase/AbstractGoToBaseService.cs +++ b/src/EditorFeatures/Core/GoToBase/AbstractGoToBaseService.cs @@ -51,14 +51,14 @@ await context.SetSearchTitleAsync( var definitionItem = await sourceDefinition.ToClassifiedDefinitionItemAsync( solution, isPrimary: true, includeHiddenLocations: false, FindReferencesSearchOptions.Default, cancellationToken: cancellationToken).ConfigureAwait(false); - await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); found = true; } else if (baseSymbol.Locations.Any(l => l.IsInMetadata)) { var definitionItem = baseSymbol.ToNonClassifiedDefinitionItem( solution, includeHiddenLocations: true); - await context.OnDefinitionFoundAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false); found = true; } } diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs index 147a5027fe978..d0fdb8795a250 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs @@ -39,7 +39,7 @@ public async Task GetSymbolsAsync(GoToSymbolContext context) foreach (var def in definitions) { - if (await def.CanNavigateToAsync(solution, cancellationToken).ConfigureAwait(false)) + if (await def.CanNavigateToAsync(solution.Workspace, cancellationToken).ConfigureAwait(false)) context.AddItem(WellKnownSymbolTypes.Definition, def); } diff --git a/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs b/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs index 37e170b3e68d8..4e83525cd49dd 100644 --- a/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs +++ b/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs @@ -73,7 +73,7 @@ public static async Task TryNavigateToOrPresentItemsAsync( foreach (var item in items) { // Ignore any definitions that we can't navigate to. - if (await item.CanNavigateToAsync(solution, cancellationToken).ConfigureAwait(false)) + if (await item.CanNavigateToAsync(solution.Workspace, cancellationToken).ConfigureAwait(false)) definitionsBuilder.Add(item); } @@ -87,7 +87,7 @@ public static async Task TryNavigateToOrPresentItemsAsync( // If we're directly going to a location we need to activate the preview so // that focus follows to the new cursor position. This behavior is expected // because we are only going to navigate once successfully - if (await item.TryNavigateToAsync(solution, showInPreviewTab: true, activateTab: true, cancellationToken).ConfigureAwait(false)) + if (await item.TryNavigateToAsync(solution.Workspace, showInPreviewTab: true, activateTab: true, cancellationToken).ConfigureAwait(false)) return true; } @@ -104,7 +104,7 @@ public static async Task TryNavigateToOrPresentItemsAsync( // going to a location we need to activate the preview so that focus follows to the new cursor position. return await nonExternalItems[0].TryNavigateToAsync( - solution, showInPreviewTab: true, activateTab: true, cancellationToken).ConfigureAwait(false); + solution.Workspace, showInPreviewTab: true, activateTab: true, cancellationToken).ConfigureAwait(false); } if (presenter != null) @@ -121,11 +121,11 @@ public static async Task TryNavigateToOrPresentItemsAsync( try { foreach (var definition in nonExternalItems) - await context.OnDefinitionFoundAsync(solution, definition, cancellationToken).ConfigureAwait(false); + await context.OnDefinitionFoundAsync(definition, cancellationToken).ConfigureAwait(false); } finally { - await context.OnCompletedAsync(solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } diff --git a/src/EditorFeatures/Test/FindReferences/FindReferencesCommandHandlerTests.cs b/src/EditorFeatures/Test/FindReferences/FindReferencesCommandHandlerTests.cs index afae423000e15..38bcb96c02e7b 100644 --- a/src/EditorFeatures/Test/FindReferences/FindReferencesCommandHandlerTests.cs +++ b/src/EditorFeatures/Test/FindReferences/FindReferencesCommandHandlerTests.cs @@ -31,7 +31,7 @@ private class MockFindUsagesContext : FindUsagesContext { public readonly List Result = new List(); - public override ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) + public override ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) { lock (Result) { diff --git a/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs b/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs index 26c50abe7da0c..683b6ca5ec23f 100644 --- a/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs +++ b/src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs @@ -98,19 +98,11 @@ private static async Task VerifyInheritanceMemberAsync(TestWorkspace testWorkspa .ToImmutableArray(); for (var i = 0; i < expectedTargets.Length; i++) { -<<<<<<< HEAD - await VerifyInheritanceTargetAsync(testWorkspace.CurrentSolution, expectedTargets[i], sortedActualTargets[i]); - } - } - - private static async Task VerifyInheritanceTargetAsync(Solution solution, TestInheritanceTargetItem expectedTarget, InheritanceTargetItem actualTarget) -======= await VerifyInheritanceTargetAsync(expectedTargets[i], sortedActualTargets[i]); } } private static async Task VerifyInheritanceTargetAsync(TestInheritanceTargetItem expectedTarget, InheritanceTargetItem actualTarget) ->>>>>>> upstream/main { Assert.Equal(expectedTarget.TargetSymbolName, actualTarget.DefinitionItem.DisplayParts.JoinText()); Assert.Equal(expectedTarget.RelationshipToMember, actualTarget.RelationToMember); @@ -127,16 +119,9 @@ private static async Task VerifyInheritanceTargetAsync(TestInheritanceTargetItem Assert.Equal(expectedDocumentSpans.Length, actualDocumentSpans.Length); for (var i = 0; i < actualDocumentSpans.Length; i++) { -<<<<<<< HEAD - var docSpan = await actualDocumentSpans[i].TryRehydrateAsync(solution, CancellationToken.None); + var docSpan = await actualDocumentSpans[i].TryRehydrateAsync(CancellationToken.None); Assert.Equal(expectedDocumentSpans[i].SourceSpan, docSpan.Value.SourceSpan); Assert.Equal(expectedDocumentSpans[i].Document.FilePath, docSpan.Value.Document.FilePath); -======= - Assert.Equal(expectedDocumentSpans[i].SourceSpan, actualDocumentSpans[i].SourceSpan); - var rehydrated = await actualDocumentSpans[i].TryRehydrateAsync(CancellationToken.None); - Assert.NotNull(rehydrated); - Assert.Equal(expectedDocumentSpans[i].Document.FilePath, rehydrated.Value.Document.FilePath); ->>>>>>> upstream/main } } } diff --git a/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb b/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb index 305867318ae4d..dcee9ca217c75 100644 --- a/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb +++ b/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb @@ -182,26 +182,24 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Return additionalPropertiesMap End Function - Private Shared Async Function GetFileNamesAndSpansAsync(solution As Solution, items As IEnumerable(Of DocumentIdSpan)) As Task(Of List(Of FileNameAndSpans)) - Dim dict = New Dictionary(Of Document, List(Of DocumentIdSpan)) + Private Shared Function GetFileNamesAndSpansAsync(solution As Solution, items As IEnumerable(Of DocumentSpan)) As Task(Of List(Of FileNameAndSpans)) + Dim dict = New Dictionary(Of Document, List(Of DocumentSpan)) For Each item In items - Dim docSpan = Await item.TryRehydrateAsync(solution, CancellationToken.None) - - Dim list As List(Of DocumentIdSpan) = Nothing - If Not dict.TryGetValue(docSpan.Value.Document, list) Then - list = New List(Of DocumentIdSpan)() - dict.Add(docSpan.Value.Document, list) + Dim list As List(Of DocumentSpan) = Nothing + If Not dict.TryGetValue(item.Document, list) Then + list = New List(Of DocumentSpan)() + dict.Add(item.Document, list) End If list.Add(item) Next - Return dict.OrderBy(Function(g) g.Key.Name). - Select(Function(g) GetFileNameAndSpans(g.Key, g.Value)).ToList() + Return Task.FromResult(dict.OrderBy(Function(g) g.Key.Name). + Select(Function(g) GetFileNameAndSpans(g.Key, g.Value)).ToList()) End Function - Private Shared Function GetFileNameAndSpans(document As Document, items As List(Of DocumentIdSpan)) As FileNameAndSpans + Private Shared Function GetFileNameAndSpans(document As Document, items As List(Of DocumentSpan)) As FileNameAndSpans Return New FileNameAndSpans( document.Name, items.Select(Function(i) i.SourceSpan).OrderBy(Function(s) s.Start).Distinct().ToList()) @@ -249,7 +247,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Return definition.DisplayIfNoReferences End Function - Public Overrides Function OnDefinitionFoundAsync(solution As Solution, definition As DefinitionItem, cancellationToken As CancellationToken) As ValueTask + Public Overrides Function OnDefinitionFoundAsync(definition As DefinitionItem, cancellationToken As CancellationToken) As ValueTask SyncLock gate Me.Definitions.Add(definition) End SyncLock @@ -257,7 +255,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Return Nothing End Function - Public Overrides Function OnReferenceFoundAsync(solution As Solution, reference As SourceReferenceItem, cancellationToken As CancellationToken) As ValueTask + Public Overrides Function OnReferenceFoundAsync(reference As SourceReferenceItem, cancellationToken As CancellationToken) As ValueTask SyncLock gate References.Add(reference) End SyncLock diff --git a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb index 284c6ffa9dfb4..5bf9d604595f1 100644 --- a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb +++ b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb @@ -14,7 +14,7 @@ Imports Microsoft.VisualStudio.Text Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition Public Class GoToDefinitionTestsBase - Private Shared Async Function Test( + Private Shared Function Test( workspaceDefinition As XElement, expectedResult As Boolean, executeOnDocument As Func(Of Document, Integer, IThreadingContext, IStreamingFindUsagesPresenter, Boolean)) As Task @@ -91,8 +91,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition For Each location In items For Each ss In location.SourceSpans - Dim docSpan = Await ss.TryRehydrateAsync(document.Project.Solution, CancellationToken.None) - actualLocations.Add(New FilePathAndSpan(docSpan.Value.Document.FilePath, docSpan.Value.SourceSpan)) + actualLocations.Add(New FilePathAndSpan(ss.Document.FilePath, ss.SourceSpan)) Next Next @@ -109,6 +108,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition Assert.False(presenterCalled) End If + Return Task.CompletedTask End Using End Function diff --git a/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb b/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb index 26a325d409ada..0d354ff4bd3aa 100644 --- a/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb +++ b/src/EditorFeatures/Test2/GoToHelpers/GoToHelpers.vb @@ -35,8 +35,7 @@ Friend Class GoToHelpers For Each definition In context.GetDefinitions() For Each sourceSpan In definition.SourceSpans - Dim docSpan = Await sourceSpan.TryRehydrateAsync(solution, CancellationToken.None) - actualDefinitions.Add(New FilePathAndSpan(docSpan.Value.Document.FilePath, docSpan.Value.SourceSpan)) + actualDefinitions.Add(New FilePathAndSpan(sourceSpan.Document.FilePath, sourceSpan.SourceSpan)) Next Next actualDefinitions.Sort() diff --git a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb index db83d65093ea4..de4c825d85281 100644 --- a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb +++ b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb @@ -26,7 +26,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers Return SpecializedTasks.True End Function - Public Function WouldNavigateToSymbolAsync(solution As Solution, definitionItem As DefinitionItem, cancellationToken As CancellationToken) As Task(Of (filePath As String, lineNumber As Integer, charOffset As Integer)?) Implements ISymbolNavigationService.WouldNavigateToSymbolAsync + Public Function WouldNavigateToSymbolAsync(definitionItem As DefinitionItem, cancellationToken As CancellationToken) As Task(Of (filePath As String, lineNumber As Integer, charOffset As Integer)?) Implements ISymbolNavigationService.WouldNavigateToSymbolAsync _wouldNavigateToSymbol = True Return Task.FromResult(Of (filePath As String, lineNumber As Integer, charOffset As Integer)?)(Nothing) End Function diff --git a/src/EditorFeatures/TestUtilities2/Utilities/MockSymbolNavigationServiceProvider.vb b/src/EditorFeatures/TestUtilities2/Utilities/MockSymbolNavigationServiceProvider.vb index a3851a5366d92..dc126a7372e26 100644 --- a/src/EditorFeatures/TestUtilities2/Utilities/MockSymbolNavigationServiceProvider.vb +++ b/src/EditorFeatures/TestUtilities2/Utilities/MockSymbolNavigationServiceProvider.vb @@ -62,7 +62,6 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities End Function Public Function WouldNavigateToSymbolAsync( - solution As Solution, definitionItem As DefinitionItem, cancellationToken As CancellationToken) As Task(Of (filePath As String, lineNumber As Integer, charOffset As Integer)?) Implements ISymbolNavigationService.WouldNavigateToSymbolAsync Me.WouldNavigateToSymbolProvidedDefinitionItem = definitionItem diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.DefaultDefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.DefaultDefinitionItem.cs index 9d074f898dc6c..d1d5c57c0c225 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.DefaultDefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.DefaultDefinitionItem.cs @@ -37,32 +37,34 @@ public DefaultDefinitionItem( { } - public sealed override bool CanNavigateTo(Workspace workspace, CancellationToken cancellationToken) + [Obsolete("Override CanNavigateToAsync instead", error: false)] + public override bool CanNavigateTo(Workspace workspace, CancellationToken cancellationToken) + => throw new NotImplementedException(); + + [Obsolete("Override TryNavigateToAsync instead", error: false)] + public override bool TryNavigateTo(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) + => throw new NotImplementedException(); + + public sealed override async Task CanNavigateToAsync(Workspace workspace, CancellationToken cancellationToken) { if (Properties.ContainsKey(NonNavigable)) return false; if (Properties.TryGetValue(MetadataSymbolKey, out var symbolKey)) - return CanNavigateToMetadataSymbol(solution.Workspace, symbolKey); - - if (await this.SourceSpans[0].TryRehydrateAsync(solution, cancellationToken).ConfigureAwait(false) is not DocumentSpan span) - return false; + return CanNavigateToMetadataSymbol(workspace, symbolKey); - return await span.CanNavigateToAsync(cancellationToken).ConfigureAwait(false); + return await this.SourceSpans[0].CanNavigateToAsync(cancellationToken).ConfigureAwait(false); } - public sealed override bool TryNavigateTo(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) + public sealed override async Task TryNavigateToAsync(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) { if (Properties.ContainsKey(NonNavigable)) return false; if (Properties.TryGetValue(MetadataSymbolKey, out var symbolKey)) - return TryNavigateToMetadataSymbol(solution.Workspace, symbolKey); - - if (await this.SourceSpans[0].TryRehydrateAsync(solution, cancellationToken).ConfigureAwait(false) is not DocumentSpan span) - return false; + return TryNavigateToMetadataSymbol(workspace, symbolKey); - return await span.TryNavigateToAsync(showInPreviewTab, activateTab, cancellationToken).ConfigureAwait(false); + return await this.SourceSpans[0].TryNavigateToAsync(showInPreviewTab, activateTab, cancellationToken).ConfigureAwait(false); } public DetachedDefinitionItem Detach() diff --git a/src/Features/Core/Portable/FindUsages/DefinitionItem.cs b/src/Features/Core/Portable/FindUsages/DefinitionItem.cs index 662bdb8f470e8..06c21ede36a09 100644 --- a/src/Features/Core/Portable/FindUsages/DefinitionItem.cs +++ b/src/Features/Core/Portable/FindUsages/DefinitionItem.cs @@ -95,7 +95,7 @@ internal abstract partial class DefinitionItem /// Additional locations to present in the UI. A definition may have multiple locations /// for cases like partial types/members. /// - public ImmutableArray SourceSpans { get; } + public ImmutableArray SourceSpans { get; } /// /// Whether or not this definition should be presented if we never found any references to @@ -146,7 +146,7 @@ protected DefinitionItem( DisplayParts = displayParts; NameDisplayParts = nameDisplayParts.IsDefaultOrEmpty ? displayParts : nameDisplayParts; OriginationParts = originationParts.NullToEmpty(); - SourceSpans = sourceSpans.NullToEmpty().SelectAsArray(ss => new DocumentIdSpan(ss)); + SourceSpans = sourceSpans.NullToEmpty(); Properties = properties ?? ImmutableDictionary.Empty; DisplayableProperties = displayableProperties ?? ImmutableDictionary.Empty; DisplayIfNoReferences = displayIfNoReferences; @@ -163,17 +163,17 @@ protected DefinitionItem( [Obsolete("Override TryNavigateToAsync instead", error: false)] public abstract bool TryNavigateTo(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken); - public virtual Task CanNavigateToAsync(Solution solution, CancellationToken cancellationToken) + public virtual Task CanNavigateToAsync(Workspace workspace, CancellationToken cancellationToken) { #pragma warning disable CS0618 // Type or member is obsolete - return Task.FromResult(CanNavigateTo(solution.Workspace, cancellationToken)); + return Task.FromResult(CanNavigateTo(workspace, cancellationToken)); #pragma warning restore CS0618 // Type or member is obsolete } - public virtual Task TryNavigateToAsync(Solution solution, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) + public virtual Task TryNavigateToAsync(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) { #pragma warning disable CS0618 // Type or member is obsolete - return Task.FromResult(TryNavigateTo(solution.Workspace, showInPreviewTab, activateTab, cancellationToken)); + return Task.FromResult(TryNavigateTo(workspace, showInPreviewTab, activateTab, cancellationToken)); #pragma warning restore CS0618 // Type or member is obsolete } diff --git a/src/Features/Core/Portable/FindUsages/IFindUsagesContext.cs b/src/Features/Core/Portable/FindUsages/IFindUsagesContext.cs index 40621c114592e..aa818a48152e9 100644 --- a/src/Features/Core/Portable/FindUsages/IFindUsagesContext.cs +++ b/src/Features/Core/Portable/FindUsages/IFindUsagesContext.cs @@ -27,7 +27,7 @@ internal interface IFindUsagesContext /// ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken); - ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken); - ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken); + ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken); + ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken); } } diff --git a/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs b/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs index 6ba65045782fc..67329e31f308f 100644 --- a/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs +++ b/src/Features/Core/Portable/FindUsages/IRemoteFindUsagesService.cs @@ -108,14 +108,14 @@ public async ValueTask OnDefinitionFoundAsync(SerializableDefinitionItem definit _idToDefinition.Add(id, rehydrated); } - await _context.OnDefinitionFoundAsync(_solution, rehydrated, cancellationToken).ConfigureAwait(false); + await _context.OnDefinitionFoundAsync(rehydrated, cancellationToken).ConfigureAwait(false); } public async ValueTask OnReferenceFoundAsync(SerializableSourceReferenceItem reference, CancellationToken cancellationToken) { var rehydrated = await reference.RehydrateAsync(_solution, GetDefinition(reference.DefinitionId), cancellationToken).ConfigureAwait(false); - await _context.OnReferenceFoundAsync(_solution, rehydrated, cancellationToken).ConfigureAwait(false); + await _context.OnReferenceFoundAsync(rehydrated, cancellationToken).ConfigureAwait(false); } private DefinitionItem GetDefinition(int definitionId) @@ -143,8 +143,8 @@ public SerializableDocumentSpan(DocumentId documentId, TextSpan sourceSpan) SourceSpan = sourceSpan; } - public static SerializableDocumentSpan Dehydrate(DocumentIdSpan documentSpan) - => new(documentSpan.DocumentId, documentSpan.SourceSpan); + public static SerializableDocumentSpan Dehydrate(DocumentSpan documentSpan) + => new(documentSpan.Document.Id, documentSpan.SourceSpan); public async ValueTask RehydrateAsync(Solution solution, CancellationToken cancellationToken) { diff --git a/src/Features/Core/Portable/FindUsages/SourceReferenceItem.cs b/src/Features/Core/Portable/FindUsages/SourceReferenceItem.cs index d0be9b9772497..98404758d1e2a 100644 --- a/src/Features/Core/Portable/FindUsages/SourceReferenceItem.cs +++ b/src/Features/Core/Portable/FindUsages/SourceReferenceItem.cs @@ -22,7 +22,7 @@ internal sealed class SourceReferenceItem /// /// The location of the source item. /// - public DocumentIdSpan SourceSpan { get; } + public DocumentSpan SourceSpan { get; } /// /// If this reference is a location where the definition is written to. @@ -50,7 +50,7 @@ private SourceReferenceItem( bool isWrittenTo) { Definition = definition; - SourceSpan = new DocumentIdSpan(sourceSpan); + SourceSpan = sourceSpan; SymbolUsageInfo = symbolUsageInfo; IsWrittenTo = isWrittenTo; AdditionalProperties = additionalProperties ?? ImmutableDictionary.Empty; diff --git a/src/Features/Core/Portable/Navigation/DefaultSymbolNavigationService.cs b/src/Features/Core/Portable/Navigation/DefaultSymbolNavigationService.cs index 5fed9d8a4b8e7..d571c0922d358 100644 --- a/src/Features/Core/Portable/Navigation/DefaultSymbolNavigationService.cs +++ b/src/Features/Core/Portable/Navigation/DefaultSymbolNavigationService.cs @@ -19,7 +19,7 @@ public Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project project => SpecializedTasks.False; public Task<(string filePath, int lineNumber, int charOffset)?> WouldNavigateToSymbolAsync( - Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken) + DefinitionItem definitionItem, CancellationToken cancellationToken) { return Task.FromResult<(string filePath, int lineNumber, int charOffset)?>(null); } diff --git a/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs b/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs index 03354f84985cd..adc276d6ac08a 100644 --- a/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs +++ b/src/Features/Core/Portable/Navigation/ISymbolNavigationService.cs @@ -29,6 +29,6 @@ internal interface ISymbolNavigationService : IWorkspaceService /// Non-null if the navigation would be handled. Task<(string filePath, int lineNumber, int charOffset)?> WouldNavigateToSymbolAsync( - Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken); + DefinitionItem definitionItem, CancellationToken cancellationToken); } } diff --git a/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs b/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs index 2919b1d5f9804..86253b58495eb 100644 --- a/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs +++ b/src/Features/LanguageServer/Protocol/CustomProtocol/FindUsagesLSPContext.cs @@ -86,10 +86,10 @@ public FindUsagesLSPContext( } // After all definitions/references have been found, wait here until all results have been reported. - public override async ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) + public override async ValueTask OnCompletedAsync(CancellationToken cancellationToken) => await _workQueue.WaitUntilCurrentBatchCompletesAsync().ConfigureAwait(false); - public override async ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) + public override async ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) { using (await _semaphore.DisposableWaitAsync(cancellationToken).ConfigureAwait(false)) { @@ -124,7 +124,7 @@ public override async ValueTask OnDefinitionFoundAsync(Solution solution, Defini } } - public override async ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) + public override async ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) { using (await _semaphore.DisposableWaitAsync(cancellationToken).ConfigureAwait(false)) { @@ -133,11 +133,8 @@ public override async ValueTask OnReferenceFoundAsync(Solution solution, SourceR if (!_definitionToId.TryGetValue(reference.Definition, out var definitionId)) return; - var documentSpan = await reference.SourceSpan.TryRehydrateAsync(solution, cancellationToken).ConfigureAwait(false); - if (documentSpan == null) - return; - - var document = documentSpan.Value.Document; + var documentSpan = reference.SourceSpan; + var document = documentSpan.Document; // If this is reference to the same physical location we've already reported, just // filter this out. it will clutter the UI to show the same places. @@ -171,7 +168,7 @@ public override async ValueTask OnReferenceFoundAsync(Solution solution, SourceR int? definitionId, Document document, int position, - DocumentIdSpan? serializableDocumentSpan, + DocumentSpan? documentSpan, ImmutableDictionary properties, IMetadataAsSourceFileService metadataAsSourceFileService, ClassifiedTextElement? definitionText, @@ -180,9 +177,6 @@ public override async ValueTask OnReferenceFoundAsync(Solution solution, SourceR bool isWrittenTo, CancellationToken cancellationToken) { - var documentSpan = serializableDocumentSpan == null - ? null - : await serializableDocumentSpan.Value.TryRehydrateAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); var location = await ComputeLocationAsync(document, position, documentSpan, metadataAsSourceFileService, cancellationToken).ConfigureAwait(false); // Getting the text for the Text property. If we somehow can't compute the text, that means we're probably dealing with a metadata diff --git a/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs b/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs index f9c2d6a47afe0..e36ac13036669 100644 --- a/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/References/FindAllReferencesHandler.cs @@ -63,7 +63,7 @@ public FindAllReferencesHandler( // Finds the references for the symbol at the specific position in the document, reporting them via streaming to the LSP client. await findUsagesService.FindReferencesAsync(document, position, findUsagesContext, cancellationToken).ConfigureAwait(false); - await findUsagesContext.OnCompletedAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); + await findUsagesContext.OnCompletedAsync(cancellationToken).ConfigureAwait(false); return progress.GetValues(); } diff --git a/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs b/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs index 862059bf253a8..628ac7e85555d 100644 --- a/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/References/FindImplementationsHandler.cs @@ -51,17 +51,13 @@ public FindImplementationsHandler() var text = definition.GetClassifiedText(); foreach (var sourceSpan in definition.SourceSpans) { - var span = await sourceSpan.TryRehydrateAsync(document.Project.Solution, cancellationToken).ConfigureAwait(false); - if (span == null) - continue; - if (context.ClientCapabilities?.HasVisualStudioLspCapability() == true) { - locations.AddIfNotNull(await ProtocolConversions.DocumentSpanToLocationWithTextAsync(span.Value, text, cancellationToken).ConfigureAwait(false)); + locations.AddIfNotNull(await ProtocolConversions.DocumentSpanToLocationWithTextAsync(sourceSpan, text, cancellationToken).ConfigureAwait(false)); } else { - locations.AddIfNotNull(await ProtocolConversions.DocumentSpanToLocationAsync(span.Value, cancellationToken).ConfigureAwait(false)); + locations.AddIfNotNull(await ProtocolConversions.DocumentSpanToLocationAsync(sourceSpan, cancellationToken).ConfigureAwait(false)); } } } diff --git a/src/Tools/ExternalAccess/Debugger/DebuggerFindReferencesService.cs b/src/Tools/ExternalAccess/Debugger/DebuggerFindReferencesService.cs index c1c2aa6661fde..c7526f1d34bc8 100644 --- a/src/Tools/ExternalAccess/Debugger/DebuggerFindReferencesService.cs +++ b/src/Tools/ExternalAccess/Debugger/DebuggerFindReferencesService.cs @@ -48,7 +48,7 @@ public async Task FindSymbolReferencesAsync(ISymbol symbol, Project project, Can } finally { - await context.OnCompletedAsync(project.Solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } } diff --git a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs index 6d5d0b1727d1f..e8bf8c1cb9041 100644 --- a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs +++ b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesContext.cs @@ -11,13 +11,11 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.FSharp.Internal.Editor.FindUsage { internal class FSharpFindUsagesContext : IFSharpFindUsagesContext { - private readonly Solution _solution; private readonly IFindUsagesContext _context; private readonly CancellationToken _cancellationToken; - public FSharpFindUsagesContext(Solution solution, IFindUsagesContext context, CancellationToken cancellationToken) + public FSharpFindUsagesContext(IFindUsagesContext context, CancellationToken cancellationToken) { - _solution = solution; _context = context; _cancellationToken = cancellationToken; } @@ -26,12 +24,12 @@ public FSharpFindUsagesContext(Solution solution, IFindUsagesContext context, Ca public Task OnDefinitionFoundAsync(FSharp.FindUsages.FSharpDefinitionItem definition) { - return _context.OnDefinitionFoundAsync(_solution, definition.RoslynDefinitionItem, _cancellationToken).AsTask(); + return _context.OnDefinitionFoundAsync(definition.RoslynDefinitionItem, _cancellationToken).AsTask(); } public Task OnReferenceFoundAsync(FSharp.FindUsages.FSharpSourceReferenceItem reference) { - return _context.OnReferenceFoundAsync(_solution, reference.RoslynSourceReferenceItem, _cancellationToken).AsTask(); + return _context.OnReferenceFoundAsync(reference.RoslynSourceReferenceItem, _cancellationToken).AsTask(); } public Task ReportMessageAsync(string message) diff --git a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesService.cs b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesService.cs index 8a3ccefe71b52..623dda3cb550c 100644 --- a/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesService.cs +++ b/src/Tools/ExternalAccess/FSharp/Internal/Editor/FindUsages/FSharpFindUsagesService.cs @@ -25,9 +25,9 @@ public FSharpFindUsagesService(IFSharpFindUsagesService service) => _service = service; public Task FindImplementationsAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _service.FindImplementationsAsync(document, position, new FSharpFindUsagesContext(document.Project.Solution, context, cancellationToken)); + => _service.FindImplementationsAsync(document, position, new FSharpFindUsagesContext(context, cancellationToken)); public Task FindReferencesAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken) - => _service.FindReferencesAsync(document, position, new FSharpFindUsagesContext(document.Project.Solution, context, cancellationToken)); + => _service.FindReferencesAsync(document, position, new FSharpFindUsagesContext(context, cancellationToken)); } } diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs index d44ccb1fde635..1c41de6ddf81f 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs @@ -303,44 +303,39 @@ public sealed override ValueTask SetSearchTitleAsync(string title, CancellationT return default; } - public sealed override async ValueTask OnCompletedAsync(Solution solution, CancellationToken cancellationToken) + public sealed override async ValueTask OnCompletedAsync(CancellationToken cancellationToken) { - await OnCompletedAsyncWorkerAsync(solution, cancellationToken).ConfigureAwait(false); + await OnCompletedAsyncWorkerAsync(cancellationToken).ConfigureAwait(false); _tableDataSink.IsStable = true; } - protected abstract Task OnCompletedAsyncWorkerAsync(Solution solution, CancellationToken cancellationToken); + protected abstract Task OnCompletedAsyncWorkerAsync(CancellationToken cancellationToken); - public sealed override ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) + public sealed override ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) { lock (Gate) { Definitions.Add(definition); } - return OnDefinitionFoundWorkerAsync(solution, definition, cancellationToken); + return OnDefinitionFoundWorkerAsync(definition, cancellationToken); } - protected abstract ValueTask OnDefinitionFoundWorkerAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken); + protected abstract ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem definition, CancellationToken cancellationToken); protected async Task TryCreateDocumentSpanEntryAsync( - Solution solution, RoslynDefinitionBucket definitionBucket, - DocumentIdSpan idSpan, + DocumentSpan documentSpan, HighlightSpanKind spanKind, SymbolUsageInfo symbolUsageInfo, ImmutableDictionary additionalProperties, CancellationToken cancellationToken) { - var documentSpan = await idSpan.TryRehydrateAsync(solution, cancellationToken).ConfigureAwait(false); - if (documentSpan == null) - return null; - - var document = documentSpan.Value.Document; + var document = documentSpan.Document; var sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); - var (excerptResult, lineText) = await ExcerptAsync(sourceText, documentSpan.Value, cancellationToken).ConfigureAwait(false); + var (excerptResult, lineText) = await ExcerptAsync(sourceText, documentSpan, cancellationToken).ConfigureAwait(false); - var mappedDocumentSpan = await AbstractDocumentSpanEntry.TryMapAndGetFirstAsync(documentSpan.Value, sourceText, cancellationToken).ConfigureAwait(false); + var mappedDocumentSpan = await AbstractDocumentSpanEntry.TryMapAndGetFirstAsync(documentSpan, sourceText, cancellationToken).ConfigureAwait(false); if (mappedDocumentSpan == null) { // this will be removed from the result @@ -356,7 +351,7 @@ public sealed override ValueTask OnDefinitionFoundAsync(Solution solution, Defin projectName, projectFlavor, document.FilePath, - documentSpan.Value.SourceSpan, + documentSpan.SourceSpan, spanKind, mappedDocumentSpan.Value, excerptResult, @@ -391,10 +386,10 @@ public sealed override ValueTask OnDefinitionFoundAsync(Solution solution, Defin return (excerptResult, AbstractDocumentSpanEntry.GetLineContainingPosition(sourceText, documentSpan.SourceSpan.Start)); } - public sealed override ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) - => OnReferenceFoundWorkerAsync(solution, reference, cancellationToken); + public sealed override ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) + => OnReferenceFoundWorkerAsync(reference, cancellationToken); - protected abstract ValueTask OnReferenceFoundWorkerAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken); + protected abstract ValueTask OnReferenceFoundWorkerAsync(SourceReferenceItem reference, CancellationToken cancellationToken); protected RoslynDefinitionBucket GetOrCreateDefinitionBucket(DefinitionItem definition, bool expandedByDefault) { diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs index f32839fd85e17..991572355d512 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithReferencesFindUsagesContext.cs @@ -38,16 +38,16 @@ public WithReferencesFindUsagesContext( { } - protected override async ValueTask OnDefinitionFoundWorkerAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) + protected override async ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem definition, CancellationToken cancellationToken) { // If this is a definition we always want to show, then create entries for all the declaration locations // immediately. Otherwise, we'll create them on demand when we hear about references for this // definition. if (definition.DisplayIfNoReferences) - await AddDeclarationEntriesAsync(solution, definition, expandedByDefault: true, cancellationToken).ConfigureAwait(false); + await AddDeclarationEntriesAsync(definition, expandedByDefault: true, cancellationToken).ConfigureAwait(false); } - private async Task AddDeclarationEntriesAsync(Solution solution, DefinitionItem definition, bool expandedByDefault, CancellationToken cancellationToken) + private async Task AddDeclarationEntriesAsync(DefinitionItem definition, bool expandedByDefault, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -70,7 +70,7 @@ private async Task AddDeclarationEntriesAsync(Solution solution, DefinitionItem foreach (var declarationLocation in definition.SourceSpans) { var definitionEntry = await TryCreateDocumentSpanEntryAsync( - solution, definitionBucket, declarationLocation, HighlightSpanKind.Definition, SymbolUsageInfo.None, + definitionBucket, declarationLocation, HighlightSpanKind.Definition, SymbolUsageInfo.None, additionalProperties: definition.DisplayableProperties, cancellationToken).ConfigureAwait(false); declarations.AddIfNotNull(definitionEntry); } @@ -105,15 +105,13 @@ private bool HasDeclarationEntries(DefinitionItem definition) } } - protected override ValueTask OnReferenceFoundWorkerAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) + protected override ValueTask OnReferenceFoundWorkerAsync(SourceReferenceItem reference, CancellationToken cancellationToken) { // Normal references go into both sets of entries. We ensure an entry for the definition, and an entry // for the reference itself. return OnEntryFoundAsync( - solution, reference.Definition, bucket => TryCreateDocumentSpanEntryAsync( - solution, bucket, reference.SourceSpan, reference.IsWrittenTo ? HighlightSpanKind.WrittenReference : HighlightSpanKind.Reference, reference.SymbolUsageInfo, @@ -126,7 +124,6 @@ protected override ValueTask OnReferenceFoundWorkerAsync(Solution solution, Sour } private async ValueTask OnEntryFoundAsync( - Solution solution, DefinitionItem definition, Func> createEntryAsync, bool addToEntriesWhenGroupingByDefinition, @@ -141,7 +138,7 @@ private async ValueTask OnEntryFoundAsync( // that we haven't created any declaration entries for (i.e. because it had DisplayIfNoReferences = // false). Because we've now found a reference, we want to make sure all its declaration entries are // added. - await AddDeclarationEntriesAsync(solution, definition, expandedByDefault, cancellationToken).ConfigureAwait(false); + await AddDeclarationEntriesAsync(definition, expandedByDefault, cancellationToken).ConfigureAwait(false); // First find the bucket corresponding to our definition. var definitionBucket = GetOrCreateDefinitionBucket(definition, expandedByDefault); @@ -169,22 +166,22 @@ private async ValueTask OnEntryFoundAsync( NotifyChange(); } - protected override async Task OnCompletedAsyncWorkerAsync(Solution solution, CancellationToken cancellationToken) + protected override async Task OnCompletedAsyncWorkerAsync(CancellationToken cancellationToken) { // Now that we know the search is over, create and display any error messages // for definitions that were not found. - await CreateMissingReferenceEntriesIfNecessaryAsync(solution, cancellationToken).ConfigureAwait(false); - await CreateNoResultsFoundEntryIfNecessaryAsync(solution, cancellationToken).ConfigureAwait(false); + await CreateMissingReferenceEntriesIfNecessaryAsync(cancellationToken).ConfigureAwait(false); + await CreateNoResultsFoundEntryIfNecessaryAsync(cancellationToken).ConfigureAwait(false); } - private async Task CreateMissingReferenceEntriesIfNecessaryAsync(Solution solution, CancellationToken cancellationToken) + private async Task CreateMissingReferenceEntriesIfNecessaryAsync(CancellationToken cancellationToken) { - await CreateMissingReferenceEntriesIfNecessaryAsync(solution, whenGroupingByDefinition: true, cancellationToken).ConfigureAwait(false); - await CreateMissingReferenceEntriesIfNecessaryAsync(solution, whenGroupingByDefinition: false, cancellationToken).ConfigureAwait(false); + await CreateMissingReferenceEntriesIfNecessaryAsync(whenGroupingByDefinition: true, cancellationToken).ConfigureAwait(false); + await CreateMissingReferenceEntriesIfNecessaryAsync(whenGroupingByDefinition: false, cancellationToken).ConfigureAwait(false); } private async Task CreateMissingReferenceEntriesIfNecessaryAsync( - Solution solution, bool whenGroupingByDefinition, CancellationToken cancellationToken) + bool whenGroupingByDefinition, CancellationToken cancellationToken) { // Go through and add dummy entries for any definitions that // that we didn't find any references for. @@ -195,7 +192,6 @@ private async Task CreateMissingReferenceEntriesIfNecessaryAsync( if (definition.IsExternal) { await OnEntryFoundAsync( - solution, definition, bucket => SimpleMessageEntry.CreateAsync(bucket, bucket, ServicesVSResources.External_reference_found)!, addToEntriesWhenGroupingByDefinition: whenGroupingByDefinition, @@ -210,7 +206,6 @@ await OnEntryFoundAsync( // We'll place this under a single bucket called "Symbols without references" and we'll allow // the user to navigate on that text entry to that definition if possible. await OnEntryFoundAsync( - solution, SymbolsWithoutReferencesDefinitionItem, bucket => SimpleMessageEntry.CreateAsync( definitionBucket: bucket, @@ -262,7 +257,7 @@ private ImmutableArray GetDefinitionsToCreateMissingReferenceIte } } - private async Task CreateNoResultsFoundEntryIfNecessaryAsync(Solution solution, CancellationToken cancellationToken) + private async Task CreateNoResultsFoundEntryIfNecessaryAsync(CancellationToken cancellationToken) { bool noDefinitions; lock (Gate) @@ -274,7 +269,6 @@ private async Task CreateNoResultsFoundEntryIfNecessaryAsync(Solution solution, { // Create a fake definition/reference called "search found no results" await OnEntryFoundAsync( - solution, NoResultsDefinitionItem, bucket => SimpleMessageEntry.CreateAsync(bucket, null, ServicesVSResources.Search_found_no_results)!, addToEntriesWhenGroupingByDefinition: true, diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs index c5f4ae03c9a29..a7b995683d608 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs @@ -36,14 +36,14 @@ public WithoutReferencesFindUsagesContext( } // We should never be called in a context where we get references. - protected override ValueTask OnReferenceFoundWorkerAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) + protected override ValueTask OnReferenceFoundWorkerAsync(SourceReferenceItem reference, CancellationToken cancellationToken) => throw new InvalidOperationException(); // Nothing to do on completion. - protected override Task OnCompletedAsyncWorkerAsync(Solution solution, CancellationToken cancellationToken) + protected override Task OnCompletedAsyncWorkerAsync(CancellationToken cancellationToken) => Task.CompletedTask; - protected override async ValueTask OnDefinitionFoundWorkerAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) + protected override async ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem definition, CancellationToken cancellationToken) { var definitionBucket = GetOrCreateDefinitionBucket(definition, expandedByDefault: true); @@ -55,7 +55,7 @@ protected override async ValueTask OnDefinitionFoundWorkerAsync(Solution solutio // definition as what to show. That way we show enough information for things // methods. i.e. we'll show "void TypeName.MethodName(args...)" allowing // the user to see the type the method was created in. - var entry = await TryCreateEntryAsync(solution, definitionBucket, definition, cancellationToken).ConfigureAwait(false); + var entry = await TryCreateEntryAsync(definitionBucket, definition, cancellationToken).ConfigureAwait(false); entries.AddIfNotNull(entry); } else if (definition.SourceSpans.Length == 0) @@ -73,7 +73,6 @@ protected override async ValueTask OnDefinitionFoundWorkerAsync(Solution solutio foreach (var sourceSpan in definition.SourceSpans) { var entry = await TryCreateDocumentSpanEntryAsync( - solution, definitionBucket, sourceSpan, HighlightSpanKind.Definition, @@ -97,17 +96,15 @@ protected override async ValueTask OnDefinitionFoundWorkerAsync(Solution solutio } private async Task TryCreateEntryAsync( - Solution solution, RoslynDefinitionBucket definitionBucket, DefinitionItem definition, CancellationToken cancellationToken) + RoslynDefinitionBucket definitionBucket, DefinitionItem definition, CancellationToken cancellationToken) { - var documentSpan = await definition.SourceSpans[0].TryRehydrateAsync(solution, cancellationToken).ConfigureAwait(false); - if (documentSpan == null) - return null; + var documentSpan = definition.SourceSpans[0]; - var (guid, projectName, _) = GetGuidAndProjectInfo(documentSpan.Value.Document); - var sourceText = await documentSpan.Value.Document.GetTextAsync(cancellationToken).ConfigureAwait(false); + var (guid, projectName, _) = GetGuidAndProjectInfo(documentSpan.Document); + var sourceText = await documentSpan.Document.GetTextAsync(cancellationToken).ConfigureAwait(false); - var lineText = AbstractDocumentSpanEntry.GetLineContainingPosition(sourceText, documentSpan.Value.SourceSpan.Start); - var mappedDocumentSpan = await AbstractDocumentSpanEntry.TryMapAndGetFirstAsync(documentSpan.Value, sourceText, cancellationToken).ConfigureAwait(false); + var lineText = AbstractDocumentSpanEntry.GetLineContainingPosition(sourceText, documentSpan.SourceSpan.Start); + var mappedDocumentSpan = await AbstractDocumentSpanEntry.TryMapAndGetFirstAsync(documentSpan, sourceText, cancellationToken).ConfigureAwait(false); if (mappedDocumentSpan == null) { // this will be removed from the result diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/MetadataDefinitionItemEntry.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/MetadataDefinitionItemEntry.cs index 519b37fd51534..6895c3a9d8c6f 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/MetadataDefinitionItemEntry.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Entries/MetadataDefinitionItemEntry.cs @@ -36,7 +36,7 @@ public MetadataDefinitionItemEntry( Task ISupportsNavigation.TryNavigateToAsync(bool isPreview, CancellationToken cancellationToken) => DefinitionBucket.DefinitionItem.TryNavigateToAsync( - Presenter._workspace.CurrentSolution, showInPreviewTab: isPreview, activateTab: !isPreview, cancellationToken); // Only activate the tab if not opening in preview + Presenter._workspace, showInPreviewTab: isPreview, activateTab: !isPreview, cancellationToken); // Only activate the tab if not opening in preview protected override IList CreateLineTextInlines() => DefinitionBucket.DefinitionItem.DisplayParts diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/RoslynDefinitionBucket.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/RoslynDefinitionBucket.cs index 7731e9339cb74..1f7e02bfaefae 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/RoslynDefinitionBucket.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/RoslynDefinitionBucket.cs @@ -65,7 +65,7 @@ public static RoslynDefinitionBucket Create( public Task TryNavigateToAsync(bool isPreview, CancellationToken cancellationToken) => DefinitionItem.TryNavigateToAsync( - _presenter._workspace.CurrentSolution, showInPreviewTab: isPreview, activateTab: !isPreview, cancellationToken); // Only activate the tab if not opening in preview + _presenter._workspace, showInPreviewTab: isPreview, activateTab: !isPreview, cancellationToken); // Only activate the tab if not opening in preview public override bool TryGetValue(string key, out object? content) { diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs index 48ffa71a737d4..070c650ffe0cc 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/VisualStudioDefinitionsAndReferencesFactory.cs @@ -46,7 +46,7 @@ public VisualStudioDefinitionsAndReferencesFactory( Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken) { var symbolNavigationService = solution.Workspace.Services.GetRequiredService(); - var result = await symbolNavigationService.WouldNavigateToSymbolAsync(solution, definitionItem, cancellationToken).ConfigureAwait(false); + var result = await symbolNavigationService.WouldNavigateToSymbolAsync(definitionItem, cancellationToken).ConfigureAwait(false); if (result is not var (filePath, lineNumber, charOffset)) return null; @@ -117,10 +117,10 @@ public ExternalDefinitionItem( _charOffset = charOffset; } - public override Task CanNavigateToAsync(Solution solution, CancellationToken cancellationToken) + public override Task CanNavigateToAsync(Workspace workspace, CancellationToken cancellationToken) => SpecializedTasks.True; - public override async Task TryNavigateToAsync(Solution solution, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) + public override async Task TryNavigateToAsync(Workspace workspace, bool showInPreviewTab, bool activateTab, CancellationToken cancellationToken) { await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); return TryOpenFile() && TryNavigateToPosition(); diff --git a/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs b/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs index 181b903fc1e0b..5bca469a14289 100644 --- a/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs +++ b/src/VisualStudio/Core/Def/Implementation/Library/ObjectBrowser/AbstractObjectBrowserLibraryManager.cs @@ -525,7 +525,7 @@ await Task.Run( } finally { - await context.OnCompletedAsync(project.Solution, cancellationToken).ConfigureAwait(false); + await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs index ee17febe0f957..b97b8cb22302e 100644 --- a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs +++ b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs @@ -171,7 +171,7 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p var definitionItem = symbol.ToNonClassifiedDefinitionItem(project.Solution, includeHiddenLocations: true); definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey1, out var rqName); - var result = await TryGetNavigationAPIRequiredArgumentsAsync(project.Solution, definitionItem, rqName, cancellationToken).ConfigureAwait(true); + var result = await TryGetNavigationAPIRequiredArgumentsAsync(definitionItem, rqName, cancellationToken).ConfigureAwait(true); if (result is not var (hierarchy, itemID, navigationNotify)) return false; @@ -185,23 +185,23 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p } public async Task<(string filePath, int lineNumber, int charOffset)?> WouldNavigateToSymbolAsync( - Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken) + DefinitionItem definitionItem, CancellationToken cancellationToken) { definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey1, out var rqName1); definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey2, out var rqName2); - return await WouldNotifyToSpecificSymbolAsync(solution, definitionItem, rqName1, cancellationToken).ConfigureAwait(false) ?? - await WouldNotifyToSpecificSymbolAsync(solution, definitionItem, rqName2, cancellationToken).ConfigureAwait(false); + return await WouldNotifyToSpecificSymbolAsync(definitionItem, rqName1, cancellationToken).ConfigureAwait(false) ?? + await WouldNotifyToSpecificSymbolAsync(definitionItem, rqName2, cancellationToken).ConfigureAwait(false); } public async Task<(string filePath, int lineNumber, int charOffset)?> WouldNotifyToSpecificSymbolAsync( - Solution solution, DefinitionItem definitionItem, string? rqName, CancellationToken cancellationToken) + DefinitionItem definitionItem, string? rqName, CancellationToken cancellationToken) { if (rqName == null) return null; var values = await TryGetNavigationAPIRequiredArgumentsAsync( - solution, definitionItem, rqName, cancellationToken).ConfigureAwait(false); + definitionItem, rqName, cancellationToken).ConfigureAwait(false); if (values is not var (hierarchy, itemID, navigationNotify)) return null; @@ -229,7 +229,6 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p } private async Task<(IVsHierarchy hierarchy, uint itemId, IVsSymbolicNavigationNotify navigationNotify)?> TryGetNavigationAPIRequiredArgumentsAsync( - Solution solution, DefinitionItem definitionItem, string? rqName, CancellationToken cancellationToken) @@ -243,10 +242,7 @@ public async Task TrySymbolNavigationNotifyAsync(ISymbol symbol, Project p using var _ = ArrayBuilder.GetInstance(out var documentsBuilder); foreach (var loc in sourceLocations) - { - var docSpan = await loc.TryRehydrateAsync(solution, cancellationToken).ConfigureAwait(false); - documentsBuilder.AddIfNotNull(docSpan?.Document); - } + documentsBuilder.AddIfNotNull(loc.Document); var documents = documentsBuilder.ToImmutable(); diff --git a/src/Workspaces/Remote/ServiceHub/Services/FindUsages/RemoteFindUsagesService.cs b/src/Workspaces/Remote/ServiceHub/Services/FindUsages/RemoteFindUsagesService.cs index ba3fc3b7d4e9b..8ec4923b98d2c 100644 --- a/src/Workspaces/Remote/ServiceHub/Services/FindUsages/RemoteFindUsagesService.cs +++ b/src/Workspaces/Remote/ServiceHub/Services/FindUsages/RemoteFindUsagesService.cs @@ -108,7 +108,7 @@ public ValueTask ReportMessageAsync(string message, CancellationToken cancellati public ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) => _callback.InvokeAsync((callback, cancellationToken) => callback.SetSearchTitleAsync(_callbackId, title, cancellationToken), cancellationToken); - public ValueTask OnDefinitionFoundAsync(Solution solution, DefinitionItem definition, CancellationToken cancellationToken) + public ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken) { var id = GetOrAddDefinitionItemId(definition); var dehydratedDefinition = SerializableDefinitionItem.Dehydrate(id, definition); @@ -129,7 +129,7 @@ private int GetOrAddDefinitionItemId(DefinitionItem item) } } - public ValueTask OnReferenceFoundAsync(Solution solution, SourceReferenceItem reference, CancellationToken cancellationToken) + public ValueTask OnReferenceFoundAsync(SourceReferenceItem reference, CancellationToken cancellationToken) { var definitionItem = GetOrAddDefinitionItemId(reference.Definition); var dehydratedReference = SerializableSourceReferenceItem.Dehydrate(definitionItem, reference); From 4db39fa423f37bce433ef0a86a59078fe3a0fdbc Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 25 Aug 2021 11:49:40 -0700 Subject: [PATCH 36/42] Remove unneeded code --- .../Core/CommandHandlers/AbstractGoToCommandHandler.cs | 4 +--- .../Core/GoToBase/GoToBaseCommandHandler.cs | 3 --- .../GoToImplementationCommandHandler.cs | 10 ---------- .../MetadataAsSource/MetadataAsSourceFileService.cs | 2 +- .../MetadataAsSource/SymbolMappingServiceFactory.cs | 10 ---------- .../Portable/SymbolMapping/ISymbolMappingService.cs | 7 ------- .../SymbolMapping/SymbolMappingServiceFactory.cs | 3 --- 7 files changed, 2 insertions(+), 37 deletions(-) diff --git a/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs b/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs index 2f90755fcf976..85ecef8ad836c 100644 --- a/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs +++ b/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs @@ -37,7 +37,6 @@ public AbstractGoToCommandHandler( protected abstract string ScopeDescription { get; } protected abstract FunctionId FunctionId { get; } protected abstract Task FindActionAsync(TLanguageService service, Document document, int caretPosition, IFindUsagesContext context, CancellationToken cancellationToken); - protected abstract Task GetSolutionAsync(Document document, CancellationToken cancellationToken); public CommandState GetCommandState(TCommandArgs args) { @@ -126,9 +125,8 @@ private void ExecuteCommand( if (context.Message != null) return context.Message; - var solution = await GetSolutionAsync(document, cancellationToken).ConfigureAwait(false); await _streamingPresenter.TryNavigateToOrPresentItemsAsync( - _threadingContext, solution, context.SearchTitle, context.GetDefinitions(), cancellationToken).ConfigureAwait(false); + _threadingContext, document.Project.Solution, context.SearchTitle, context.GetDefinitions(), cancellationToken).ConfigureAwait(false); return null; } } diff --git a/src/EditorFeatures/Core/GoToBase/GoToBaseCommandHandler.cs b/src/EditorFeatures/Core/GoToBase/GoToBaseCommandHandler.cs index b0e77c1b69742..2e9b12769efd8 100644 --- a/src/EditorFeatures/Core/GoToBase/GoToBaseCommandHandler.cs +++ b/src/EditorFeatures/Core/GoToBase/GoToBaseCommandHandler.cs @@ -45,8 +45,5 @@ protected override IGoToBaseService GetService(Document document) protected override Task FindActionAsync(IGoToBaseService service, Document document, int caretPosition, IFindUsagesContext context, CancellationToken cancellationToken) => service.FindBasesAsync(document, caretPosition, context, cancellationToken); - - protected override Task GetSolutionAsync(Document document, CancellationToken cancellationToken) - => Task.FromResult(document.Project.Solution); } } diff --git a/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs b/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs index b9087bb895481..b736d47713f39 100644 --- a/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs +++ b/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs @@ -45,15 +45,5 @@ protected override Task FindActionAsync(IFindUsagesService service, Document doc protected override IFindUsagesService? GetService(Document? document) => document?.GetLanguageService(); - - protected override async Task GetSolutionAsync(Document document, CancellationToken cancellationToken) - { - // The original document we may be starting with might be in a metadata-as-source workspace. - // Ensure that we map back to the real primary workspace to present symbols in so we can - // navigate back to source implementations there. - var mappingService = document.Project.Solution.Workspace.Services.GetRequiredService(); - var mappedProject = await mappingService.MapDocumentAsync(document, cancellationToken).ConfigureAwait(false); - return mappedProject?.Solution ?? document.Project.Solution; - } } } diff --git a/src/Features/Core/Portable/MetadataAsSource/MetadataAsSourceFileService.cs b/src/Features/Core/Portable/MetadataAsSource/MetadataAsSourceFileService.cs index 31a6feb4a1c69..d235687f5d560 100644 --- a/src/Features/Core/Portable/MetadataAsSource/MetadataAsSourceFileService.cs +++ b/src/Features/Core/Portable/MetadataAsSource/MetadataAsSourceFileService.cs @@ -297,7 +297,7 @@ private void InitializeWorkspace(Project project) } } - internal async Task MapDocumentAsync(Document document, CancellationToken cancellationToken) + private async Task MapDocumentAsync(Document document, CancellationToken cancellationToken) { MetadataAsSourceGeneratedFileInfo? fileInfo; diff --git a/src/Features/Core/Portable/MetadataAsSource/SymbolMappingServiceFactory.cs b/src/Features/Core/Portable/MetadataAsSource/SymbolMappingServiceFactory.cs index 488e04a94c1ec..e4c5d32488f63 100644 --- a/src/Features/Core/Portable/MetadataAsSource/SymbolMappingServiceFactory.cs +++ b/src/Features/Core/Portable/MetadataAsSource/SymbolMappingServiceFactory.cs @@ -41,16 +41,6 @@ private sealed class SymbolMappingService : ISymbolMappingService { return await MapSymbolAsync(document, SymbolKey.Create(symbol, cancellationToken), cancellationToken).ConfigureAwait(false); } - - public Task MapDocumentAsync(Document document, CancellationToken cancellationToken) - { - if (document.Project.Solution.Workspace is not MetadataAsSourceWorkspace workspace) - { - throw new ArgumentException(FeaturesResources.Document_must_be_contained_in_the_workspace_that_created_this_service, nameof(document)); - } - - return workspace.FileService.MapDocumentAsync(document, cancellationToken); - } } } } diff --git a/src/Features/Core/Portable/SymbolMapping/ISymbolMappingService.cs b/src/Features/Core/Portable/SymbolMapping/ISymbolMappingService.cs index 50c5578ff50b2..13d443a5ed8aa 100644 --- a/src/Features/Core/Portable/SymbolMapping/ISymbolMappingService.cs +++ b/src/Features/Core/Portable/SymbolMapping/ISymbolMappingService.cs @@ -31,12 +31,5 @@ internal interface ISymbolMappingService : IWorkspaceService /// To cancel symbol resolution /// The matching symbol from the correct solution or null Task MapSymbolAsync(Document document, ISymbol symbol, CancellationToken cancellationToken = default); - - /// - /// Given an the document that a particular - /// came from, locate the project in the correct solution that contained the symbol - /// this document was created for. - /// - Task MapDocumentAsync(Document document, CancellationToken cancellationToken); } } diff --git a/src/Features/Core/Portable/SymbolMapping/SymbolMappingServiceFactory.cs b/src/Features/Core/Portable/SymbolMapping/SymbolMappingServiceFactory.cs index b4ba6d8ca1899..cd4e863db139e 100644 --- a/src/Features/Core/Portable/SymbolMapping/SymbolMappingServiceFactory.cs +++ b/src/Features/Core/Portable/SymbolMapping/SymbolMappingServiceFactory.cs @@ -35,8 +35,5 @@ public async Task MapSymbolAsync(Document document, SymbolK public Task MapSymbolAsync(Document document, ISymbol symbol, CancellationToken cancellationToken) => Task.FromResult(new SymbolMappingResult(document.Project, symbol)); - - public Task MapDocumentAsync(Document document, CancellationToken cancellationToken) - => Task.FromResult(document.Project); } } From 7f026a4d2deff898cf37d79c031249982e7d7f21 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 25 Aug 2021 11:55:13 -0700 Subject: [PATCH 37/42] Revert --- .../Contexts/WithoutReferencesFindUsagesContext.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs index a7b995683d608..af994b360b8a7 100644 --- a/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/Implementation/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs @@ -10,7 +10,6 @@ using Microsoft.CodeAnalysis.DocumentHighlighting; using Microsoft.CodeAnalysis.FindUsages; using Microsoft.CodeAnalysis.PooledObjects; -using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.VisualStudio.Shell.FindAllReferences; using Microsoft.VisualStudio.Shell.TableControl; @@ -99,7 +98,6 @@ protected override async ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem d RoslynDefinitionBucket definitionBucket, DefinitionItem definition, CancellationToken cancellationToken) { var documentSpan = definition.SourceSpans[0]; - var (guid, projectName, _) = GetGuidAndProjectInfo(documentSpan.Document); var sourceText = await documentSpan.Document.GetTextAsync(cancellationToken).ConfigureAwait(false); From 1c79f1a746802ef803bbf65d6f464dcb156de3a2 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 25 Aug 2021 11:57:07 -0700 Subject: [PATCH 38/42] REvert --- .../Core/CommandHandlers/AbstractGoToCommandHandler.cs | 2 +- .../Core/GoToDefinition/AbstractGoToDefinitionService.cs | 2 +- .../Core/GoToDefinition/GoToDefinitionHelpers.cs | 4 ++-- .../Core/Host/IStreamingFindReferencesPresenter.cs | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs b/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs index 85ecef8ad836c..4ad732394b8dc 100644 --- a/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs +++ b/src/EditorFeatures/Core/CommandHandlers/AbstractGoToCommandHandler.cs @@ -126,7 +126,7 @@ private void ExecuteCommand( return context.Message; await _streamingPresenter.TryNavigateToOrPresentItemsAsync( - _threadingContext, document.Project.Solution, context.SearchTitle, context.GetDefinitions(), cancellationToken).ConfigureAwait(false); + _threadingContext, document.Project.Solution.Workspace, context.SearchTitle, context.GetDefinitions(), cancellationToken).ConfigureAwait(false); return null; } } diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs index a21988b01f79d..5fdae0d10036a 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs @@ -131,7 +131,7 @@ private bool TryGoToAlternativeLocationIfAlreadyOnDefinition( } return await _streamingPresenter.TryNavigateToOrPresentItemsAsync( - _threadingContext, solution, title, definitions.ToImmutable(), cancellationToken).ConfigureAwait(true); + _threadingContext, solution.Workspace, title, definitions.ToImmutable(), cancellationToken).ConfigureAwait(true); }); } diff --git a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs index b42cd3e881aa7..a9e050da09de4 100644 --- a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs +++ b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs @@ -117,7 +117,7 @@ public static bool TryGoToDefinition( var definitions = await GetDefinitionsAsync(symbol, solution, thirdPartyNavigationAllowed, cancellationToken).ConfigureAwait(false); return await streamingPresenter.TryNavigateToOrPresentItemsAsync( - threadingContext, solution, title, definitions, cancellationToken).ConfigureAwait(false); + threadingContext, solution.Workspace, title, definitions, cancellationToken).ConfigureAwait(false); }); } @@ -131,7 +131,7 @@ public static bool TryGoToDefinition( { return threadingContext.JoinableTaskFactory.Run(() => streamingPresenter.TryNavigateToOrPresentItemsAsync( - threadingContext, solution, title, definitions, cancellationToken)); + threadingContext, solution.Workspace, title, definitions, cancellationToken)); } } } diff --git a/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs b/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs index 4e83525cd49dd..8edc3d7a2c4ac 100644 --- a/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs +++ b/src/EditorFeatures/Core/Host/IStreamingFindReferencesPresenter.cs @@ -61,7 +61,7 @@ internal static class IStreamingFindUsagesPresenterExtensions public static async Task TryNavigateToOrPresentItemsAsync( this IStreamingFindUsagesPresenter presenter, IThreadingContext threadingContext, - Solution solution, + Workspace workspace, string title, ImmutableArray items, CancellationToken cancellationToken) @@ -73,7 +73,7 @@ public static async Task TryNavigateToOrPresentItemsAsync( foreach (var item in items) { // Ignore any definitions that we can't navigate to. - if (await item.CanNavigateToAsync(solution.Workspace, cancellationToken).ConfigureAwait(false)) + if (await item.CanNavigateToAsync(workspace, cancellationToken).ConfigureAwait(false)) definitionsBuilder.Add(item); } @@ -87,7 +87,7 @@ public static async Task TryNavigateToOrPresentItemsAsync( // If we're directly going to a location we need to activate the preview so // that focus follows to the new cursor position. This behavior is expected // because we are only going to navigate once successfully - if (await item.TryNavigateToAsync(solution.Workspace, showInPreviewTab: true, activateTab: true, cancellationToken).ConfigureAwait(false)) + if (await item.TryNavigateToAsync(workspace, showInPreviewTab: true, activateTab: true, cancellationToken).ConfigureAwait(false)) return true; } @@ -104,7 +104,7 @@ public static async Task TryNavigateToOrPresentItemsAsync( // going to a location we need to activate the preview so that focus follows to the new cursor position. return await nonExternalItems[0].TryNavigateToAsync( - solution.Workspace, showInPreviewTab: true, activateTab: true, cancellationToken).ConfigureAwait(false); + workspace, showInPreviewTab: true, activateTab: true, cancellationToken).ConfigureAwait(false); } if (presenter != null) From 9f41c2a4d068a9c2944ec4d72d7a3d8ee599f994 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 25 Aug 2021 11:58:40 -0700 Subject: [PATCH 39/42] Simplify --- .../Core/GoToDefinition/AbstractGoToDefinitionService.cs | 4 ++-- .../InheritanceMargin/MarginGlyph/InheritanceMargin.xaml.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs index 5fdae0d10036a..aab0063b8d5c7 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs @@ -126,8 +126,8 @@ private bool TryGoToAlternativeLocationIfAlreadyOnDefinition( // already blocking the UI thread by being in a JTF.Run call. So we might as well try to // continue to use the blocking UI thread to do as much work as possible instead of making // it wait for threadpool threads to be available to process the work. - foreach (var def in await GoToDefinitionHelpers.GetDefinitionsAsync(impl, solution, thirdPartyNavigationAllowed: false, cancellationToken).ConfigureAwait(true)) - definitions.Add(def); + definitions.AddRange(await GoToDefinitionHelpers.GetDefinitionsAsync( + impl, solution, thirdPartyNavigationAllowed: false, cancellationToken).ConfigureAwait(true)); } return await _streamingPresenter.TryNavigateToOrPresentItemsAsync( diff --git a/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/MarginGlyph/InheritanceMargin.xaml.cs b/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/MarginGlyph/InheritanceMargin.xaml.cs index 6d9ef146de7c0..fd22a9b565e0d 100644 --- a/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/MarginGlyph/InheritanceMargin.xaml.cs +++ b/src/VisualStudio/Core/Def/Implementation/InheritanceMargin/MarginGlyph/InheritanceMargin.xaml.cs @@ -93,7 +93,7 @@ private async Task TargetMenuItem_OnClickAsync(TargetMenuItemViewModel viewModel await _streamingFindUsagesPresenter.TryNavigateToOrPresentItemsAsync( _threadingContext, - _workspace.CurrentSolution, + _workspace, string.Format(EditorFeaturesResources._0_declarations, viewModel.DisplayContent), ImmutableArray.Create(rehydrated), cancellationToken).ConfigureAwait(false); From c1c20dd95b9cb53ee15909075aae8348c28985b3 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 25 Aug 2021 11:59:25 -0700 Subject: [PATCH 40/42] Revert --- .../Core/GoToDefinition/AbstractGoToSymbolService.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs index d0fdb8795a250..cacd8843db3c7 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs @@ -37,10 +37,10 @@ public async Task GetSymbolsAsync(GoToSymbolContext context) var solution = document.Project.Solution; var definitions = await GoToDefinitionHelpers.GetDefinitionsAsync(symbol, solution, thirdPartyNavigationAllowed: true, cancellationToken).ConfigureAwait(false); - foreach (var def in definitions) + foreach (var definition in definitions) { - if (await def.CanNavigateToAsync(solution.Workspace, cancellationToken).ConfigureAwait(false)) - context.AddItem(WellKnownSymbolTypes.Definition, def); + if (await definition.CanNavigateToAsync(solution.Workspace, cancellationToken).ConfigureAwait(false)) + context.AddItem(WellKnownSymbolTypes.Definition, definition); } context.Span = span; From 2992f03023cc37f735145d4a25b47e5a716076f4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 25 Aug 2021 12:04:35 -0700 Subject: [PATCH 41/42] revert --- .../FindReferences/FindReferencesTests.vb | 47 +++++++------------ 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb b/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb index dcee9ca217c75..e88e0ee842ffd 100644 --- a/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb +++ b/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb @@ -67,9 +67,8 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences For Each cursorDocument In workspace.Documents.Where(Function(d) d.CursorPosition.HasValue) Dim cursorPosition = cursorDocument.CursorPosition.Value - Dim solution = workspace.CurrentSolution - Dim startDocument = If(solution.GetDocument(cursorDocument.Id), - Await solution.GetSourceGeneratedDocumentAsync(cursorDocument.Id, CancellationToken.None)) + Dim startDocument = If(workspace.CurrentSolution.GetDocument(cursorDocument.Id), + Await workspace.CurrentSolution.GetSourceGeneratedDocumentAsync(cursorDocument.Id, CancellationToken.None)) Assert.NotNull(startDocument) Dim findRefsService = startDocument.GetLanguageService(Of IFindUsagesService) @@ -82,8 +81,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(d) New FileNameAndSpans( d.Name, d.AnnotatedSpans(DefinitionKey).ToList())).ToList() - Dim actualDefinitions = Await GetFileNamesAndSpansAsync( - solution, + Dim actualDefinitions = GetFileNamesAndSpans( context.Definitions.Where(AddressOf context.ShouldShow). SelectMany(Function(d) d.SourceSpans)) @@ -95,8 +93,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(d) New FileNameAndSpans( d.Name, d.SelectedSpans.ToList())).ToList() - Dim actualReferences = Await GetFileNamesAndSpansAsync( - solution, + Dim actualReferences = GetFileNamesAndSpans( context.References.Select(Function(r) r.SourceSpan)) Assert.Equal(expectedReferences, actualReferences) @@ -109,8 +106,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(d) New FileNameAndSpans( d.Name, d.AnnotatedSpans(key).ToList())).ToList() Dim valueUsageInfoField = key.Substring(ValueUsageInfoKey.Length) - Dim actual = Await GetFileNamesAndSpansAsync( - solution, + Dim actual = GetFileNamesAndSpans( context.References.Where(Function(r) r.SymbolUsageInfo.ValueUsageInfoOpt?.ToString() = valueUsageInfoField).Select(Function(r) r.SourceSpan)) Assert.Equal(expected, actual) @@ -124,8 +120,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Select(Function(d) New FileNameAndSpans( d.Name, d.AnnotatedSpans(key).ToList())).ToList() Dim typeOrNamespaceUsageInfoFieldNames = key.Substring(TypeOrNamespaceUsageInfoKey.Length).Split(","c).Select(Function(s) s.Trim) - Dim actual = Await GetFileNamesAndSpansAsync( - solution, + Dim actual = GetFileNamesAndSpans( context.References.Where(Function(r) Return r.SymbolUsageInfo.TypeOrNamespaceUsageInfoOpt IsNot Nothing AndAlso r.SymbolUsageInfo.TypeOrNamespaceUsageInfoOpt.ToString().Split(","c).Select(Function(s) s.Trim).SetEquals(typeOrNamespaceUsageInfoFieldNames) @@ -144,8 +139,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences OrderBy(Function(d) d.Name). Select(Function(d) New FileNameAndSpans( d.Name, d.AnnotatedSpans(annotationKey).ToList())).ToList() - Dim actual = Await GetFileNamesAndSpansAsync( - solution, + Dim actual = GetFileNamesAndSpans( context.References.Where(Function(r) Dim actualValue As String = Nothing If r.AdditionalProperties.TryGetValue(propertyName, actualValue) Then @@ -182,27 +176,18 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences Return additionalPropertiesMap End Function - Private Shared Function GetFileNamesAndSpansAsync(solution As Solution, items As IEnumerable(Of DocumentSpan)) As Task(Of List(Of FileNameAndSpans)) - Dim dict = New Dictionary(Of Document, List(Of DocumentSpan)) - - For Each item In items - Dim list As List(Of DocumentSpan) = Nothing - If Not dict.TryGetValue(item.Document, list) Then - list = New List(Of DocumentSpan)() - dict.Add(item.Document, list) - End If - - list.Add(item) - Next - - Return Task.FromResult(dict.OrderBy(Function(g) g.Key.Name). - Select(Function(g) GetFileNameAndSpans(g.Key, g.Value)).ToList()) + Private Shared Function GetFileNamesAndSpans(items As IEnumerable(Of DocumentSpan)) As List(Of FileNameAndSpans) + Return items.Where(Function(i) i.Document IsNot Nothing). + GroupBy(Function(i) i.Document). + OrderBy(Function(g) g.Key.Name). + Select(Function(g) GetFileNameAndSpans(g)).ToList() End Function - Private Shared Function GetFileNameAndSpans(document As Document, items As List(Of DocumentSpan)) As FileNameAndSpans + Private Shared Function GetFileNameAndSpans(g As IGrouping(Of Document, DocumentSpan)) As FileNameAndSpans Return New FileNameAndSpans( - document.Name, - items.Select(Function(i) i.SourceSpan).OrderBy(Function(s) s.Start).Distinct().ToList()) + g.Key.Name, + g.Select(Function(i) i.SourceSpan).OrderBy(Function(s) s.Start). + Distinct().ToList()) End Function Private Structure FileNameAndSpans From fcd5b7f9d9374d2bc6b95a405e60fbde5c975057 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 25 Aug 2021 12:13:34 -0700 Subject: [PATCH 42/42] Ververt --- .../CSharpGoToDefinitionTests.vb | 792 +++++++++--------- .../GoToDefinition/GoToDefinitionTestsBase.vb | 17 +- .../VisualBasicGoToDefinitionTests.vb | 415 ++++----- 3 files changed, 612 insertions(+), 612 deletions(-) diff --git a/src/EditorFeatures/Test2/GoToDefinition/CSharpGoToDefinitionTests.vb b/src/EditorFeatures/Test2/GoToDefinition/CSharpGoToDefinitionTests.vb index d84cf8c4e3c97..88d4a4bc661e5 100644 --- a/src/EditorFeatures/Test2/GoToDefinition/CSharpGoToDefinitionTests.vb +++ b/src/EditorFeatures/Test2/GoToDefinition/CSharpGoToDefinitionTests.vb @@ -9,7 +9,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition #Region "P2P Tests" - Public Async Function TestP2PClassReference() As Task + Public Sub TestP2PClassReference() Dim workspace = @@ -33,15 +33,15 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition - Await Test(workspace) - End Function + Test(workspace) + End Sub #End Region #Region "Normal CSharp Tests" - Public Async Function TestCSharpGoToDefinition() As Task + Public Sub TestCSharpGoToDefinition() Dim workspace = @@ -52,12 +52,12 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpLiteralGoToDefinition() As Task + Public Sub TestCSharpLiteralGoToDefinition() Dim workspace = @@ -67,12 +67,12 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpStringLiteralGoToDefinition() As Task + Public Sub TestCSharpStringLiteralGoToDefinition() Dim workspace = @@ -82,12 +82,12 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToDefinitionOnAnonymousMember() As Task + Public Sub TestCSharpGoToDefinitionOnAnonymousMember() Dim workspace = @@ -111,11 +111,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToDefinitionSameClass() As Task + Public Sub TestCSharpGoToDefinitionSameClass() Dim workspace = @@ -125,11 +125,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToDefinitionNestedClass() As Task + Public Sub TestCSharpGoToDefinitionNestedClass() Dim workspace = @@ -146,11 +146,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionDifferentFiles() As Task + Public Sub TestCSharpGotoDefinitionDifferentFiles() Dim workspace = @@ -166,11 +166,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionPartialClasses() As Task + Public Sub TestCSharpGotoDefinitionPartialClasses() Dim workspace = @@ -189,11 +189,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionMethod() As Task + Public Sub TestCSharpGotoDefinitionMethod() Dim workspace = @@ -212,12 +212,12 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionPartialMethod() As Task + Public Sub TestCSharpGotoDefinitionPartialMethod() Dim workspace = @@ -245,11 +245,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionExtendedPartialMethod() As Task + Public Sub TestCSharpGotoDefinitionExtendedPartialMethod() Dim workspace = @@ -277,11 +277,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionOnMethodCall1() As Task + Public Sub TestCSharpGotoDefinitionOnMethodCall1() Dim workspace = @@ -302,11 +302,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionOnMethodCall2() As Task + Public Sub TestCSharpGotoDefinitionOnMethodCall2() Dim workspace = @@ -327,11 +327,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionOnMethodCall3() As Task + Public Sub TestCSharpGotoDefinitionOnMethodCall3() Dim workspace = @@ -352,11 +352,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionOnMethodCall4() As Task + Public Sub TestCSharpGotoDefinitionOnMethodCall4() Dim workspace = @@ -377,11 +377,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionOnConstructor1() As Task + Public Sub TestCSharpGotoDefinitionOnConstructor1() Dim workspace = @@ -397,12 +397,12 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionOnConstructor2() As Task + Public Sub TestCSharpGotoDefinitionOnConstructor2() Dim workspace = @@ -418,11 +418,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionWithoutExplicitConstruct() As Task + Public Sub TestCSharpGotoDefinitionWithoutExplicitConstruct() Dim workspace = @@ -438,11 +438,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionOnLocalVariable1() As Task + Public Sub TestCSharpGotoDefinitionOnLocalVariable1() Dim workspace = @@ -459,11 +459,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionOnLocalVariable2() As Task + Public Sub TestCSharpGotoDefinitionOnLocalVariable2() Dim workspace = @@ -480,11 +480,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionOnLocalField() As Task + Public Sub TestCSharpGotoDefinitionOnLocalField() Dim workspace = @@ -501,11 +501,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionOnAttributeClass() As Task + Public Sub TestCSharpGotoDefinitionOnAttributeClass() Dim workspace = @@ -519,11 +519,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionTouchLeft() As Task + Public Sub TestCSharpGotoDefinitionTouchLeft() Dim workspace = @@ -536,11 +536,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionTouchRight() As Task + Public Sub TestCSharpGotoDefinitionTouchRight() Dim workspace = @@ -553,11 +553,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionOnGenericTypeParameterInPresenceOfInheritedNestedTypeWithSameName() As Task + Public Sub TestCSharpGotoDefinitionOnGenericTypeParameterInPresenceOfInheritedNestedTypeWithSameName() Dim workspace = @@ -574,12 +574,12 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionThroughOddlyNamedType() As Task + Public Sub TestCSharpGotoDefinitionThroughOddlyNamedType() Dim workspace = @@ -590,11 +590,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToDefinitionOnConstructorInitializer1() As Task + Public Sub TestCSharpGoToDefinitionOnConstructorInitializer1() Dim workspace = @@ -619,11 +619,11 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToDefinitionOnExtensionMethod() As Task + Public Sub TestCSharpGoToDefinitionOnExtensionMethod() Dim workspace = @@ -645,12 +645,12 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpTestLambdaParameter() As Task + Public Sub TestCSharpTestLambdaParameter() Dim workspace = @@ -667,11 +667,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpTestLabel() As Task + Public Sub TestCSharpTestLabel() Dim workspace = @@ -689,11 +689,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToDefinitionFromCref() As Task + Public Sub TestCSharpGoToDefinitionFromCref() Dim workspace = @@ -706,12 +706,12 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOverriddenDefinition_FromDeconstructionDeclaration() As Task + Public Sub TestCSharpGoToOverriddenDefinition_FromDeconstructionDeclaration() Dim workspace = @@ -729,12 +729,12 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOverriddenDefinition_FromDeconstructionAssignment() As Task + Public Sub TestCSharpGoToOverriddenDefinition_FromDeconstructionAssignment() Dim workspace = @@ -753,12 +753,12 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOverriddenDefinition_FromDeconstructionForeach() As Task + Public Sub TestCSharpGoToOverriddenDefinition_FromDeconstructionForeach() Dim workspace = @@ -776,11 +776,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOverriddenDefinition_FromOverride() As Task + Public Sub TestCSharpGoToOverriddenDefinition_FromOverride() Dim workspace = @@ -793,11 +793,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOverriddenDefinition_FromOverride2() As Task + Public Sub TestCSharpGoToOverriddenDefinition_FromOverride2() Dim workspace = @@ -808,11 +808,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOverriddenProperty_FromOverride() As Task + Public Sub TestCSharpGoToOverriddenProperty_FromOverride() Dim workspace = @@ -823,11 +823,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToUnmanaged_Keyword() As Task + Public Sub TestCSharpGoToUnmanaged_Keyword() Dim workspace = @@ -839,11 +839,11 @@ class C - Await Test(workspace, expectedResult:=False) - End Function + Test(workspace, expectedResult:=False) + End Sub - Public Async Function TestCSharpGoToUnmanaged_Type() As Task + Public Sub TestCSharpGoToUnmanaged_Type() Dim workspace = @@ -858,12 +858,12 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToImplementedInterfaceMemberFromImpl1() As Task + Public Sub TestCSharpGoToImplementedInterfaceMemberFromImpl1() Dim workspace = @@ -881,12 +881,12 @@ class Foo : IFoo1 - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToImplementedInterfaceMemberFromImpl2() As Task + Public Sub TestCSharpGoToImplementedInterfaceMemberFromImpl2() Dim workspace = @@ -904,12 +904,12 @@ class Foo : IFoo1 - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToImplementedInterfaceMemberFromImpl3() As Task + Public Sub TestCSharpGoToImplementedInterfaceMemberFromImpl3() Dim workspace = @@ -928,12 +928,12 @@ class Foo : IFoo1, IFoo2 - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToDefinitionInVarPatterns() As Task + Public Sub TestCSharpGoToDefinitionInVarPatterns() Dim workspace = @@ -955,8 +955,8 @@ class D - Await Test(workspace) - End Function + Test(workspace) + End Sub #End Region #Region "CSharp TupleTests" @@ -985,7 +985,7 @@ namespace System ]]> - Public Async Function TestCSharpGotoDefinitionTupleFieldEqualTuples01() As Task + Public Sub TestCSharpGotoDefinitionTupleFieldEqualTuples01() Dim workspace = @@ -1008,11 +1008,11 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionTupleFieldEqualTuples02() As Task + Public Sub TestCSharpGotoDefinitionTupleFieldEqualTuples02() Dim workspace = @@ -1034,11 +1034,11 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionTupleFieldMatchToOuter01() As Task + Public Sub TestCSharpGotoDefinitionTupleFieldMatchToOuter01() Dim workspace = @@ -1058,11 +1058,11 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionTupleFieldMatchToOuter02() As Task + Public Sub TestCSharpGotoDefinitionTupleFieldMatchToOuter02() Dim workspace = @@ -1082,11 +1082,11 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionTupleFieldMatchToOuter03() As Task + Public Sub TestCSharpGotoDefinitionTupleFieldMatchToOuter03() Dim workspace = @@ -1106,11 +1106,11 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionTupleFieldRedeclared01() As Task + Public Sub TestCSharpGotoDefinitionTupleFieldRedeclared01() Dim workspace = @@ -1130,11 +1130,11 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionTupleFieldRedeclared02() As Task + Public Sub TestCSharpGotoDefinitionTupleFieldRedeclared02() Dim workspace = @@ -1154,11 +1154,11 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionTupleFieldItem01() As Task + Public Sub TestCSharpGotoDefinitionTupleFieldItem01() Dim workspace = @@ -1178,11 +1178,11 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionTupleFieldItem02() As Task + Public Sub TestCSharpGotoDefinitionTupleFieldItem02() Dim workspace = @@ -1202,11 +1202,11 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGotoDefinitionTupleFieldItem03() As Task + Public Sub TestCSharpGotoDefinitionTupleFieldItem03() Dim workspace = @@ -1226,14 +1226,14 @@ namespace System - Await Test(workspace, expectedResult:=False) - End Function + Test(workspace, expectedResult:=False) + End Sub #End Region #Region "CSharp Venus Tests" - Public Async Function TestCSharpVenusGotoDefinition() As Task + Public Sub TestCSharpVenusGotoDefinition() Dim workspace = @@ -1249,12 +1249,12 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpFilterGotoDefResultsFromHiddenCodeForUIPresenters() As Task + Public Sub TestCSharpFilterGotoDefResultsFromHiddenCodeForUIPresenters() Dim workspace = @@ -1270,12 +1270,12 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpDoNotFilterGotoDefResultsFromHiddenCodeForApis() As Task + Public Sub TestCSharpDoNotFilterGotoDefResultsFromHiddenCodeForApis() Dim workspace = @@ -1291,15 +1291,15 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub #End Region #Region "CSharp Script Tests" - Public Async Function TestCSharpScriptGoToDefinition() As Task + Public Sub TestCSharpScriptGoToDefinition() Dim workspace = @@ -1311,11 +1311,11 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpScriptGoToDefinitionSameClass() As Task + Public Sub TestCSharpScriptGoToDefinitionSameClass() Dim workspace = @@ -1326,11 +1326,11 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpScriptGoToDefinitionNestedClass() As Task + Public Sub TestCSharpScriptGoToDefinitionNestedClass() Dim workspace = @@ -1348,11 +1348,11 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpScriptGotoDefinitionDifferentFiles() As Task + Public Sub TestCSharpScriptGotoDefinitionDifferentFiles() Dim workspace = @@ -1371,11 +1371,11 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpScriptGotoDefinitionPartialClasses() As Task + Public Sub TestCSharpScriptGotoDefinitionPartialClasses() Dim workspace = @@ -1398,11 +1398,11 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpScriptGotoDefinitionMethod() As Task + Public Sub TestCSharpScriptGotoDefinitionMethod() Dim workspace = @@ -1423,11 +1423,11 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpScriptGotoDefinitionOnMethodCall1() As Task + Public Sub TestCSharpScriptGotoDefinitionOnMethodCall1() Dim workspace = @@ -1449,11 +1449,11 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpScriptGotoDefinitionOnMethodCall2() As Task + Public Sub TestCSharpScriptGotoDefinitionOnMethodCall2() Dim workspace = @@ -1475,10 +1475,10 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpScriptGotoDefinitionOnMethodCall3() As Task + Public Sub TestCSharpScriptGotoDefinitionOnMethodCall3() Dim workspace = @@ -1500,11 +1500,11 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpScriptGotoDefinitionOnMethodCall4() As Task + Public Sub TestCSharpScriptGotoDefinitionOnMethodCall4() Dim workspace = @@ -1526,12 +1526,12 @@ namespace System - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpDoNotFilterGeneratedSourceLocations() As Task + Public Sub TestCSharpDoNotFilterGeneratedSourceLocations() Dim workspace = @@ -1551,12 +1551,12 @@ partial class [|C|] - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpUseGeneratedSourceLocationsIfNoNongeneratedLocationsAvailable() As Task + Public Sub TestCSharpUseGeneratedSourceLocationsIfNoNongeneratedLocationsAvailable() Dim workspace = @@ -1576,14 +1576,14 @@ class D - Await Test(workspace) - End Function + Test(workspace) + End Sub #End Region - Public Async Function TestCSharpTestAliasAndTarget1() As Task + Public Sub TestCSharpTestAliasAndTarget1() Dim workspace = @@ -1607,12 +1607,12 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpTestAliasAndTarget2() As Task + Public Sub TestCSharpTestAliasAndTarget2() Dim workspace = @@ -1636,12 +1636,12 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpTestAliasAndTarget3() As Task + Public Sub TestCSharpTestAliasAndTarget3() Dim workspace = @@ -1665,12 +1665,12 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpTestAliasAndTarget4() As Task + Public Sub TestCSharpTestAliasAndTarget4() Dim workspace = @@ -1694,13 +1694,13 @@ class Program - Await Test(workspace) - End Function + Test(workspace) + End Sub #Region "Show notification tests" - Public Async Function TestShowNotificationCS() As Task + Public Sub TestShowNotificationCS() Dim workspace = @@ -1714,12 +1714,12 @@ class Program - Await Test(workspace, expectedResult:=False) - End Function + Test(workspace, expectedResult:=False) + End Sub - Public Async Function TestGoToDefinitionOnGlobalKeyword() As Task + Public Sub TestGoToDefinitionOnGlobalKeyword() Dim workspace = @@ -1732,8 +1732,8 @@ class Program - Await Test(workspace, expectedResult:=False) - End Function + Test(workspace, expectedResult:=False) + End Sub #End Region #Region "CSharp Query expressions Tests" @@ -1798,7 +1798,7 @@ namespace QueryPattern - Public Async Function TestQuerySelect() As Task + Public Sub TestQuerySelect() Dim workspace = @@ -1824,12 +1824,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryWhere() As Task + Public Sub TestQueryWhere() Dim workspace = @@ -1856,12 +1856,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQuerySelectMany1() As Task + Public Sub TestQuerySelectMany1() Dim workspace = @@ -1888,12 +1888,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQuerySelectMany2() As Task + Public Sub TestQuerySelectMany2() Dim workspace = @@ -1920,12 +1920,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryJoin1() As Task + Public Sub TestQueryJoin1() Dim workspace = @@ -1952,12 +1952,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryJoin2() As Task + Public Sub TestQueryJoin2() Dim workspace = @@ -1984,12 +1984,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryJoin3() As Task + Public Sub TestQueryJoin3() Dim workspace = @@ -2016,12 +2016,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryJoin4() As Task + Public Sub TestQueryJoin4() Dim workspace = @@ -2048,12 +2048,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryGroupJoin1() As Task + Public Sub TestQueryGroupJoin1() Dim workspace = @@ -2080,12 +2080,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryGroupJoin2() As Task + Public Sub TestQueryGroupJoin2() Dim workspace = @@ -2112,12 +2112,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryGroupJoin3() As Task + Public Sub TestQueryGroupJoin3() Dim workspace = @@ -2144,12 +2144,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryGroupJoin4() As Task + Public Sub TestQueryGroupJoin4() Dim workspace = @@ -2176,12 +2176,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryGroupBy1() As Task + Public Sub TestQueryGroupBy1() Dim workspace = @@ -2207,12 +2207,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryGroupBy2() As Task + Public Sub TestQueryGroupBy2() Dim workspace = @@ -2238,12 +2238,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryFromCast1() As Task + Public Sub TestQueryFromCast1() Dim workspace = @@ -2269,12 +2269,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryFromCast2() As Task + Public Sub TestQueryFromCast2() Dim workspace = @@ -2300,12 +2300,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryJoinCast1() As Task + Public Sub TestQueryJoinCast1() Dim workspace = @@ -2332,12 +2332,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryJoinCast2() As Task + Public Sub TestQueryJoinCast2() Dim workspace = @@ -2364,12 +2364,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQuerySelectManyCast1() As Task + Public Sub TestQuerySelectManyCast1() Dim workspace = @@ -2396,12 +2396,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQuerySelectManyCast2() As Task + Public Sub TestQuerySelectManyCast2() Dim workspace = @@ -2428,12 +2428,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryOrderBySingleParameter() As Task + Public Sub TestQueryOrderBySingleParameter() Dim workspace = @@ -2460,12 +2460,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryOrderBySingleParameterWithOrderClause() As Task + Public Sub TestQueryOrderBySingleParameterWithOrderClause() Dim workspace = @@ -2492,12 +2492,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryOrderByTwoParameterWithoutOrderClause() As Task + Public Sub TestQueryOrderByTwoParameterWithoutOrderClause() Dim workspace = @@ -2524,12 +2524,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryOrderByTwoParameterWithOrderClause() As Task + Public Sub TestQueryOrderByTwoParameterWithOrderClause() Dim workspace = @@ -2556,12 +2556,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestQueryDegeneratedSelect() As Task + Public Sub TestQueryDegeneratedSelect() Dim workspace = @@ -2588,12 +2588,12 @@ class Test - Await Test(workspace, False) - End Function + Test(workspace, False) + End Sub - Public Async Function TestQueryLet() As Task + Public Sub TestQueryLet() Dim workspace = @@ -2620,12 +2620,12 @@ class Test - Await Test(workspace) - End Function + Test(workspace) + End Sub #End Region - Public Async Function TestCSharpGoToOnBreakInSwitchStatement() As Task + Public Sub TestCSharpGoToOnBreakInSwitchStatement() Dim workspace = @@ -2647,11 +2647,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnContinueInSwitchStatement() As Task + Public Sub TestCSharpGoToOnContinueInSwitchStatement() Dim workspace = @@ -2673,11 +2673,11 @@ class C - Await Test(workspace, expectedResult:=False) - End Function + Test(workspace, expectedResult:=False) + End Sub - Public Async Function TestCSharpGoToOnBreakInDoStatement() As Task + Public Sub TestCSharpGoToOnBreakInDoStatement() Dim workspace = @@ -2697,11 +2697,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnContinueInDoStatement() As Task + Public Sub TestCSharpGoToOnContinueInDoStatement() Dim workspace = @@ -2721,11 +2721,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnBreakInForStatement() As Task + Public Sub TestCSharpGoToOnBreakInForStatement() Dim workspace = @@ -2744,11 +2744,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnContinueInForStatement() As Task + Public Sub TestCSharpGoToOnContinueInForStatement() Dim workspace = @@ -2767,11 +2767,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnBreakInForeachStatement() As Task + Public Sub TestCSharpGoToOnBreakInForeachStatement() Dim workspace = @@ -2790,11 +2790,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnContinueInForeachStatement() As Task + Public Sub TestCSharpGoToOnContinueInForeachStatement() Dim workspace = @@ -2813,11 +2813,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnBreakInForeachVariableStatement() As Task + Public Sub TestCSharpGoToOnBreakInForeachVariableStatement() Dim workspace = @@ -2836,11 +2836,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnContinueInForeachVariableStatement() As Task + Public Sub TestCSharpGoToOnContinueInForeachVariableStatement() Dim workspace = @@ -2859,11 +2859,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnContinueInSwitchInForeach() As Task + Public Sub TestCSharpGoToOnContinueInSwitchInForeach() Dim workspace = @@ -2886,11 +2886,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnTopLevelContinue() As Task + Public Sub TestCSharpGoToOnTopLevelContinue() Dim workspace = @@ -2900,11 +2900,11 @@ cont$$inue; - Await Test(workspace, expectedResult:=False) - End Function + Test(workspace, expectedResult:=False) + End Sub - Public Async Function TestCSharpGoToOnBreakInParenthesizedLambda() As Task + Public Sub TestCSharpGoToOnBreakInParenthesizedLambda() Dim workspace = @@ -2927,11 +2927,11 @@ class C - Await Test(workspace, expectedResult:=False) - End Function + Test(workspace, expectedResult:=False) + End Sub - Public Async Function TestCSharpGoToOnBreakInSimpleLambda() As Task + Public Sub TestCSharpGoToOnBreakInSimpleLambda() Dim workspace = @@ -2954,11 +2954,11 @@ class C - Await Test(workspace, expectedResult:=False) - End Function + Test(workspace, expectedResult:=False) + End Sub - Public Async Function TestCSharpGoToOnBreakInLocalFunction() As Task + Public Sub TestCSharpGoToOnBreakInLocalFunction() Dim workspace = @@ -2984,11 +2984,11 @@ class C - Await Test(workspace, expectedResult:=False) - End Function + Test(workspace, expectedResult:=False) + End Sub - Public Async Function TestCSharpGoToOnBreakInMethod() As Task + Public Sub TestCSharpGoToOnBreakInMethod() Dim workspace = @@ -3004,11 +3004,11 @@ class C - Await Test(workspace, expectedResult:=False) - End Function + Test(workspace, expectedResult:=False) + End Sub - Public Async Function TestCSharpGoToOnBreakInAccessor() As Task + Public Sub TestCSharpGoToOnBreakInAccessor() Dim workspace = @@ -3024,11 +3024,11 @@ class C - Await Test(workspace, expectedResult:=False) - End Function + Test(workspace, expectedResult:=False) + End Sub - Public Async Function TestCSharpGoToOnReturnInVoidMethod() As Task + Public Sub TestCSharpGoToOnReturnInVoidMethod() Dim workspace = @@ -3047,11 +3047,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnReturnInIntMethod() As Task + Public Sub TestCSharpGoToOnReturnInIntMethod() Dim workspace = @@ -3071,11 +3071,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnReturnInVoidLambda() As Task + Public Sub TestCSharpGoToOnReturnInVoidLambda() Dim workspace = @@ -3097,11 +3097,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnReturnedExpression() As Task + Public Sub TestCSharpGoToOnReturnedExpression() Dim workspace = @@ -3120,11 +3120,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnReturnedConstantExpression() As Task + Public Sub TestCSharpGoToOnReturnedConstantExpression() Dim workspace = @@ -3143,11 +3143,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnYieldReturn_Return() As Task + Public Sub TestCSharpGoToOnYieldReturn_Return() Dim workspace = @@ -3163,11 +3163,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnYieldReturn_Yield() As Task + Public Sub TestCSharpGoToOnYieldReturn_Yield() Dim workspace = @@ -3183,11 +3183,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnYieldReturn_Yield_Partial() As Task + Public Sub TestCSharpGoToOnYieldReturn_Yield_Partial() Dim workspace = @@ -3205,11 +3205,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnYieldReturn_Yield_Partial_ReverseOrder() As Task + Public Sub TestCSharpGoToOnYieldReturn_Yield_Partial_ReverseOrder() Dim workspace = @@ -3227,11 +3227,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnYieldBreak_Yield() As Task + Public Sub TestCSharpGoToOnYieldBreak_Yield() Dim workspace = @@ -3247,11 +3247,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCSharpGoToOnYieldBreak_Break() As Task + Public Sub TestCSharpGoToOnYieldBreak_Break() Dim workspace = @@ -3267,11 +3267,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function ExtendedPropertyPattern_FirstPart() As Task + Public Sub ExtendedPropertyPattern_FirstPart() Dim workspace = @@ -3290,11 +3290,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function ExtendedPropertyPattern_SecondPart() As Task + Public Sub ExtendedPropertyPattern_SecondPart() Dim workspace = @@ -3313,11 +3313,11 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TopLevelStatements_EmptySpace() As Task + Public Sub TopLevelStatements_EmptySpace() Dim workspace = @@ -3331,7 +3331,7 @@ $$ - Await Test(workspace, expectedResult:=False) - End Function + Test(workspace, expectedResult:=False) + End Sub End Class End Namespace diff --git a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb index 5bf9d604595f1..d97d0b6a347f5 100644 --- a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb +++ b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTestsBase.vb @@ -14,10 +14,10 @@ Imports Microsoft.VisualStudio.Text Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition Public Class GoToDefinitionTestsBase - Private Shared Function Test( + Private Shared Sub Test( workspaceDefinition As XElement, expectedResult As Boolean, - executeOnDocument As Func(Of Document, Integer, IThreadingContext, IStreamingFindUsagesPresenter, Boolean)) As Task + executeOnDocument As Func(Of Document, Integer, IThreadingContext, IStreamingFindUsagesPresenter, Boolean)) Using workspace = TestWorkspace.Create(workspaceDefinition, composition:=GoToTestHelpers.Composition) Dim solution = workspace.CurrentSolution Dim cursorDocument = workspace.Documents.First(Function(d) d.CursorPosition.HasValue) @@ -90,8 +90,8 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition Dim items = context.GetDefinitions() For Each location In items - For Each ss In location.SourceSpans - actualLocations.Add(New FilePathAndSpan(ss.Document.FilePath, ss.SourceSpan)) + For Each docSpan In location.SourceSpans + actualLocations.Add(New FilePathAndSpan(docSpan.Document.FilePath, docSpan.SourceSpan)) Next Next @@ -108,12 +108,11 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition Assert.False(presenterCalled) End If - Return Task.CompletedTask End Using - End Function + End Sub - Friend Shared Async Function Test(workspaceDefinition As XElement, Optional expectedResult As Boolean = True) As Task - Await Test(workspaceDefinition, expectedResult, + Friend Shared Sub Test(workspaceDefinition As XElement, Optional expectedResult As Boolean = True) + Test(workspaceDefinition, expectedResult, Function(document, cursorPosition, threadingContext, presenter) Dim goToDefService = If(document.Project.Language = LanguageNames.CSharp, DirectCast(New CSharpGoToDefinitionService(threadingContext, presenter), IGoToDefinitionService), @@ -121,7 +120,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition Return goToDefService.TryGoToDefinition(document, cursorPosition, CancellationToken.None) End Function) - End Function + End Sub End Class End Namespace diff --git a/src/EditorFeatures/Test2/GoToDefinition/VisualBasicGoToDefinitionTests.vb b/src/EditorFeatures/Test2/GoToDefinition/VisualBasicGoToDefinitionTests.vb index 2a5818ee3ccf8..aab33b5a34ef7 100644 --- a/src/EditorFeatures/Test2/GoToDefinition/VisualBasicGoToDefinitionTests.vb +++ b/src/EditorFeatures/Test2/GoToDefinition/VisualBasicGoToDefinitionTests.vb @@ -10,7 +10,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition - Public Async Function TestVisualBasicGoToDefinitionOnAnonymousMember() As Task + Public Sub TestVisualBasicGoToDefinitionOnAnonymousMember() Dim workspace = @@ -29,11 +29,11 @@ end class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToDefinition() As Task + Public Sub TestVisualBasicGoToDefinition() Dim workspace = @@ -47,12 +47,12 @@ end class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicLiteralGoToDefinition() As Task + Public Sub TestVisualBasicLiteralGoToDefinition() Dim workspace = @@ -62,12 +62,12 @@ end class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicStringLiteralGoToDefinition() As Task + Public Sub TestVisualBasicStringLiteralGoToDefinition() Dim workspace = @@ -77,12 +77,12 @@ end class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicPropertyBackingField() As Task + Public Sub TestVisualBasicPropertyBackingField() Dim workspace = @@ -97,11 +97,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToDefinitionSameClass() As Task + Public Sub TestVisualBasicGoToDefinitionSameClass() Dim workspace = @@ -113,11 +113,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToDefinitionNestedClass() As Task + Public Sub TestVisualBasicGoToDefinitionNestedClass() Dim workspace = @@ -131,11 +131,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGotoDefinitionDifferentFiles() As Task + Public Sub TestVisualBasicGotoDefinitionDifferentFiles() Dim workspace = @@ -156,11 +156,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGotoDefinitionPartialClasses() As Task + Public Sub TestVisualBasicGotoDefinitionPartialClasses() Dim workspace = @@ -186,11 +186,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGotoDefinitionMethod() As Task + Public Sub TestVisualBasicGotoDefinitionMethod() Dim workspace = @@ -209,12 +209,12 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGotoDefinitionPartialMethod() As Task + Public Sub TestVisualBasicGotoDefinitionPartialMethod() Dim workspace = @@ -239,11 +239,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicTouchLeft() As Task + Public Sub TestVisualBasicTouchLeft() Dim workspace = @@ -262,11 +262,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicTouchRight() As Task + Public Sub TestVisualBasicTouchRight() Dim workspace = @@ -285,12 +285,12 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicMe() As Task + Public Sub TestVisualBasicMe() Dim workspace = @@ -319,12 +319,12 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicMyClass() As Task + Public Sub TestVisualBasicMyClass() Dim workspace = @@ -353,12 +353,12 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicMyBase() As Task + Public Sub TestVisualBasicMyBase() Dim workspace = @@ -387,11 +387,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOverridenSubDefinition() As Task + Public Sub TestVisualBasicGoToOverridenSubDefinition() Dim workspace = @@ -410,11 +410,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOverridenFunctionDefinition() As Task + Public Sub TestVisualBasicGoToOverridenFunctionDefinition() Dim workspace = @@ -435,11 +435,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOverridenPropertyDefinition() As Task + Public Sub TestVisualBasicGoToOverridenPropertyDefinition() Dim workspace = @@ -456,14 +456,14 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub #End Region #Region "Venus Visual Basic Tests" - Public Async Function TestVisualBasicVenusGotoDefinition() As Task + Public Sub TestVisualBasicVenusGotoDefinition() Dim workspace = @@ -479,12 +479,12 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicFilterGotoDefResultsFromHiddenCodeForUIPresenters() As Task + Public Sub TestVisualBasicFilterGotoDefResultsFromHiddenCodeForUIPresenters() Dim workspace = @@ -500,12 +500,12 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicDoNotFilterGotoDefResultsFromHiddenCodeForApis() As Task + Public Sub TestVisualBasicDoNotFilterGotoDefResultsFromHiddenCodeForApis() Dim workspace = @@ -521,12 +521,12 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub #End Region - Public Async Function TestVisualBasicTestThroughExecuteCommand() As Task + Public Sub TestVisualBasicTestThroughExecuteCommand() Dim workspace = @@ -545,11 +545,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToDefinitionOnExtensionMethod() As Task + Public Sub TestVisualBasicGoToDefinitionOnExtensionMethod() Dim workspace = @@ -574,12 +574,12 @@ End Module]]>] - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicQueryRangeVariable() As Task + Public Sub TestVisualBasicQueryRangeVariable() Dim workspace = @@ -598,12 +598,12 @@ End Module - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGotoConstant() As Task + Public Sub TestVisualBasicGotoConstant() Dim workspace = @@ -618,13 +618,13 @@ End Module - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCrossLanguageParameterizedPropertyOverride() As Task + Public Sub TestCrossLanguageParameterizedPropertyOverride() Dim workspace = @@ -651,12 +651,12 @@ class B : A - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestCrossLanguageNavigationToVBModuleMember() As Task + Public Sub TestCrossLanguageNavigationToVBModuleMember() Dim workspace = @@ -681,13 +681,13 @@ class C - Await Test(workspace) - End Function + Test(workspace) + End Sub #Region "Show notification tests" - Public Async Function TestShowNotificationVB() As Task + Public Sub TestShowNotificationVB() Dim workspace = @@ -701,12 +701,12 @@ class C - Await Test(workspace, expectedResult:=False) - End Function + Test(workspace, expectedResult:=False) + End Sub - Public Async Function TestGoToDefinitionOnInferredFieldInitializer() As Task + Public Sub TestGoToDefinitionOnInferredFieldInitializer() Dim workspace = @@ -728,12 +728,12 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestGoToDefinitionGlobalImportAlias() As Task + Public Sub TestGoToDefinitionGlobalImportAlias() Dim workspace = @@ -760,12 +760,12 @@ End Namespace - Await Test(workspace) - End Function + Test(workspace) + End Sub #End Region - Public Async Function TestVisualBasicGoToOnExitSelect_Exit() As Task + Public Sub TestVisualBasicGoToOnExitSelect_Exit() Dim workspace = @@ -782,11 +782,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnExitSelect_Select() As Task + Public Sub TestVisualBasicGoToOnExitSelect_Select() Dim workspace = @@ -803,11 +803,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnExitSub() As Task + Public Sub TestVisualBasicGoToOnExitSub() Dim workspace = @@ -821,11 +821,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnExitFunction() As Task + Public Sub TestVisualBasicGoToOnExitFunction() Dim workspace = @@ -839,11 +839,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnContinueWhile_Continue() As Task + Public Sub TestVisualBasicGoToOnContinueWhile_Continue() Dim workspace = @@ -859,11 +859,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnContinueWhile_While() As Task + Public Sub TestVisualBasicGoToOnContinueWhile_While() Dim workspace = @@ -879,11 +879,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnExitWhile_While() As Task + Public Sub TestVisualBasicGoToOnExitWhile_While() Dim workspace = @@ -899,11 +899,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnContinueFor_Continue() As Task + Public Sub TestVisualBasicGoToOnContinueFor_Continue() Dim workspace = @@ -919,11 +919,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnContinueFor_For() As Task + Public Sub TestVisualBasicGoToOnContinueFor_For() Dim workspace = @@ -939,11 +939,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnExitFor_For() As Task + Public Sub TestVisualBasicGoToOnExitFor_For() Dim workspace = @@ -959,11 +959,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnContinueForEach_For() As Task + Public Sub TestVisualBasicGoToOnContinueForEach_For() Dim workspace = @@ -979,11 +979,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnExitForEach_For() As Task + Public Sub TestVisualBasicGoToOnExitForEach_For() Dim workspace = @@ -999,11 +999,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnContinueDoWhileLoop_Do() As Task + Public Sub TestVisualBasicGoToOnContinueDoWhileLoop_Do() Dim workspace = @@ -1019,11 +1019,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnExitDoWhileLoop_Do() As Task + Public Sub TestVisualBasicGoToOnExitDoWhileLoop_Do() Dim workspace = @@ -1039,11 +1039,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnContinueDoUntilLoop_Do() As Task + Public Sub TestVisualBasicGoToOnContinueDoUntilLoop_Do() Dim workspace = @@ -1059,11 +1059,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnExitDoUntilLoop_Do() As Task + Public Sub TestVisualBasicGoToOnExitDoUntilLoop_Do() Dim workspace = @@ -1079,11 +1079,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnContinueDoLoopWhile_Do() As Task + Public Sub TestVisualBasicGoToOnContinueDoLoopWhile_Do() Dim workspace = @@ -1099,11 +1099,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnContinueDoLoopUntil_Do() As Task + Public Sub TestVisualBasicGoToOnContinueDoLoopUntil_Do() Dim workspace = @@ -1119,11 +1119,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnExitTry() As Task + Public Sub TestVisualBasicGoToOnExitTry() Dim workspace = @@ -1139,11 +1139,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnExitTryInCatch() As Task + Public Sub TestVisualBasicGoToOnExitTryInCatch() Dim workspace = @@ -1160,11 +1160,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnReturnInSub() As Task + Public Sub TestVisualBasicGoToOnReturnInSub() Dim workspace = @@ -1178,11 +1178,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnReturnInSub_Partial() As Task + Public Sub TestVisualBasicGoToOnReturnInSub_Partial() Dim workspace = @@ -1199,11 +1199,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnReturnInSub_Partial_ReverseOrder() As Task + Public Sub TestVisualBasicGoToOnReturnInSub_Partial_ReverseOrder() Dim workspace = @@ -1220,11 +1220,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnReturnInSubLambda() As Task + Public Sub TestVisualBasicGoToOnReturnInSubLambda() Dim workspace = @@ -1240,11 +1240,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnReturnInFunction() As Task + Public Sub TestVisualBasicGoToOnReturnInFunction() Dim workspace = @@ -1258,11 +1258,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnReturnInFunction_OnValue() As Task + Public Sub TestVisualBasicGoToOnReturnInFunction_OnValue() Dim workspace = @@ -1276,11 +1276,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnReturnInIterator() As Task + Public Sub TestVisualBasicGoToOnReturnInIterator() Dim workspace = @@ -1294,11 +1294,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnReturnInIterator_OnValue() As Task + Public Sub TestVisualBasicGoToOnReturnInIterator_OnValue() Dim workspace = @@ -1312,11 +1312,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnReturnInFunctionLambda() As Task + Public Sub TestVisualBasicGoToOnReturnInFunctionLambda() Dim workspace = @@ -1332,11 +1332,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnReturnInConstructor() As Task + Public Sub TestVisualBasicGoToOnReturnInConstructor() Dim workspace = @@ -1350,11 +1350,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnReturnInOperator() As Task + Public Sub TestVisualBasicGoToOnReturnInOperator() Dim workspace = @@ -1368,11 +1368,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnReturnInGetAccessor() As Task + Public Sub TestVisualBasicGoToOnReturnInGetAccessor() Dim workspace = @@ -1388,11 +1388,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnReturnInSetAccessor() As Task + Public Sub TestVisualBasicGoToOnReturnInSetAccessor() Dim workspace = @@ -1408,11 +1408,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnExitPropertyInGetAccessor() As Task + Public Sub TestVisualBasicGoToOnExitPropertyInGetAccessor() Dim workspace = @@ -1428,11 +1428,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnExitPropertyInSetAccessor() As Task + Public Sub TestVisualBasicGoToOnExitPropertyInSetAccessor() Dim workspace = @@ -1448,11 +1448,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnReturnInAddHandler() As Task + Public Sub TestVisualBasicGoToOnReturnInAddHandler() Dim workspace = @@ -1468,11 +1468,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnReturnInRemoveHandler() As Task + Public Sub TestVisualBasicGoToOnReturnInRemoveHandler() Dim workspace = @@ -1488,11 +1488,11 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub - Public Async Function TestVisualBasicGoToOnReturnInRaiseEvent() As Task + Public Sub TestVisualBasicGoToOnReturnInRaiseEvent() Dim workspace = @@ -1508,7 +1508,8 @@ End Class - Await Test(workspace) - End Function + Test(workspace) + End Sub + End Class End Namespace