From b4420494a6f54c2b59406e03f12f3d9a0c02d669 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Sat, 22 Apr 2017 16:10:03 -0700 Subject: [PATCH] Allow callers to indicate if they want classified text produced or not for their definition items. --- ...stractFindUsagesService.ProgressAdapter.cs | 5 ++- .../FindUsages/AbstractFindUsagesService.cs | 5 ++- .../IDefinitionsAndReferencesFactory.cs | 33 +++++++++++++++++-- .../GoToDefinition/GoToDefinitionHelpers.cs | 2 +- .../Peek/PeekableItemFactory.cs | 3 +- .../VisualStudioSymbolNavigationService.cs | 3 +- 6 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs index 8a44deab64d..1e9439192c9 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.ProgressAdapter.cs @@ -90,9 +90,8 @@ private async Task GetDefinitionItemAsync(SymbolAndProjectId def { if (!_definitionToItem.TryGetValue(definition.Symbol, out var definitionItem)) { - definitionItem = await definition.Symbol.ToDefinitionItemAsync( - _solution, includeHiddenLocations: false, - cancellationToken: _context.CancellationToken).ConfigureAwait(false); + definitionItem = await definition.Symbol.ToClassifiedDefinitionItemAsync( + _solution, includeHiddenLocations: false, cancellationToken: _context.CancellationToken).ConfigureAwait(false); _definitionToItem[definition.Symbol] = definitionItem; } diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.cs index 155ff61a991..e054205e05f 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.cs @@ -39,9 +39,8 @@ internal abstract partial class AbstractFindUsagesService : IFindUsagesService var project = tuple.Value.project; foreach (var implementation in tuple.Value.implementations) { - var definitionItem = await implementation.ToDefinitionItemAsync( - project.Solution, includeHiddenLocations: false, - cancellationToken: cancellationToken).ConfigureAwait(false); + var definitionItem = await implementation.ToClassifiedDefinitionItemAsync( + project.Solution, includeHiddenLocations: false, cancellationToken: cancellationToken).ConfigureAwait(false); await context.OnDefinitionFoundAsync(definitionItem).ConfigureAwait(false); } } diff --git a/src/EditorFeatures/Core/FindUsages/IDefinitionsAndReferencesFactory.cs b/src/EditorFeatures/Core/FindUsages/IDefinitionsAndReferencesFactory.cs index 42b3c84b3ce..396595d0383 100644 --- a/src/EditorFeatures/Core/FindUsages/IDefinitionsAndReferencesFactory.cs +++ b/src/EditorFeatures/Core/FindUsages/IDefinitionsAndReferencesFactory.cs @@ -37,10 +37,35 @@ internal class DefaultDefinitionsAndReferencesFactory : IDefinitionsAndReference internal static class DefinitionItemExtensions { - public static async Task ToDefinitionItemAsync( + public static DefinitionItem ToNonClassifiedDefinitionItem( + this ISymbol definition, + Solution solution, + bool includeHiddenLocations) + { + // Because we're passing in 'false' for 'includeClassifiedSpans', this won't ever have + // to actually do async work. This is because the only asynchrony is when we are trying + // to compute the classified spans for the locations of the definition. So it's totally + // fine to pass in CancellationToken.None and block on the result. + return ToDefinitionItemAsync(definition, solution, includeHiddenLocations, + includeClassifiedSpans: false, cancellationToken: CancellationToken.None).Result; + } + + public static Task ToClassifiedDefinitionItemAsync( + this ISymbol definition, + Solution solution, + bool includeHiddenLocations, + CancellationToken cancellationToken) + { + return ToDefinitionItemAsync(definition, solution, + includeHiddenLocations, includeClassifiedSpans: true, cancellationToken: cancellationToken); + } + + + private static async Task ToDefinitionItemAsync( this ISymbol definition, Solution solution, bool includeHiddenLocations, + bool includeClassifiedSpans, CancellationToken cancellationToken) { // Ensure we're working with the original definition for the symbol. I.e. When we're @@ -86,8 +111,10 @@ internal static class DefinitionItemExtensions var document = solution.GetDocument(location.SourceTree); if (document != null) { - var documentLocation = await ClassifiedSpansAndHighlightSpan.GetClassifiedDocumentSpanAsync( - document, location.SourceSpan, cancellationToken).ConfigureAwait(false); + var documentLocation = !includeClassifiedSpans + ? new DocumentSpan(document, location.SourceSpan) + : await ClassifiedSpansAndHighlightSpan.GetClassifiedDocumentSpanAsync( + document, location.SourceSpan, cancellationToken).ConfigureAwait(false); sourceLocations.Add(documentLocation); } diff --git a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs index 14484174b9f..9592b6c12f1 100644 --- a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs +++ b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs @@ -61,7 +61,7 @@ internal static class GoToDefinitionHelpers } var definitions = ArrayBuilder.GetInstance(); - var definitionItem = symbol.ToDefinitionItemAsync( + var definitionItem = symbol.ToClassifiedDefinitionItemAsync( solution, includeHiddenLocations: true, cancellationToken: cancellationToken).WaitAndGetResult(cancellationToken); if (thirdPartyNavigationAllowed) diff --git a/src/EditorFeatures/Core/Implementation/Peek/PeekableItemFactory.cs b/src/EditorFeatures/Core/Implementation/Peek/PeekableItemFactory.cs index f8cc9872d90..2ec25c535cb 100644 --- a/src/EditorFeatures/Core/Implementation/Peek/PeekableItemFactory.cs +++ b/src/EditorFeatures/Core/Implementation/Peek/PeekableItemFactory.cs @@ -60,8 +60,7 @@ private PeekableItemFactory(IMetadataAsSourceFileService metadataAsSourceFileSer } var symbolNavigationService = solution.Workspace.Services.GetService(); - var definitionItem = await symbol.ToDefinitionItemAsync( - solution, includeHiddenLocations: true, cancellationToken: cancellationToken).ConfigureAwait(false); + var definitionItem = symbol.ToNonClassifiedDefinitionItem(solution, includeHiddenLocations: true); if (symbolNavigationService.WouldNavigateToSymbol( definitionItem, solution, cancellationToken, diff --git a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs index 3490b0d6f58..a090d970c7a 100644 --- a/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs +++ b/src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioSymbolNavigationService.cs @@ -158,9 +158,8 @@ public bool TrySymbolNavigationNotify(ISymbol symbol, Solution solution, Cancell ISymbol symbol, Solution solution, CancellationToken cancellationToken) { AssertIsForeground(); - var definitionItem = symbol.ToDefinitionItemAsync( - solution, includeHiddenLocations: true, cancellationToken: cancellationToken).WaitAndGetResult(cancellationToken); + var definitionItem = symbol.ToNonClassifiedDefinitionItem(solution, includeHiddenLocations: true); definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey1, out var rqName); if (!TryGetNavigationAPIRequiredArguments( -- GitLab