提交 e5a0aa90 编写于 作者: S Sam Harwell

Make IStreamingFindUsagesPresenters a required export

上级 065f3579
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Composition;
using Microsoft.CodeAnalysis.Editor.GoToDefinition;
using Microsoft.CodeAnalysis.Editor.Host;
......@@ -12,9 +11,8 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.GoToDefinition
internal class CSharpGoToDefinitionService : AbstractGoToDefinitionService
{
[ImportingConstructor]
public CSharpGoToDefinitionService(
[Import(AllowDefault = true)] Lazy<IStreamingFindUsagesPresenter> streamingPresenterOpt)
: base(streamingPresenterOpt)
public CSharpGoToDefinitionService(IStreamingFindUsagesPresenter streamingPresenter)
: base(streamingPresenter)
{
}
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
......@@ -16,12 +15,11 @@ namespace Microsoft.CodeAnalysis.Editor.GoToDefinition
// GoToDefinition
internal abstract class AbstractGoToDefinitionService : IGoToDefinitionService
{
private readonly Lazy<IStreamingFindUsagesPresenter> _streamingPresenterOpt;
private readonly IStreamingFindUsagesPresenter _streamingPresenter;
protected AbstractGoToDefinitionService(
Lazy<IStreamingFindUsagesPresenter> streamingPresenterOpt)
protected AbstractGoToDefinitionService(IStreamingFindUsagesPresenter streamingPresenter)
{
_streamingPresenterOpt = streamingPresenterOpt;
_streamingPresenter = streamingPresenter;
}
public async Task<IEnumerable<INavigableItem>> FindDefinitionsAsync(
......@@ -54,7 +52,7 @@ public bool TryGoToDefinition(Document document, int position, CancellationToken
return GoToDefinitionHelpers.TryGoToDefinition(symbol,
document.Project,
_streamingPresenterOpt,
_streamingPresenter,
thirdPartyNavigationAllowed: isThirdPartyNavigationAllowed,
throwOnHiddenDefinition: true,
cancellationToken: cancellationToken);
......
......@@ -95,18 +95,17 @@ internal static class GoToDefinitionHelpers
public static bool TryGoToDefinition(
ISymbol symbol,
Project project,
Lazy<IStreamingFindUsagesPresenter> streamingPresenterOpt,
IStreamingFindUsagesPresenter streamingPresenter,
CancellationToken cancellationToken,
bool thirdPartyNavigationAllowed = true,
bool throwOnHiddenDefinition = false)
{
var definitions = GetDefinitions(symbol, project, thirdPartyNavigationAllowed, cancellationToken);
var presenter = streamingPresenterOpt?.Value;
var title = string.Format(EditorFeaturesResources._0_declarations,
FindUsagesHelpers.GetDisplayName(symbol));
return presenter.TryNavigateToOrPresentItemsAsync(
return streamingPresenter.TryNavigateToOrPresentItemsAsync(
project.Solution.Workspace, title, definitions).WaitAndGetResult(cancellationToken);
}
......
......@@ -100,7 +100,7 @@ class C
Dim cursorBuffer = cursorDocument.TextBuffer
Dim document = workspace.CurrentSolution.GetDocument(cursorDocument.Id)
Dim goToDefService = New CSharpGoToDefinitionService(New Lazy(Of IStreamingFindUsagesPresenter)(Function() presenter))
Dim goToDefService = New CSharpGoToDefinitionService(presenter)
Dim waitContext = New TestUIThreadOperationContext(updatesBeforeCancel)
Dim commandHandler = New GoToDefinitionCommandHandler()
......
......@@ -14,7 +14,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition
Public Class GoToDefinitionTests
Friend Sub Test(workspaceDefinition As XElement,
expectedResult As Boolean,
executeOnDocument As Func(Of Document, Integer, Lazy(Of IStreamingFindUsagesPresenter), Boolean))
executeOnDocument As Func(Of Document, Integer, IStreamingFindUsagesPresenter, Boolean))
Using workspace = TestWorkspace.Create(
workspaceDefinition, exportProvider:=GoToTestHelpers.ExportProviderFactory.CreateExportProvider())
Dim solution = workspace.CurrentSolution
......@@ -38,7 +38,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition
Dim presenterCalled As Boolean = False
Dim presenter = New MockStreamingFindUsagesPresenter(Sub() presenterCalled = True)
Dim actualResult = executeOnDocument(document, cursorPosition, New Lazy(Of IStreamingFindUsagesPresenter)(Function() presenter))
Dim actualResult = executeOnDocument(document, cursorPosition, presenter)
Assert.Equal(expectedResult, actualResult)
......@@ -103,7 +103,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition
Private Sub Test(workspaceDefinition As XElement, Optional expectedResult As Boolean = True)
Test(workspaceDefinition, expectedResult,
Function(document As Document, cursorPosition As Integer, presenter As Lazy(Of IStreamingFindUsagesPresenter))
Function(document As Document, cursorPosition As Integer, presenter As IStreamingFindUsagesPresenter)
Dim goToDefService = If(document.Project.Language = LanguageNames.CSharp,
DirectCast(New CSharpGoToDefinitionService(presenter), IGoToDefinitionService),
New VisualBasicGoToDefinitionService(presenter))
......
......@@ -11,8 +11,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.GoToDefinition
Inherits AbstractGoToDefinitionService
<ImportingConstructor>
Public Sub New(<Import(AllowDefault:=True)> streamingPresenterOpt As Lazy(Of IStreamingFindUsagesPresenter))
MyBase.New(streamingPresenterOpt)
Public Sub New(streamingPresenter As IStreamingFindUsagesPresenter)
MyBase.New(streamingPresenter)
End Sub
End Class
End Namespace
......@@ -2,7 +2,6 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.CodeAnalysis;
......@@ -41,7 +40,7 @@ internal abstract partial class AbstractObjectBrowserLibraryManager : AbstractLi
private AbstractListItemFactory _listItemFactory;
private object _classMemberGate = new object();
private readonly Lazy<IStreamingFindUsagesPresenter> _streamingPresenterOpt;
private readonly IStreamingFindUsagesPresenter _streamingPresenter;
private readonly IThreadingContext _threadingContext;
protected AbstractObjectBrowserLibraryManager(
......@@ -61,7 +60,7 @@ internal abstract partial class AbstractObjectBrowserLibraryManager : AbstractLi
Workspace.WorkspaceChanged += OnWorkspaceChanged;
_libraryService = new Lazy<ILibraryService>(() => Workspace.Services.GetLanguageServices(_languageName).GetService<ILibraryService>());
_streamingPresenterOpt = componentModel.DefaultExportProvider.GetExports<IStreamingFindUsagesPresenter>().SingleOrDefault();
_streamingPresenter = componentModel.DefaultExportProvider.GetExportedValue<IStreamingFindUsagesPresenter>();
_threadingContext = componentModel.DefaultExportProvider.GetExportedValue<IThreadingContext>();
}
......@@ -501,10 +500,8 @@ protected override bool TryExec(Guid commandGroup, uint commandId)
switch (commandId)
{
case (uint)VSConstants.VSStd97CmdID.FindReferences:
var streamingPresenter = _streamingPresenterOpt?.Value;
var symbolListItem = _activeListItem as SymbolListItem;
if (streamingPresenter != null && symbolListItem?.ProjectId != null)
if (symbolListItem?.ProjectId != null)
{
var project = this.Workspace.CurrentSolution.GetProject(symbolListItem.ProjectId);
if (project != null)
......@@ -514,7 +511,7 @@ protected override bool TryExec(Guid commandGroup, uint commandId)
// and the references will be asynchronously added to the FindReferences
// window as they are computed. The user also knows something is happening
// as the window, with the progress-banner will pop up immediately.
var task = FindReferencesAsync(streamingPresenter, symbolListItem, project);
var task = FindReferencesAsync(_streamingPresenter, symbolListItem, project);
return true;
}
}
......
......@@ -28,6 +28,10 @@ namespace Microsoft.VisualStudio.LanguageServices
[Export(typeof(VisualStudioWorkspaceImpl))]
internal class RoslynVisualStudioWorkspace : VisualStudioWorkspaceImpl
{
/// <remarks>
/// Must be lazily constructed since the <see cref="IStreamingFindUsagesPresenter"/> implementation imports a
/// backreference to <see cref="VisualStudioWorkspace"/>.
/// </remarks>
private readonly Lazy<IStreamingFindUsagesPresenter> _streamingPresenter;
[ImportingConstructor]
......@@ -116,7 +120,7 @@ private static bool TryResolveSymbol(ISymbol symbol, Project project, Cancellati
return GoToDefinitionHelpers.TryGoToDefinition(
searchSymbol, searchProject,
_streamingPresenter, cancellationToken);
_streamingPresenter.Value, cancellationToken);
}
public override bool TryFindAllReferences(ISymbol symbol, Project project, CancellationToken cancellationToken)
......
......@@ -3,7 +3,6 @@
Imports System.Threading
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Editor.GoToDefinition
Imports Microsoft.CodeAnalysis.Editor.Host
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Imports Microsoft.CodeAnalysis.Test.Utilities
......@@ -42,7 +41,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.GoToDefinition
WpfTestRunner.RequireWpfFact($"{NameOf(GoToDefinitionHelpers)}.{NameOf(GoToDefinitionHelpers.TryGoToDefinition)} assumes it's on the UI thread with a {NameOf(TaskExtensions.WaitAndGetResult)} call")
Dim success = GoToDefinitionHelpers.TryGoToDefinition(
symbolInfo.Symbol, document.Project,
New Lazy(Of IStreamingFindUsagesPresenter)(Function() presenter),
presenter,
thirdPartyNavigationAllowed:=True, throwOnHiddenDefinition:=False,
cancellationToken:=CancellationToken.None)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册