提交 77c68b37 编写于 作者: S Sam Harwell

improving performance on running completion tests (#33817)

Cherry picked from commit aa2db962
上级 fd501c70
......@@ -33,9 +33,8 @@ internal abstract class AbstractCommandHandlerTestState : IDisposable
XElement workspaceElement,
IList<Type> excludedTypes = null,
ComposableCatalog extraParts = null,
bool useMinimumCatalog = false,
string workspaceKind = null)
: this(workspaceElement, GetExportProvider(useMinimumCatalog, excludedTypes, extraParts), workspaceKind)
: this(workspaceElement, GetExportProvider(excludedTypes, extraParts), workspaceKind)
{
}
......@@ -131,20 +130,16 @@ public T GetService<T>()
return Workspace.GetService<T>();
}
private static ExportProvider GetExportProvider(bool useMinimumCatalog, IList<Type> excludedTypes, ComposableCatalog extraParts)
internal static ExportProvider GetExportProvider(IList<Type> excludedTypes, ComposableCatalog extraParts)
{
excludedTypes = excludedTypes ?? Type.EmptyTypes;
if (excludedTypes.Count == 0 && (extraParts == null || extraParts.Parts.Count == 0))
{
return useMinimumCatalog
? TestExportProvider.MinimumExportProviderFactoryWithCSharpAndVisualBasic.CreateExportProvider()
: TestExportProvider.ExportProviderFactoryWithCSharpAndVisualBasic.CreateExportProvider();
return TestExportProvider.ExportProviderFactoryWithCSharpAndVisualBasic.CreateExportProvider();
}
var baseCatalog = useMinimumCatalog
? TestExportProvider.MinimumCatalogWithCSharpAndVisualBasic
: TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic;
var baseCatalog = TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic;
var filteredCatalog = baseCatalog.WithoutPartsOfTypes(excludedTypes);
......
......@@ -116,11 +116,6 @@ private static Type[] GetNeutralAndCSharpAndVisualBasicTypes()
.ToArray();
}
private static IExportProviderFactory CreateExportProviderFactoryWithCSharpAndVisualBasic()
{
return ExportProviderCache.GetOrCreateExportProviderFactory(EntireAssemblyCatalogWithCSharpAndVisualBasic);
}
private static ComposableCatalog CreateAssemblyCatalogWithCSharpAndVisualBasic()
{
return ExportProviderCache
......
......@@ -13,6 +13,7 @@ Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Imports Microsoft.CodeAnalysis.SignatureHelp
Imports Microsoft.CodeAnalysis.Test.Utilities
Imports Microsoft.VisualStudio.Commanding
Imports Microsoft.VisualStudio.Composition
Imports Microsoft.VisualStudio.Language.Intellisense
Imports Microsoft.VisualStudio.Text
Imports Microsoft.VisualStudio.Text.Editor
......@@ -35,6 +36,36 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense
Friend ReadOnly IntelliSenseCommandHandler As IntelliSenseCommandHandler
Private ReadOnly SessionTestState As IIntelliSenseTestState
Private Shared s_lazyEntireAssemblyCatalogWithCSharpAndVisualBasicWithoutCompletionTestParts As Lazy(Of ComposableCatalog) =
New Lazy(Of ComposableCatalog)(Function()
Return TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.
WithoutPartsOfTypes({
GetType(IIntelliSensePresenter(Of ICompletionPresenterSession, ICompletionSession)),
GetType(IIntelliSensePresenter(Of ISignatureHelpPresenterSession, ISignatureHelpSession)),
GetType(FormatCommandHandler)}).
WithParts({
GetType(TestCompletionPresenter),
GetType(TestSignatureHelpPresenter),
GetType(IntelliSenseTestState)})
End Function)
Private Shared ReadOnly Property EntireAssemblyCatalogWithCSharpAndVisualBasicWithoutCompletionTestParts As ComposableCatalog
Get
Return s_lazyEntireAssemblyCatalogWithCSharpAndVisualBasicWithoutCompletionTestParts.Value
End Get
End Property
Private Shared s_lazyExportProviderFactoryWithCSharpAndVisualBasicWithoutCompletionTestParts As Lazy(Of IExportProviderFactory) =
New Lazy(Of IExportProviderFactory)(Function()
Return ExportProviderCache.GetOrCreateExportProviderFactory(EntireAssemblyCatalogWithCSharpAndVisualBasicWithoutCompletionTestParts)
End Function)
Private Shared ReadOnly Property ExportProviderFactoryWithCSharpAndVisualBasicWithoutCompletionTestParts As IExportProviderFactory
Get
Return s_lazyExportProviderFactoryWithCSharpAndVisualBasicWithoutCompletionTestParts.Value
End Get
End Property
Friend ReadOnly Property CurrentSignatureHelpPresenterSession As TestSignatureHelpPresenterSession
Get
Return SessionTestState.CurrentSignatureHelpPresenterSession
......@@ -53,7 +84,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense
Optional extraExportedTypes As List(Of Type) = Nothing,
Optional includeFormatCommandHandler As Boolean = False,
Optional workspaceKind As String = Nothing)
MyBase.New(workspaceElement, CombineExcludedTypes(excludedTypes, includeFormatCommandHandler), ExportProviderCache.CreateTypeCatalog(CombineExtraTypes(If(extraExportedTypes, New List(Of Type)))), workspaceKind:=workspaceKind)
MyBase.New(workspaceElement, GetExportProvider(excludedTypes, extraExportedTypes, includeFormatCommandHandler), workspaceKind:=workspaceKind)
Dim languageServices = Me.Workspace.CurrentSolution.Projects.First().LanguageServices
Dim language = languageServices.Language
......@@ -84,6 +115,20 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense
Nothing)
End Sub
Private Overloads Shared Function GetExportProvider(excludedTypes As List(Of Type),
extraExportedTypes As List(Of Type),
includeFormatCommandHandler As Boolean) As ExportProvider
If (excludedTypes Is Nothing OrElse excludedTypes.Count = 0) AndAlso
(extraExportedTypes Is Nothing OrElse extraExportedTypes.Count = 0) AndAlso
Not includeFormatCommandHandler Then
Return ExportProviderFactoryWithCSharpAndVisualBasicWithoutCompletionTestParts.CreateExportProvider()
End If
Dim combinedExcludedTypes = CombineExcludedTypes(excludedTypes, includeFormatCommandHandler)
Dim extraParts = ExportProviderCache.CreateTypeCatalog(CombineExtraTypes(If(extraExportedTypes, New List(Of Type))))
Return GetExportProvider(combinedExcludedTypes, extraParts)
End Function
Private Shared Function CombineExcludedTypes(excludedTypes As IList(Of Type), includeFormatCommandHandler As Boolean) As IList(Of Type)
Dim result = New List(Of Type) From {
GetType(IIntelliSensePresenter(Of ICompletionPresenterSession, ICompletionSession)),
......
......@@ -23,7 +23,7 @@ internal sealed class EventHookupTestState : AbstractCommandHandlerTestState
private Mutex _testSessionHookupMutex;
public EventHookupTestState(XElement workspaceElement, IDictionary<OptionKey, object> options)
: base(workspaceElement, excludedTypes: null, GetExtraParts(), false)
: base(workspaceElement, excludedTypes: null, GetExtraParts())
{
_commandHandler = new EventHookupCommandHandler(
Workspace.ExportProvider.GetExportedValue<IThreadingContext>(),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册