提交 bbe1d6b2 编写于 作者: C Cyrus Najmabadi

Siplify code

上级 05b2ed1b
...@@ -102,8 +102,7 @@ private async Task<DefinitionItem> GetDefinitionItemAsync(ISymbol definition) ...@@ -102,8 +102,7 @@ private async Task<DefinitionItem> GetDefinitionItemAsync(ISymbol definition)
if (!_definitionToItem.TryGetValue(definition, out var definitionItem)) if (!_definitionToItem.TryGetValue(definition, out var definitionItem))
{ {
definitionItem = await definition.ToClassifiedDefinitionItemAsync( definitionItem = await definition.ToClassifiedDefinitionItemAsync(
_solution.GetOriginatingProject(definition), includeHiddenLocations: false, _solution, includeHiddenLocations: false, _options, _context.CancellationToken).ConfigureAwait(false);
_options, _context.CancellationToken).ConfigureAwait(false);
_definitionToItem[definition] = definitionItem; _definitionToItem[definition] = definitionItem;
} }
......
...@@ -52,8 +52,7 @@ protected AbstractFindUsagesService(IThreadingContext threadingContext) ...@@ -52,8 +52,7 @@ protected AbstractFindUsagesService(IThreadingContext threadingContext)
foreach (var implementation in implementations) foreach (var implementation in implementations)
{ {
var definitionItem = await implementation.ToClassifiedDefinitionItemAsync( var definitionItem = await implementation.ToClassifiedDefinitionItemAsync(
solution.GetOriginatingProject(implementation), includeHiddenLocations: false, solution, includeHiddenLocations: false, FindReferencesSearchOptions.Default, cancellationToken).ConfigureAwait(false);
FindReferencesSearchOptions.Default, cancellationToken).ConfigureAwait(false);
await context.OnDefinitionFoundAsync(definitionItem).ConfigureAwait(false); await context.OnDefinitionFoundAsync(definitionItem).ConfigureAwait(false);
} }
...@@ -122,16 +121,16 @@ protected AbstractFindUsagesService(IThreadingContext threadingContext) ...@@ -122,16 +121,16 @@ protected AbstractFindUsagesService(IThreadingContext threadingContext)
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
// Find the symbol we want to search and the solution we want to search in. // Find the symbol we want to search and the solution we want to search in.
var symbolAndProjectOpt = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync( var symbolAndSolutionOpt = await FindUsagesHelpers.GetRelevantSymbolAndSolutionAtPositionAsync(
document, position, cancellationToken).ConfigureAwait(false); document, position, cancellationToken).ConfigureAwait(false);
if (symbolAndProjectOpt == null) if (symbolAndSolutionOpt == null)
return; return;
var (symbol, project) = symbolAndProjectOpt.Value; var (symbol, solution) = symbolAndSolutionOpt.Value;
await FindSymbolReferencesAsync( await FindSymbolReferencesAsync(
_threadingContext, context, _threadingContext, context,
symbol, project, symbol, solution,
cancellationToken).ConfigureAwait(false); cancellationToken).ConfigureAwait(false);
} }
...@@ -141,9 +140,9 @@ protected AbstractFindUsagesService(IThreadingContext threadingContext) ...@@ -141,9 +140,9 @@ protected AbstractFindUsagesService(IThreadingContext threadingContext)
/// </summary> /// </summary>
public static async Task FindSymbolReferencesAsync( public static async Task FindSymbolReferencesAsync(
IThreadingContext threadingContext, IFindUsagesContext context, IThreadingContext threadingContext, IFindUsagesContext context,
ISymbol symbol, Project project, CancellationToken cancellationToken) ISymbol symbol, Solution solution, CancellationToken cancellationToken)
{ {
var monikerUsagesService = project.Solution.Workspace.Services.GetRequiredService<IFindSymbolMonikerUsagesService>(); var monikerUsagesService = solution.Workspace.Services.GetRequiredService<IFindSymbolMonikerUsagesService>();
await context.SetSearchTitleAsync(string.Format(EditorFeaturesResources._0_references, await context.SetSearchTitleAsync(string.Format(EditorFeaturesResources._0_references,
FindUsagesHelpers.GetDisplayName(symbol))).ConfigureAwait(false); FindUsagesHelpers.GetDisplayName(symbol))).ConfigureAwait(false);
...@@ -154,20 +153,13 @@ protected AbstractFindUsagesService(IThreadingContext threadingContext) ...@@ -154,20 +153,13 @@ protected AbstractFindUsagesService(IThreadingContext threadingContext)
// engine will push results into the 'progress' instance passed into it. // engine will push results into the 'progress' instance passed into it.
// We'll take those results, massage them, and forward them along to the // We'll take those results, massage them, and forward them along to the
// FindReferencesContext instance we were given. // FindReferencesContext instance we were given.
var progress = new FindReferencesProgressAdapter(threadingContext, solution, context, options);
var normalFindReferencesTask = SymbolFinder.FindReferencesAsync( var normalFindReferencesTask = SymbolFinder.FindReferencesAsync(
symbol, symbol, solution, progress, documents: null, options, cancellationToken);
project.Solution,
new FindReferencesProgressAdapter(threadingContext, project.Solution, context, options),
documents: null,
options,
cancellationToken);
// Kick off work to search the online code index system in parallel // Kick off work to search the online code index system in parallel
var codeIndexReferencesTask = FindSymbolMonikerReferencesAsync( var codeIndexReferencesTask = FindSymbolMonikerReferencesAsync(
monikerUsagesService, monikerUsagesService, symbol, context, cancellationToken);
symbol,
context,
cancellationToken);
await Task.WhenAll(normalFindReferencesTask, codeIndexReferencesTask).ConfigureAwait(false); await Task.WhenAll(normalFindReferencesTask, codeIndexReferencesTask).ConfigureAwait(false);
} }
......
...@@ -31,7 +31,7 @@ public static string GetDisplayName(ISymbol symbol) ...@@ -31,7 +31,7 @@ public static string GetDisplayName(ISymbol symbol)
/// there may be symbol mapping involved (for example in Metadata-As-Source /// there may be symbol mapping involved (for example in Metadata-As-Source
/// scenarios). /// scenarios).
/// </summary> /// </summary>
public static async Task<(ISymbol symbol, Project project)?> GetRelevantSymbolAndProjectAtPositionAsync( public static async Task<(ISymbol symbol, Solution solution)?> GetRelevantSymbolAndSolutionAtPositionAsync(
Document document, int position, CancellationToken cancellationToken) Document document, int position, CancellationToken cancellationToken)
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
...@@ -49,19 +49,19 @@ public static string GetDisplayName(ISymbol symbol) ...@@ -49,19 +49,19 @@ public static string GetDisplayName(ISymbol symbol)
if (mapping == null) if (mapping == null)
return null; return null;
return (mapping.Symbol, mapping.Project); return (mapping.Symbol, mapping.Project.Solution);
} }
public static async Task<(Solution solution, ISymbol symbol, ImmutableArray<ISymbol> implementations, string message)?> FindSourceImplementationsAsync(Document document, int position, CancellationToken cancellationToken) public static async Task<(Solution solution, ISymbol symbol, ImmutableArray<ISymbol> implementations, string message)?> FindSourceImplementationsAsync(Document document, int position, CancellationToken cancellationToken)
{ {
var symbolAndProjectOpt = await GetRelevantSymbolAndProjectAtPositionAsync( var symbolAndSolutionOpt = await GetRelevantSymbolAndSolutionAtPositionAsync(
document, position, cancellationToken).ConfigureAwait(false); document, position, cancellationToken).ConfigureAwait(false);
if (symbolAndProjectOpt == null) if (symbolAndSolutionOpt == null)
return null; return null;
var (symbol, project) = symbolAndProjectOpt.Value; var (symbol, solution) = symbolAndSolutionOpt.Value;
return await FindSourceImplementationsAsync( return await FindSourceImplementationsAsync(
project.Solution, symbol, cancellationToken).ConfigureAwait(false); solution, symbol, cancellationToken).ConfigureAwait(false);
} }
private static async Task<(Solution solution, ISymbol symbol, ImmutableArray<ISymbol> implementations, string message)?> FindSourceImplementationsAsync( private static async Task<(Solution solution, ISymbol symbol, ImmutableArray<ISymbol> implementations, string message)?> FindSourceImplementationsAsync(
......
...@@ -53,7 +53,7 @@ internal static class DefinitionItemExtensions ...@@ -53,7 +53,7 @@ internal static class DefinitionItemExtensions
{ {
public static DefinitionItem ToNonClassifiedDefinitionItem( public static DefinitionItem ToNonClassifiedDefinitionItem(
this ISymbol definition, this ISymbol definition,
Project project, Solution solution,
bool includeHiddenLocations) bool includeHiddenLocations)
{ {
// Because we're passing in 'false' for 'includeClassifiedSpans', this won't ever have // Because we're passing in 'false' for 'includeClassifiedSpans', this won't ever have
...@@ -61,25 +61,25 @@ internal static class DefinitionItemExtensions ...@@ -61,25 +61,25 @@ internal static class DefinitionItemExtensions
// to compute the classified spans for the locations of the definition. So it's totally // 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. // fine to pass in CancellationToken.None and block on the result.
return ToDefinitionItemAsync( return ToDefinitionItemAsync(
definition, project, includeHiddenLocations, includeClassifiedSpans: false, definition, solution, includeHiddenLocations, includeClassifiedSpans: false,
options: FindReferencesSearchOptions.Default, cancellationToken: CancellationToken.None).WaitAndGetResult_CanCallOnBackground(CancellationToken.None); options: FindReferencesSearchOptions.Default, cancellationToken: CancellationToken.None).WaitAndGetResult_CanCallOnBackground(CancellationToken.None);
} }
public static Task<DefinitionItem> ToClassifiedDefinitionItemAsync( public static Task<DefinitionItem> ToClassifiedDefinitionItemAsync(
this ISymbol definition, this ISymbol definition,
Project project, Solution solution,
bool includeHiddenLocations, bool includeHiddenLocations,
FindReferencesSearchOptions options, FindReferencesSearchOptions options,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
return ToDefinitionItemAsync(definition, project, return ToDefinitionItemAsync(definition, solution,
includeHiddenLocations, includeClassifiedSpans: true, includeHiddenLocations, includeClassifiedSpans: true,
options, cancellationToken); options, cancellationToken);
} }
private static async Task<DefinitionItem> ToDefinitionItemAsync( private static async Task<DefinitionItem> ToDefinitionItemAsync(
this ISymbol definition, this ISymbol definition,
Project project, Solution solution,
bool includeHiddenLocations, bool includeHiddenLocations,
bool includeClassifiedSpans, bool includeClassifiedSpans,
FindReferencesSearchOptions options, FindReferencesSearchOptions options,
...@@ -121,7 +121,7 @@ internal static class DefinitionItemExtensions ...@@ -121,7 +121,7 @@ internal static class DefinitionItemExtensions
if (location.IsInMetadata) if (location.IsInMetadata)
{ {
return DefinitionItem.CreateMetadataDefinition( return DefinitionItem.CreateMetadataDefinition(
tags, displayParts, nameDisplayParts, project, tags, displayParts, nameDisplayParts, solution,
definition, properties, displayIfNoReferences); definition, properties, displayIfNoReferences);
} }
else if (location.IsInSource) else if (location.IsInSource)
...@@ -132,7 +132,7 @@ internal static class DefinitionItemExtensions ...@@ -132,7 +132,7 @@ internal static class DefinitionItemExtensions
continue; continue;
} }
var document = project.Solution.GetDocument(location.SourceTree); var document = solution.GetDocument(location.SourceTree);
if (document != null) if (document != null)
{ {
var documentLocation = !includeClassifiedSpans var documentLocation = !includeClassifiedSpans
......
...@@ -16,21 +16,20 @@ internal abstract partial class AbstractGoToBaseService : IGoToBaseService ...@@ -16,21 +16,20 @@ internal abstract partial class AbstractGoToBaseService : IGoToBaseService
public async Task FindBasesAsync(Document document, int position, IFindUsagesContext context) public async Task FindBasesAsync(Document document, int position, IFindUsagesContext context)
{ {
var cancellationToken = context.CancellationToken; var cancellationToken = context.CancellationToken;
var symbolAndProjectOpt = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync( var symbolAndSolutionOpt = await FindUsagesHelpers.GetRelevantSymbolAndSolutionAtPositionAsync(
document, position, cancellationToken).ConfigureAwait(false); document, position, cancellationToken).ConfigureAwait(false);
if (symbolAndProjectOpt == null) if (symbolAndSolutionOpt == null)
{ {
await context.ReportMessageAsync( await context.ReportMessageAsync(
EditorFeaturesResources.Cannot_navigate_to_the_symbol_under_the_caret).ConfigureAwait(false); EditorFeaturesResources.Cannot_navigate_to_the_symbol_under_the_caret).ConfigureAwait(false);
return; return;
} }
var (symbol, project) = symbolAndProjectOpt.Value; var (symbol, solution) = symbolAndSolutionOpt.Value;
var solution = project.Solution;
var bases = FindBaseHelpers.FindBases( var bases = FindBaseHelpers.FindBases(
symbol, project, cancellationToken); symbol, solution, cancellationToken);
await context.SetSearchTitleAsync( await context.SetSearchTitleAsync(
string.Format(EditorFeaturesResources._0_bases, string.Format(EditorFeaturesResources._0_bases,
...@@ -48,8 +47,7 @@ public async Task FindBasesAsync(Document document, int position, IFindUsagesCon ...@@ -48,8 +47,7 @@ public async Task FindBasesAsync(Document document, int position, IFindUsagesCon
if (sourceDefinition != null) if (sourceDefinition != null)
{ {
var definitionItem = await sourceDefinition.ToClassifiedDefinitionItemAsync( var definitionItem = await sourceDefinition.ToClassifiedDefinitionItemAsync(
solution.GetOriginatingProject(sourceDefinition), includeHiddenLocations: false, solution, includeHiddenLocations: false, FindReferencesSearchOptions.Default, cancellationToken: cancellationToken).ConfigureAwait(false);
FindReferencesSearchOptions.Default, cancellationToken: cancellationToken).ConfigureAwait(false);
await context.OnDefinitionFoundAsync(definitionItem).ConfigureAwait(false); await context.OnDefinitionFoundAsync(definitionItem).ConfigureAwait(false);
found = true; found = true;
...@@ -57,7 +55,7 @@ public async Task FindBasesAsync(Document document, int position, IFindUsagesCon ...@@ -57,7 +55,7 @@ public async Task FindBasesAsync(Document document, int position, IFindUsagesCon
else if (baseSymbol.Locations.Any(l => l.IsInMetadata)) else if (baseSymbol.Locations.Any(l => l.IsInMetadata))
{ {
var definitionItem = baseSymbol.ToNonClassifiedDefinitionItem( var definitionItem = baseSymbol.ToNonClassifiedDefinitionItem(
project, includeHiddenLocations: true); solution, includeHiddenLocations: true);
await context.OnDefinitionFoundAsync(definitionItem).ConfigureAwait(false); await context.OnDefinitionFoundAsync(definitionItem).ConfigureAwait(false);
found = true; found = true;
} }
......
...@@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.Editor.GoToBase ...@@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.Editor.GoToBase
internal static class FindBaseHelpers internal static class FindBaseHelpers
{ {
public static ImmutableArray<ISymbol> FindBases( public static ImmutableArray<ISymbol> FindBases(
ISymbol symbol, Project project, CancellationToken cancellationToken) ISymbol symbol, Solution solution, CancellationToken cancellationToken)
{ {
if (symbol is INamedTypeSymbol namedTypeSymbol && if (symbol is INamedTypeSymbol namedTypeSymbol &&
(namedTypeSymbol.TypeKind == TypeKind.Class || (namedTypeSymbol.TypeKind == TypeKind.Class ||
...@@ -24,8 +24,7 @@ internal static class FindBaseHelpers ...@@ -24,8 +24,7 @@ internal static class FindBaseHelpers
symbol.Kind == SymbolKind.Method || symbol.Kind == SymbolKind.Method ||
symbol.Kind == SymbolKind.Event) symbol.Kind == SymbolKind.Event)
{ {
return BaseTypeFinder.FindOverriddenAndImplementedMembers( return BaseTypeFinder.FindOverriddenAndImplementedMembers(symbol, solution, cancellationToken);
symbol, project, cancellationToken);
} }
else else
{ {
......
...@@ -63,7 +63,7 @@ public bool TryGoToDefinition(Document document, int position, CancellationToken ...@@ -63,7 +63,7 @@ public bool TryGoToDefinition(Document document, int position, CancellationToken
var isThirdPartyNavigationAllowed = IsThirdPartyNavigationAllowed(symbol, position, document, cancellationToken); var isThirdPartyNavigationAllowed = IsThirdPartyNavigationAllowed(symbol, position, document, cancellationToken);
return GoToDefinitionHelpers.TryGoToDefinition(symbol, return GoToDefinitionHelpers.TryGoToDefinition(symbol,
document.Project, document.Project.Solution,
_streamingPresenter.Value, _streamingPresenter.Value,
thirdPartyNavigationAllowed: isThirdPartyNavigationAllowed, thirdPartyNavigationAllowed: isThirdPartyNavigationAllowed,
cancellationToken: cancellationToken); cancellationToken: cancellationToken);
...@@ -100,7 +100,7 @@ public bool TryGoToDefinition(Document document, int position, CancellationToken ...@@ -100,7 +100,7 @@ public bool TryGoToDefinition(Document document, int position, CancellationToken
var definitions = interfaceImpls.SelectMany( var definitions = interfaceImpls.SelectMany(
i => GoToDefinitionHelpers.GetDefinitions( i => GoToDefinitionHelpers.GetDefinitions(
i, project, thirdPartyNavigationAllowed: false, cancellationToken)).ToImmutableArray(); i, solution, thirdPartyNavigationAllowed: false, cancellationToken)).ToImmutableArray();
var title = string.Format(EditorFeaturesResources._0_implemented_members, var title = string.Format(EditorFeaturesResources._0_implemented_members,
FindUsagesHelpers.GetDisplayName(symbol)); FindUsagesHelpers.GetDisplayName(symbol));
......
...@@ -40,8 +40,9 @@ public async Task GetSymbolsAsync(GoToSymbolContext context) ...@@ -40,8 +40,9 @@ public async Task GetSymbolsAsync(GoToSymbolContext context)
await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, cancellationToken); await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, cancellationToken);
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
var definitions = GoToDefinitionHelpers.GetDefinitions(symbol, document.Project, thirdPartyNavigationAllowed: true, cancellationToken) var solution = document.Project.Solution;
.WhereAsArray(d => d.CanNavigateTo(document.Project.Solution.Workspace)); var definitions = GoToDefinitionHelpers.GetDefinitions(symbol, solution, thirdPartyNavigationAllowed: true, cancellationToken)
.WhereAsArray(d => d.CanNavigateTo(solution.Workspace));
await TaskScheduler.Default; await TaskScheduler.Default;
......
...@@ -20,7 +20,7 @@ internal static class GoToDefinitionHelpers ...@@ -20,7 +20,7 @@ internal static class GoToDefinitionHelpers
{ {
public static ImmutableArray<DefinitionItem> GetDefinitions( public static ImmutableArray<DefinitionItem> GetDefinitions(
ISymbol symbol, ISymbol symbol,
Project project, Solution solution,
bool thirdPartyNavigationAllowed, bool thirdPartyNavigationAllowed,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
...@@ -36,13 +36,12 @@ internal static class GoToDefinitionHelpers ...@@ -36,13 +36,12 @@ internal static class GoToDefinitionHelpers
// VB global import aliases have a synthesized SyntaxTree. // VB global import aliases have a synthesized SyntaxTree.
// We can't go to the definition of the alias, so use the target type. // We can't go to the definition of the alias, so use the target type.
var solution = project.Solution;
if (alias != null) if (alias != null)
{ {
var sourceLocations = NavigableItemFactory.GetPreferredSourceLocations( var sourceLocations = NavigableItemFactory.GetPreferredSourceLocations(
solution, symbol, cancellationToken); solution, symbol, cancellationToken);
if (sourceLocations.All(l => project.Solution.GetDocument(l.SourceTree) == null)) if (sourceLocations.All(l => solution.GetDocument(l.SourceTree) == null))
{ {
symbol = alias.Target; symbol = alias.Target;
} }
...@@ -81,7 +80,7 @@ internal static class GoToDefinitionHelpers ...@@ -81,7 +80,7 @@ internal static class GoToDefinitionHelpers
// So, if we only have a single location to go to, this does no unnecessary work. And, // So, if we only have a single location to go to, this does no unnecessary work. And,
// if we do have multiple locations to show, it will just be done in the BG, unblocking // if we do have multiple locations to show, it will just be done in the BG, unblocking
// this command thread so it can return the user faster. // this command thread so it can return the user faster.
var definitionItem = symbol.ToNonClassifiedDefinitionItem(project, includeHiddenLocations: true); var definitionItem = symbol.ToNonClassifiedDefinitionItem(solution, includeHiddenLocations: true);
if (thirdPartyNavigationAllowed) if (thirdPartyNavigationAllowed)
{ {
...@@ -96,23 +95,23 @@ internal static class GoToDefinitionHelpers ...@@ -96,23 +95,23 @@ internal static class GoToDefinitionHelpers
public static bool TryGoToDefinition( public static bool TryGoToDefinition(
ISymbol symbol, ISymbol symbol,
Project project, Solution solution,
IStreamingFindUsagesPresenter streamingPresenter, IStreamingFindUsagesPresenter streamingPresenter,
CancellationToken cancellationToken, CancellationToken cancellationToken,
bool thirdPartyNavigationAllowed = true) bool thirdPartyNavigationAllowed = true)
{ {
var definitions = GetDefinitions(symbol, project, thirdPartyNavigationAllowed, cancellationToken); var definitions = GetDefinitions(symbol, solution, thirdPartyNavigationAllowed, cancellationToken);
var title = string.Format(EditorFeaturesResources._0_declarations, var title = string.Format(EditorFeaturesResources._0_declarations,
FindUsagesHelpers.GetDisplayName(symbol)); FindUsagesHelpers.GetDisplayName(symbol));
return streamingPresenter.TryNavigateToOrPresentItemsAsync( return streamingPresenter.TryNavigateToOrPresentItemsAsync(
project.Solution.Workspace, title, definitions).WaitAndGetResult(cancellationToken); solution.Workspace, title, definitions).WaitAndGetResult(cancellationToken);
} }
public static bool TryGoToDefinition( public static bool TryGoToDefinition(
ImmutableArray<DefinitionItem> definitions, ImmutableArray<DefinitionItem> definitions,
Project project, Solution solution,
string title, string title,
IStreamingFindUsagesPresenter streamingPresenter, IStreamingFindUsagesPresenter streamingPresenter,
CancellationToken cancellationToken) CancellationToken cancellationToken)
...@@ -123,7 +122,7 @@ internal static class GoToDefinitionHelpers ...@@ -123,7 +122,7 @@ internal static class GoToDefinitionHelpers
} }
return streamingPresenter.TryNavigateToOrPresentItemsAsync( return streamingPresenter.TryNavigateToOrPresentItemsAsync(
project.Solution.Workspace, title, definitions).WaitAndGetResult(cancellationToken); solution.Workspace, title, definitions).WaitAndGetResult(cancellationToken);
} }
} }
} }
...@@ -168,7 +168,7 @@ private static void NavigateToQuickInfoTarget(string navigationTarget, Document ...@@ -168,7 +168,7 @@ private static void NavigateToQuickInfoTarget(string navigationTarget, Document
if (resolvedSymbolKey.GetAnySymbol() is { } symbol) if (resolvedSymbolKey.GetAnySymbol() is { } symbol)
{ {
GoToDefinitionHelpers.TryGoToDefinition(symbol, document.Project, streamingPresenter, CancellationToken.None); GoToDefinitionHelpers.TryGoToDefinition(symbol, document.Project.Solution, streamingPresenter, CancellationToken.None);
return; return;
} }
} }
......
...@@ -62,7 +62,7 @@ public PeekableItemFactory(IMetadataAsSourceFileService metadataAsSourceFileServ ...@@ -62,7 +62,7 @@ public PeekableItemFactory(IMetadataAsSourceFileService metadataAsSourceFileServ
} }
var symbolNavigationService = solution.Workspace.Services.GetService<ISymbolNavigationService>(); var symbolNavigationService = solution.Workspace.Services.GetService<ISymbolNavigationService>();
var definitionItem = symbol.ToNonClassifiedDefinitionItem(project, includeHiddenLocations: true); var definitionItem = symbol.ToNonClassifiedDefinitionItem(solution, includeHiddenLocations: true);
if (symbolNavigationService.WouldNavigateToSymbol( if (symbolNavigationService.WouldNavigateToSymbol(
definitionItem, solution, cancellationToken, definitionItem, solution, cancellationToken,
......
...@@ -52,7 +52,7 @@ private class NavigableSymbol : INavigableSymbol ...@@ -52,7 +52,7 @@ private class NavigableSymbol : INavigableSymbol
showProgress: false, showProgress: false,
action: context => GoToDefinitionHelpers.TryGoToDefinition( action: context => GoToDefinitionHelpers.TryGoToDefinition(
_definitions, _definitions,
_document.Project, _document.Project.Solution,
_definitions[0].NameDisplayParts.GetFullText(), _definitions[0].NameDisplayParts.GetFullText(),
_presenter, _presenter,
context.CancellationToken) context.CancellationToken)
......
...@@ -213,7 +213,7 @@ internal abstract partial class DefinitionItem ...@@ -213,7 +213,7 @@ internal abstract partial class DefinitionItem
ImmutableArray<string> tags, ImmutableArray<string> tags,
ImmutableArray<TaggedText> displayParts, ImmutableArray<TaggedText> displayParts,
ImmutableArray<TaggedText> nameDisplayParts, ImmutableArray<TaggedText> nameDisplayParts,
Project project, Solution solution,
ISymbol symbol, ISymbol symbol,
ImmutableDictionary<string, string> properties = null, ImmutableDictionary<string, string> properties = null,
bool displayIfNoReferences = true) bool displayIfNoReferences = true)
...@@ -222,9 +222,12 @@ internal abstract partial class DefinitionItem ...@@ -222,9 +222,12 @@ internal abstract partial class DefinitionItem
var symbolKey = symbol.GetSymbolKey().ToString(); var symbolKey = symbol.GetSymbolKey().ToString();
var projectId = solution.GetOriginatingProjectId(symbol);
Contract.ThrowIfNull(projectId);
properties = properties.Add(MetadataSymbolKey, symbolKey) properties = properties.Add(MetadataSymbolKey, symbolKey)
.Add(MetadataSymbolOriginatingProjectIdGuid, project.Id.Id.ToString()) .Add(MetadataSymbolOriginatingProjectIdGuid, projectId.Id.ToString())
.Add(MetadataSymbolOriginatingProjectIdDebugName, project.Id.DebugName); .Add(MetadataSymbolOriginatingProjectIdDebugName, projectId.DebugName);
var originationParts = GetOriginationParts(symbol); var originationParts = GetOriginationParts(symbol);
return new DefaultDefinitionItem( return new DefaultDefinitionItem(
......
...@@ -39,7 +39,8 @@ public async Task FindSymbolReferencesAsync(ISymbol symbol, Project project, Can ...@@ -39,7 +39,8 @@ public async Task FindSymbolReferencesAsync(ISymbol symbol, Project project, Can
// the context object that the FAR service will push results into. // the context object that the FAR service will push results into.
var context = streamingPresenter.StartSearch(EditorFeaturesResources.Find_References, supportsReferences: true); var context = streamingPresenter.StartSearch(EditorFeaturesResources.Find_References, supportsReferences: true);
await AbstractFindUsagesService.FindSymbolReferencesAsync(_threadingContext, context, symbol, project, cancellationToken).ConfigureAwait(false); await AbstractFindUsagesService.FindSymbolReferencesAsync(
_threadingContext, context, symbol, project.Solution, cancellationToken).ConfigureAwait(false);
// Note: we don't need to put this in a finally. The only time we might not hit // Note: we don't need to put this in a finally. The only time we might not hit
// this is if cancellation or another error gets thrown. In the former case, // this is if cancellation or another error gets thrown. In the former case,
......
...@@ -553,8 +553,7 @@ private static async Task FindReferencesAsync(IThreadingContext threadingContext ...@@ -553,8 +553,7 @@ private static async Task FindReferencesAsync(IThreadingContext threadingContext
if (symbol != null) if (symbol != null)
{ {
await AbstractFindUsagesService.FindSymbolReferencesAsync( await AbstractFindUsagesService.FindSymbolReferencesAsync(
threadingContext, threadingContext, context, symbol, project.Solution, cancellationToken).ConfigureAwait(false);
context, symbol, project, cancellationToken).ConfigureAwait(false);
} }
} }
} }
......
...@@ -178,14 +178,14 @@ public bool TryNavigateToSymbol(ISymbol symbol, Project project, OptionSet optio ...@@ -178,14 +178,14 @@ public bool TryNavigateToSymbol(ISymbol symbol, Project project, OptionSet optio
} }
public bool TrySymbolNavigationNotify(ISymbol symbol, Project project, CancellationToken cancellationToken) public bool TrySymbolNavigationNotify(ISymbol symbol, Project project, CancellationToken cancellationToken)
=> TryNotifyForSpecificSymbol(symbol, project, cancellationToken); => TryNotifyForSpecificSymbol(symbol, project.Solution, cancellationToken);
private bool TryNotifyForSpecificSymbol( private bool TryNotifyForSpecificSymbol(
ISymbol symbol, Project project, CancellationToken cancellationToken) ISymbol symbol, Solution solution, CancellationToken cancellationToken)
{ {
AssertIsForeground(); AssertIsForeground();
var definitionItem = symbol.ToNonClassifiedDefinitionItem(project, includeHiddenLocations: true); var definitionItem = symbol.ToNonClassifiedDefinitionItem(solution, includeHiddenLocations: true);
definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey1, out var rqName); definitionItem.Properties.TryGetValue(DefinitionItem.RQNameKey1, out var rqName);
if (!TryGetNavigationAPIRequiredArguments( if (!TryGetNavigationAPIRequiredArguments(
......
...@@ -122,7 +122,7 @@ internal override IInvisibleEditor OpenInvisibleEditor(DocumentId documentId) ...@@ -122,7 +122,7 @@ internal override IInvisibleEditor OpenInvisibleEditor(DocumentId documentId)
} }
return GoToDefinitionHelpers.TryGoToDefinition( return GoToDefinitionHelpers.TryGoToDefinition(
searchSymbol, searchProject, searchSymbol, searchProject.Solution,
_streamingPresenter.Value, cancellationToken); _streamingPresenter.Value, cancellationToken);
} }
......
...@@ -15,9 +15,8 @@ public static ImmutableArray<ISymbol> FindBaseTypesAndInterfaces(INamedTypeSymbo ...@@ -15,9 +15,8 @@ public static ImmutableArray<ISymbol> FindBaseTypesAndInterfaces(INamedTypeSymbo
=> FindBaseTypes(type).AddRange(type.AllInterfaces).CastArray<ISymbol>(); => FindBaseTypes(type).AddRange(type.AllInterfaces).CastArray<ISymbol>();
public static ImmutableArray<ISymbol> FindOverriddenAndImplementedMembers( public static ImmutableArray<ISymbol> FindOverriddenAndImplementedMembers(
ISymbol symbol, Project project, CancellationToken cancellationToken) ISymbol symbol, Solution solution, CancellationToken cancellationToken)
{ {
var solution = project.Solution;
var results = ArrayBuilder<ISymbol>.GetInstance(); var results = ArrayBuilder<ISymbol>.GetInstance();
// This is called for all: class, struct or interface member. // This is called for all: class, struct or interface member.
......
...@@ -325,7 +325,7 @@ public System.Uri Get() ...@@ -325,7 +325,7 @@ public System.Uri Get()
var projectIds = new HashSet<ProjectId>(); var projectIds = new HashSet<ProjectId>();
foreach (var r in references) foreach (var r in references)
projectIds.Add(solution.GetExactProjectId(r.Definition)); projectIds.Add(solution.GetOriginatingProjectId(r.Definition));
Assert.True(projectIds.Contains(desktopProject.Id)); Assert.True(projectIds.Contains(desktopProject.Id));
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册