未验证 提交 acf019de 编写于 作者: M msftbot[bot] 提交者: GitHub

Merge pull request #41913 from dotnet/merges/release/dev16.5-to-master

Merge release/dev16.5 to master
......@@ -2,12 +2,15 @@
// 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.Collections.Generic;
using Microsoft.CodeAnalysis.Host;
namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api
{
internal interface IUnitTestingSolutionCrawlerRegistrationServiceAccessor : IWorkspaceService
internal interface IUnitTestingSolutionCrawlerServiceAccessor : IWorkspaceService
{
void Reanalyze(Workspace workspace, IEnumerable<ProjectId> projectIds = null, IEnumerable<DocumentId> documentIds = null, bool highPriority = false);
void AddAnalyzerProvider(IUnitTestingIncrementalAnalyzerProviderImplementation provider, UnitTestingIncrementalAnalyzerProviderMetadataWrapper metadata);
}
}
// 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.Collections.Generic;
using Microsoft.CodeAnalysis.Host;
namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api
{
internal interface IUnitTestingSolutionCrawlerServiceAccessor : IWorkspaceService
{
void Reanalyze(Workspace workspace, IUnitTestingIncrementalAnalyzerImplementation analyzer, IEnumerable<ProjectId> projectIds = null, IEnumerable<DocumentId> documentIds = null, bool highPriority = false);
}
}
......@@ -12,13 +12,47 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting
{
internal sealed class UnitTestingSolutionCrawlerServiceAccessor : IUnitTestingSolutionCrawlerServiceAccessor
{
private readonly ISolutionCrawlerService _implementation;
private readonly ISolutionCrawlerRegistrationService _registrationService;
private readonly ISolutionCrawlerService _solutionCrawlerService;
private UnitTestingIncrementalAnalyzerProvider _analyzerProvider;
[Obsolete(MefConstruction.FactoryMethodMessage, error: true)]
public UnitTestingSolutionCrawlerServiceAccessor(ISolutionCrawlerService implementation)
=> _implementation = implementation;
public UnitTestingSolutionCrawlerServiceAccessor(
ISolutionCrawlerRegistrationService registrationService,
ISolutionCrawlerService solutionCrawlerService)
{
_registrationService = registrationService;
_solutionCrawlerService = solutionCrawlerService;
}
public void AddAnalyzerProvider(IUnitTestingIncrementalAnalyzerProviderImplementation provider, UnitTestingIncrementalAnalyzerProviderMetadataWrapper metadata)
{
if (_analyzerProvider != null)
{
// NOTE: We expect the analyzer to be a singleton, therefore this method should be called just once.
throw new InvalidOperationException();
}
_analyzerProvider = new UnitTestingIncrementalAnalyzerProvider(provider);
_registrationService.AddAnalyzerProvider(_analyzerProvider, metadata.UnderlyingObject);
}
// NOTE: For the Reanalyze method to work correctly, the analyzer passed into the Reanalyze method,
// must be the same as created when we call the AddAnalyzerProvider method.
// As such the analyzer provider instance caches a single instance of the analyzer.
public void Reanalyze(Workspace workspace, IEnumerable<ProjectId> projectIds = null, IEnumerable<DocumentId> documentIds = null, bool highPriority = false)
{
// NOTE: this method must be called after AddAnalyzerProvider was called previously.
if (_analyzerProvider == null)
{
throw new InvalidOperationException();
}
_solutionCrawlerService.Reanalyze(workspace, _analyzerProvider.CreateIncrementalAnalyzer(workspace), projectIds, documentIds, highPriority);
}
public void Reanalyze(Workspace workspace, IUnitTestingIncrementalAnalyzerImplementation analyzer, IEnumerable<ProjectId> projectIds = null, IEnumerable<DocumentId> documentIds = null, bool highPriority = false)
=> _implementation.Reanalyze(workspace, new UnitTestingIncrementalAnalyzer(analyzer), projectIds, documentIds, highPriority);
public void Register(Workspace workspace)
=> _registrationService.Register(workspace);
}
}
......@@ -22,8 +22,9 @@ internal sealed class UnitTestingSolutionCrawlerServiceAccessorFactory : IWorksp
[Obsolete(MefConstruction.FactoryMethodMessage, error: true)]
public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
{
var implementation = workspaceServices.GetRequiredService<ISolutionCrawlerService>();
return new UnitTestingSolutionCrawlerServiceAccessor(implementation);
var solutionCrawlerRegistrationService = workspaceServices.GetRequiredService<ISolutionCrawlerRegistrationService>();
var solutionCrawlerService = workspaceServices.GetRequiredService<ISolutionCrawlerService>();
return new UnitTestingSolutionCrawlerServiceAccessor(solutionCrawlerRegistrationService, solutionCrawlerService);
}
}
}
......@@ -6,6 +6,6 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api
{
internal interface IUnitTestingIncrementalAnalyzerProviderImplementation
{
IUnitTestingIncrementalAnalyzerImplementation CreateIncrementalAnalyzer(Workspace workspace);
IUnitTestingIncrementalAnalyzerImplementation CreateIncrementalAnalyzer();
}
}
......@@ -2,6 +2,7 @@
// 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;
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api;
using Microsoft.CodeAnalysis.SolutionCrawler;
......@@ -10,11 +11,23 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting
internal class UnitTestingIncrementalAnalyzerProvider : IIncrementalAnalyzerProvider
{
private readonly IUnitTestingIncrementalAnalyzerProviderImplementation _incrementalAnalyzerProvider;
private IIncrementalAnalyzer _analyzer;
public UnitTestingIncrementalAnalyzerProvider(IUnitTestingIncrementalAnalyzerProviderImplementation incrementalAnalyzerProvider)
=> _incrementalAnalyzerProvider = incrementalAnalyzerProvider;
public IIncrementalAnalyzer CreateIncrementalAnalyzer(Workspace workspace)
=> new UnitTestingIncrementalAnalyzer(_incrementalAnalyzerProvider.CreateIncrementalAnalyzer(workspace));
{
// NOTE: We're currently expecting the analyzer to be singleton, so that
// analyzers returned when calling this method twice would pass a reference equality check.
// One instance should be created by SolutionCrawler, another one by us, when calling the
// UnitTestingSolutionCrawlerServiceAccessor.Reanalyze method.
if (_analyzer == null)
{
_analyzer = new UnitTestingIncrementalAnalyzer(_incrementalAnalyzerProvider.CreateIncrementalAnalyzer());
}
return _analyzer;
}
}
}
// 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;
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.SolutionCrawler;
namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting
{
internal sealed class UnitTestingSolutionCrawlerRegistrationServiceAccessor
: IUnitTestingSolutionCrawlerRegistrationServiceAccessor
{
private readonly ISolutionCrawlerRegistrationService _implementation;
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public UnitTestingSolutionCrawlerRegistrationServiceAccessor(ISolutionCrawlerRegistrationService implementation)
=> _implementation = implementation;
public void AddAnalyzerProvider(IUnitTestingIncrementalAnalyzerProviderImplementation provider, UnitTestingIncrementalAnalyzerProviderMetadataWrapper metadata)
=> _implementation.AddAnalyzerProvider(new UnitTestingIncrementalAnalyzerProvider(provider), metadata.UnderlyingObject);
public void Register(Workspace workspace)
=> _implementation.Register(workspace);
}
}
// 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;
using System.Composition;
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.SolutionCrawler;
namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting
{
[ExportWorkspaceServiceFactory(typeof(IUnitTestingSolutionCrawlerRegistrationServiceAccessor))]
[Shared]
internal sealed class UnitTestingSolutionCrawlerRegistrationServiceAccessorFactory : IWorkspaceServiceFactory
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public UnitTestingSolutionCrawlerRegistrationServiceAccessorFactory() { }
[Obsolete(MefConstruction.FactoryMethodMessage, error: true)]
public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
{
var implementation = workspaceServices.GetRequiredService<ISolutionCrawlerRegistrationService>();
return new UnitTestingSolutionCrawlerRegistrationServiceAccessor(implementation);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册