diff --git a/src/Features/Core/Portable/ExternalAccess/UnitTesting/API/UnitTestingIncrementalAnalyzerProvider.cs b/src/Features/Core/Portable/ExternalAccess/UnitTesting/API/UnitTestingIncrementalAnalyzerProvider.cs deleted file mode 100644 index ddb46144c0683..0000000000000 --- a/src/Features/Core/Portable/ExternalAccess/UnitTesting/API/UnitTestingIncrementalAnalyzerProvider.cs +++ /dev/null @@ -1,58 +0,0 @@ -// 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 Microsoft.CodeAnalysis.SolutionCrawler; - -namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api -{ - internal sealed class UnitTestingIncrementalAnalyzerProvider : IIncrementalAnalyzerProvider - { - private readonly IUnitTestingIncrementalAnalyzerProviderImplementation _incrementalAnalyzerProvider; - private readonly Workspace _workspace; - - private IIncrementalAnalyzer? _lazyAnalyzer; - - internal UnitTestingIncrementalAnalyzerProvider(Workspace workspace, IUnitTestingIncrementalAnalyzerProviderImplementation incrementalAnalyzerProvider) - { - _workspace = workspace; - _incrementalAnalyzerProvider = incrementalAnalyzerProvider; - } - - // 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. - IIncrementalAnalyzer IIncrementalAnalyzerProvider.CreateIncrementalAnalyzer(Workspace workspace) - => _lazyAnalyzer ??= new UnitTestingIncrementalAnalyzer(_incrementalAnalyzerProvider.CreateIncrementalAnalyzer()); - - public void Reanalyze() - { - var solutionCrawlerService = _workspace.Services.GetService(); - if (solutionCrawlerService != null) - { - var analyzer = ((IIncrementalAnalyzerProvider)this).CreateIncrementalAnalyzer(_workspace)!; - solutionCrawlerService.Reanalyze(_workspace, analyzer, projectIds: null, documentIds: null, highPriority: false); - } - } - - public static UnitTestingIncrementalAnalyzerProvider? TryRegister(Workspace workspace, string analyzerName, IUnitTestingIncrementalAnalyzerProviderImplementation provider) - { - var solutionCrawlerRegistrationService = workspace.Services.GetService(); - if (solutionCrawlerRegistrationService == null) - { - return null; - } - - var analyzerProvider = new UnitTestingIncrementalAnalyzerProvider(workspace, provider); - - var metadata = new IncrementalAnalyzerProviderMetadata( - analyzerName, - highPriorityForActiveFile: false, - [workspace.Kind]); - - solutionCrawlerRegistrationService.AddAnalyzerProvider(analyzerProvider, metadata); - return analyzerProvider; - } - } -} diff --git a/src/Workspaces/Core/Portable/ExternalAccess/UnitTesting/Api/IUnitTestingIncrementalAnalyzerImplementation.cs b/src/Workspaces/Core/Portable/ExternalAccess/UnitTesting/Api/IUnitTestingIncrementalAnalyzerImplementation.cs deleted file mode 100644 index 9b9b23b2df17c..0000000000000 --- a/src/Workspaces/Core/Portable/ExternalAccess/UnitTesting/Api/IUnitTestingIncrementalAnalyzerImplementation.cs +++ /dev/null @@ -1,25 +0,0 @@ -// 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. - -#nullable disable - -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api -{ - internal interface IUnitTestingIncrementalAnalyzerImplementation - { - Task NewSolutionSnapshotAsync(Solution solution, CancellationToken cancellationToken); - Task DocumentOpenAsync(Document document, CancellationToken cancellationToken); - Task DocumentCloseAsync(Document document, CancellationToken cancellationToken); - Task DocumentResetAsync(Document document, CancellationToken cancellationToken); - Task AnalyzeSyntaxAsync(Document document, UnitTestingInvocationReasonsWrapper reasons, CancellationToken cancellationToken); - Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, UnitTestingInvocationReasonsWrapper reasons, CancellationToken cancellationToken); - Task AnalyzeProjectAsync(Project project, bool semanticsChanged, UnitTestingInvocationReasonsWrapper reasons, CancellationToken cancellationToken); - void RemoveDocument(DocumentId documentId); - void RemoveProject(ProjectId projectId); - } -} diff --git a/src/Workspaces/Core/Portable/ExternalAccess/UnitTesting/Api/IUnitTestingIncrementalAnalyzerProviderImplementation.cs b/src/Workspaces/Core/Portable/ExternalAccess/UnitTesting/Api/IUnitTestingIncrementalAnalyzerProviderImplementation.cs deleted file mode 100644 index 7fe5d9b9253f5..0000000000000 --- a/src/Workspaces/Core/Portable/ExternalAccess/UnitTesting/Api/IUnitTestingIncrementalAnalyzerProviderImplementation.cs +++ /dev/null @@ -1,13 +0,0 @@ -// 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. - -#nullable disable - -namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api -{ - internal interface IUnitTestingIncrementalAnalyzerProviderImplementation - { - IUnitTestingIncrementalAnalyzerImplementation CreateIncrementalAnalyzer(); - } -} diff --git a/src/Workspaces/Core/Portable/ExternalAccess/UnitTesting/Api/UnitTestingIncrementalAnalyzerProviderMetadataWrapper.cs b/src/Workspaces/Core/Portable/ExternalAccess/UnitTesting/Api/UnitTestingIncrementalAnalyzerProviderMetadataWrapper.cs deleted file mode 100644 index fff3046413add..0000000000000 --- a/src/Workspaces/Core/Portable/ExternalAccess/UnitTesting/Api/UnitTestingIncrementalAnalyzerProviderMetadataWrapper.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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.SolutionCrawler; - -namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api -{ - [Obsolete] - internal readonly struct UnitTestingIncrementalAnalyzerProviderMetadataWrapper - { - public UnitTestingIncrementalAnalyzerProviderMetadataWrapper( - string name, - bool highPriorityForActiveFile, - params string[] workspaceKinds) - => UnderlyingObject = new IncrementalAnalyzerProviderMetadata(name, highPriorityForActiveFile, workspaceKinds); - - internal UnitTestingIncrementalAnalyzerProviderMetadataWrapper(IncrementalAnalyzerProviderMetadata underlyingObject) - => UnderlyingObject = underlyingObject ?? throw new ArgumentNullException(nameof(underlyingObject)); - - internal IncrementalAnalyzerProviderMetadata UnderlyingObject { get; } - } -} diff --git a/src/Workspaces/Core/Portable/ExternalAccess/UnitTesting/Api/UnitTestingInvocationReasonsWrapper.cs b/src/Workspaces/Core/Portable/ExternalAccess/UnitTesting/Api/UnitTestingInvocationReasonsWrapper.cs deleted file mode 100644 index 74825b4f8ad1b..0000000000000 --- a/src/Workspaces/Core/Portable/ExternalAccess/UnitTesting/Api/UnitTestingInvocationReasonsWrapper.cs +++ /dev/null @@ -1,48 +0,0 @@ -// 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.SolutionCrawler; - -namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api -{ - internal readonly struct UnitTestingInvocationReasonsWrapper - { - public static readonly UnitTestingInvocationReasonsWrapper SemanticChanged = new(InvocationReasons.SemanticChanged); - public static readonly UnitTestingInvocationReasonsWrapper Reanalyze = new(InvocationReasons.Reanalyze); - public static readonly UnitTestingInvocationReasonsWrapper ProjectConfigurationChanged = new(InvocationReasons.ProjectConfigurationChanged); - public static readonly UnitTestingInvocationReasonsWrapper SyntaxChanged = new(InvocationReasons.SyntaxChanged); - public static readonly UnitTestingInvocationReasonsWrapper PredefinedDocumentAdded = new(PredefinedInvocationReasons.DocumentAdded); - public static readonly UnitTestingInvocationReasonsWrapper PredefinedReanalyze = new(PredefinedInvocationReasons.Reanalyze); - public static readonly UnitTestingInvocationReasonsWrapper PredefinedSemanticChanged = new(PredefinedInvocationReasons.SemanticChanged); - public static readonly UnitTestingInvocationReasonsWrapper PredefinedSyntaxChanged = new(PredefinedInvocationReasons.SyntaxChanged); - public static readonly UnitTestingInvocationReasonsWrapper PredefinedProjectConfigurationChanged = new(PredefinedInvocationReasons.ProjectConfigurationChanged); - public static readonly UnitTestingInvocationReasonsWrapper PredefinedDocumentOpened = new(PredefinedInvocationReasons.DocumentOpened); - public static readonly UnitTestingInvocationReasonsWrapper PredefinedDocumentClosed = new(PredefinedInvocationReasons.DocumentClosed); - public static readonly UnitTestingInvocationReasonsWrapper PredefinedDocumentRemoved = new(PredefinedInvocationReasons.DocumentRemoved); - public static readonly UnitTestingInvocationReasonsWrapper PredefinedHighPriority = new(PredefinedInvocationReasons.HighPriority); - public static readonly UnitTestingInvocationReasonsWrapper PredefinedProjectParseOptionsChanged = new(PredefinedInvocationReasons.ProjectParseOptionsChanged); - public static readonly UnitTestingInvocationReasonsWrapper PredefinedSolutionRemoved = new(PredefinedInvocationReasons.SolutionRemoved); - - internal InvocationReasons UnderlyingObject { get; } - - internal UnitTestingInvocationReasonsWrapper(InvocationReasons underlyingObject) - => UnderlyingObject = underlyingObject; - - public UnitTestingInvocationReasonsWrapper(string reason) - : this(new InvocationReasons(reason)) { } - - public UnitTestingInvocationReasonsWrapper With(UnitTestingInvocationReasonsWrapper reason) - => new(reason.UnderlyingObject.With(UnderlyingObject)); - - public bool IsReanalyze() - => UnderlyingObject.Contains(PredefinedInvocationReasons.Reanalyze); - - public bool HasSemanticChanged() - => UnderlyingObject.Contains(PredefinedInvocationReasons.SemanticChanged); - - public bool HasProjectConfigurationChanged() - => UnderlyingObject.Contains(PredefinedInvocationReasons.ProjectConfigurationChanged); - } -} diff --git a/src/Workspaces/Core/Portable/ExternalAccess/UnitTesting/UnitTestingIncrementalAnalyzer.cs b/src/Workspaces/Core/Portable/ExternalAccess/UnitTesting/UnitTestingIncrementalAnalyzer.cs deleted file mode 100644 index 554e4e40bfaf7..0000000000000 --- a/src/Workspaces/Core/Portable/ExternalAccess/UnitTesting/UnitTestingIncrementalAnalyzer.cs +++ /dev/null @@ -1,82 +0,0 @@ -// 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. - -#nullable disable - -using System.Threading; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api; -using Microsoft.CodeAnalysis.Options; -using Microsoft.CodeAnalysis.SolutionCrawler; - -namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting -{ - internal class UnitTestingIncrementalAnalyzer(IUnitTestingIncrementalAnalyzerImplementation implementation) : IIncrementalAnalyzer - { - public Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, InvocationReasons reasons, CancellationToken cancellationToken) - => implementation.AnalyzeDocumentAsync(document, bodyOpt, new UnitTestingInvocationReasonsWrapper(reasons), cancellationToken); - - public Task AnalyzeProjectAsync(Project project, bool semanticsChanged, InvocationReasons reasons, CancellationToken cancellationToken) - => implementation.AnalyzeProjectAsync(project, semanticsChanged, new UnitTestingInvocationReasonsWrapper(reasons), cancellationToken); - - public Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken) - => implementation.AnalyzeSyntaxAsync(document, new UnitTestingInvocationReasonsWrapper(reasons), cancellationToken); - - public Task DocumentCloseAsync(Document document, CancellationToken cancellationToken) - => implementation.DocumentCloseAsync(document, cancellationToken); - - public Task DocumentOpenAsync(Document document, CancellationToken cancellationToken) - => implementation.DocumentOpenAsync(document, cancellationToken); - - public Task DocumentResetAsync(Document document, CancellationToken cancellationToken) - => implementation.DocumentResetAsync(document, cancellationToken); - - public Task ActiveDocumentSwitchedAsync(TextDocument document, CancellationToken cancellationToken) - => Task.CompletedTask; - - public Task NewSolutionSnapshotAsync(Solution solution, CancellationToken cancellationToken) - => implementation.NewSolutionSnapshotAsync(solution, cancellationToken); - - public Task RemoveDocumentAsync(DocumentId documentId, CancellationToken cancellationToken) - { - implementation.RemoveDocument(documentId); - return Task.CompletedTask; - } - - public Task RemoveProjectAsync(ProjectId projectId, CancellationToken cancellationToken) - { - implementation.RemoveProject(projectId); - return Task.CompletedTask; - } - - public Task NonSourceDocumentOpenAsync(TextDocument textDocument, CancellationToken cancellationToken) - => Task.CompletedTask; - - public Task NonSourceDocumentCloseAsync(TextDocument textDocument, CancellationToken cancellationToken) - => Task.CompletedTask; - - public Task NonSourceDocumentResetAsync(TextDocument textDocument, CancellationToken cancellationToken) - => Task.CompletedTask; - - public Task AnalyzeNonSourceDocumentAsync(TextDocument textDocument, InvocationReasons reasons, CancellationToken cancellationToken) - => Task.CompletedTask; - - public void LogAnalyzerCountSummary() - { - } - - /// - /// Order all incremental analyzers below DiagnosticIncrementalAnalyzer - /// - public int Priority => 1; - - // Unit testing incremental analyzer only supports full solution analysis scope. - // In future, we should add a separate option to allow users to configure background analysis scope for unit testing. - public static BackgroundAnalysisScope GetBackgroundAnalysisScope(OptionSet _) => BackgroundAnalysisScope.FullSolution; - - public void Shutdown() - { - } - } -} diff --git a/src/Workspaces/Remote/ServiceHub/ExternalAccess/UnitTesting/Api/UnitTestingBrokeredServiceImplementation.cs b/src/Workspaces/Remote/ServiceHub/ExternalAccess/UnitTesting/Api/UnitTestingBrokeredServiceImplementation.cs index 09ebebacd587b..b9d302c83dc3e 100644 --- a/src/Workspaces/Remote/ServiceHub/ExternalAccess/UnitTesting/Api/UnitTestingBrokeredServiceImplementation.cs +++ b/src/Workspaces/Remote/ServiceHub/ExternalAccess/UnitTesting/Api/UnitTestingBrokeredServiceImplementation.cs @@ -18,19 +18,12 @@ public static ValueTask RunServiceAsync(Func implementation, CancellationToken cancellationToken) => BrokeredServiceBase.RunServiceImplAsync(implementation, cancellationToken); - public static UnitTestingIncrementalAnalyzerProvider? TryRegisterAnalyzerProvider(string analyzerName, IUnitTestingIncrementalAnalyzerProviderImplementation provider) - => UnitTestingIncrementalAnalyzerProvider.TryRegister(RemoteWorkspaceManager.Default.GetWorkspace(), analyzerName, provider); - public static NewUnitTestingIncrementalAnalyzerProvider? TryRegisterNewAnalyzerProvider(string analyzerName, INewUnitTestingIncrementalAnalyzerProviderImplementation provider) { var workspace = RemoteWorkspaceManager.Default.GetWorkspace(); return NewUnitTestingIncrementalAnalyzerProvider.TryRegister(workspace.Kind, workspace.Services.SolutionServices, analyzerName, provider); } - [Obsolete("Use RunServiceAsync (that is passsed a Solution) instead", error: false)] - public static ValueTask GetSolutionAsync(this UnitTestingPinnedSolutionInfoWrapper solutionInfo, ServiceBrokerClient client, CancellationToken cancellationToken) - => RemoteWorkspaceManager.Default.GetSolutionAsync(client, solutionInfo.UnderlyingObject, cancellationToken); - public static ValueTask RunServiceAsync(this UnitTestingPinnedSolutionInfoWrapper solutionInfo, ServiceBrokerClient client, Func> implementation, CancellationToken cancellationToken) => RemoteWorkspaceManager.Default.RunServiceAsync(client, solutionInfo.UnderlyingObject, implementation, cancellationToken); }