-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge the new UnitTesting solution crawler into Main #64368
Merged
Merged
Changes from all commits
Commits
Show all changes
199 commits
Select commit
Hold shift + click to select a range
5f6c752
Initial stubs to report solution events to OOP
CyrusNajmabadi c9bb965
In progress
CyrusNajmabadi 5f52883
in progress
CyrusNajmabadi 813dc11
in progress
CyrusNajmabadi 3375fe8
in progress
CyrusNajmabadi 5da7e9e
Make static
CyrusNajmabadi 3566e8f
In progress
CyrusNajmabadi 5def02f
Call into notification service
CyrusNajmabadi c0b1085
IN progress
CyrusNajmabadi e5e1bca
Renames
CyrusNajmabadi 77e8315
Renames
CyrusNajmabadi f358af8
remote side
CyrusNajmabadi f53250f
make workspace service
CyrusNajmabadi 97f12e8
End to end
CyrusNajmabadi f9b59c3
Formatting
CyrusNajmabadi cfc5ab6
Delete
CyrusNajmabadi 360284f
Cleanup
CyrusNajmabadi 3f11d77
nrt
CyrusNajmabadi d90eacf
Fork the solutoin crawler code to the unit testing EA lib
CyrusNajmabadi f968d3e
Fork the solutoin crawler code to the unit testing EA lib
CyrusNajmabadi bc8af14
rename
CyrusNajmabadi c97fb12
rename
CyrusNajmabadi cc3a370
rename
CyrusNajmabadi b352c80
rename
CyrusNajmabadi 06e4864
rename
CyrusNajmabadi d602909
rename
CyrusNajmabadi 712185d
rename
CyrusNajmabadi b444f8a
rename
CyrusNajmabadi d11fa92
rename
CyrusNajmabadi c93ea1f
rename
CyrusNajmabadi 90663e3
rename
CyrusNajmabadi 335cf61
rename
CyrusNajmabadi 6eba75a
rename
CyrusNajmabadi 4023c0b
rename
CyrusNajmabadi 39f7f59
rename
CyrusNajmabadi 4233f89
rename
CyrusNajmabadi cdd109c
rename
CyrusNajmabadi 6864dd5
rename
CyrusNajmabadi 4010ce1
rename
CyrusNajmabadi 0e01447
rename
CyrusNajmabadi a3e91f5
rename
CyrusNajmabadi fb0396b
rename
CyrusNajmabadi a8ea05c
rename
CyrusNajmabadi 4f31fb1
rename
CyrusNajmabadi 04a0250
rename
CyrusNajmabadi 6251dd7
rename
CyrusNajmabadi e522a3c
rename
CyrusNajmabadi 41f27db
rename
CyrusNajmabadi cfe1add
rename
CyrusNajmabadi 70c4e38
rename
CyrusNajmabadi 49f0eca
rename
CyrusNajmabadi 42e801c
rename
CyrusNajmabadi 8c78156
rename
CyrusNajmabadi bb943c2
rename
CyrusNajmabadi 70913e5
rename
CyrusNajmabadi a6634c9
rename
CyrusNajmabadi b58a658
rename
CyrusNajmabadi beaa5f4
rename
CyrusNajmabadi a31c92f
rename
CyrusNajmabadi 1483cef
rename
CyrusNajmabadi f5a0434
rename
CyrusNajmabadi 1babf76
rename
CyrusNajmabadi 96167f8
rename
CyrusNajmabadi 020b571
rename
CyrusNajmabadi 7ccc4d2
rename
CyrusNajmabadi 53ab9fe
rename
CyrusNajmabadi e1253b6
rename
CyrusNajmabadi 2152a1f
Reduce usage of Workspace in the unit testing solution crawler.
CyrusNajmabadi 2f120fb
lint
CyrusNajmabadi 7547224
Merge branch 'features/solutionEvents' into forkSolutionCrawler
CyrusNajmabadi ee87f95
Merge branch 'forkSolutionCrawler' into unitTestingRegistration
CyrusNajmabadi e8556a0
Move off of using the Workspace itself
CyrusNajmabadi d6f5895
Move off of using the Workspace itself
CyrusNajmabadi 5be3e53
Move off of using the Workspace itself
CyrusNajmabadi f64a49a
Move off of using the Workspace itself
CyrusNajmabadi af36e82
Move off of using the Workspace itself
CyrusNajmabadi b68a3e7
Move off of using the Workspace itself
CyrusNajmabadi e0b5e8a
Move off of using solution
CyrusNajmabadi 2fc71b4
Move off of using solution
CyrusNajmabadi e5d1e48
Merge pull request #64127 from CyrusNajmabadi/features/solutionEvents
CyrusNajmabadi 82ca5f5
Rename namespace
CyrusNajmabadi 85957d5
renames
CyrusNajmabadi 6979a52
renames
CyrusNajmabadi d8adbc6
renames
CyrusNajmabadi 809ccf5
renames
CyrusNajmabadi b838b94
Simplify
CyrusNajmabadi 1f1dbdb
Simplify
CyrusNajmabadi 53af1fa
Merge branch 'justWorkspaecEvents' into forkSolutionCrawler
CyrusNajmabadi f781b57
Merge branch 'forkSolutionCrawler' into unitTestingRegistration
CyrusNajmabadi 08e4a37
Rename user facing string
CyrusNajmabadi fdd201b
Merge branch 'justWorkspaecEvents' into forkSolutionCrawler
CyrusNajmabadi 9528e68
Merge branch 'forkSolutionCrawler' into unitTestingRegistration
CyrusNajmabadi 83bac9f
fix
CyrusNajmabadi cbed0d1
Merge branch 'justWorkspaecEvents' into forkSolutionCrawler
CyrusNajmabadi c0af821
Merge branch 'forkSolutionCrawler' into unitTestingRegistration
CyrusNajmabadi 8b7fd47
build
CyrusNajmabadi 3f1f4da
Remove unneeded components
CyrusNajmabadi 79abf9e
In progress
CyrusNajmabadi 7e997bb
In progress
CyrusNajmabadi be289e7
Move off of workspace
CyrusNajmabadi accbf42
Add descriptor concept
CyrusNajmabadi be121e3
Add descriptor concept
CyrusNajmabadi d919cc3
Singleton descriptors
CyrusNajmabadi 9c5f872
Merge pull request #64147 from CyrusNajmabadi/justWorkspaecEvents
CyrusNajmabadi b9593e9
Pass teh descriptor along
CyrusNajmabadi af9e4ca
Merge pull request #64149 from CyrusNajmabadi/forkSolutionCrawler
CyrusNajmabadi 3fbaa25
Stream the events into the unit testing crawler
CyrusNajmabadi 64f898e
Merge remote-tracking branch 'upstream/features/solutionEvents' into …
CyrusNajmabadi 602aff1
Lint
CyrusNajmabadi 49fd2a0
Remove workspace
CyrusNajmabadi afe0e45
use kind and services
CyrusNajmabadi 634ba80
Revert
CyrusNajmabadi 266791f
Simplify
CyrusNajmabadi ca073da
Add the new unit testing apis
CyrusNajmabadi f153377
Add the new unit testing apis
CyrusNajmabadi cfef25a
Entrypoint
CyrusNajmabadi fc8778e
make neste type
CyrusNajmabadi d688362
Merge pull request #64150 from CyrusNajmabadi/unitTestingRegistration
CyrusNajmabadi 44585c2
Remove the ILegacyWorkspaceDescriptor concept
CyrusNajmabadi d8780b4
add lock for consistency
CyrusNajmabadi b7c44e6
Merge branch 'removeDescriptor' into newUnitTestingApis
CyrusNajmabadi 63538c3
Remove
CyrusNajmabadi 4547049
Remove
CyrusNajmabadi 5284983
Merge branch 'removeDescriptor' into newUnitTestingApis
CyrusNajmabadi 5f42ced
nrt
CyrusNajmabadi af089ce
Make sealed
CyrusNajmabadi 9016b14
Merge pull request #64167 from dotnet/merges/main-to-features/solutio…
dotnet-bot 292f8c6
Merge remote-tracking branch 'upstream/main' into newUnitTestingApis
CyrusNajmabadi 3a9f2a2
Disable unused functionality
CyrusNajmabadi b87d6a5
Disable unused functionality
CyrusNajmabadi 46b5344
Disable unused functionality
CyrusNajmabadi ae0d333
Disable unused functionality
CyrusNajmabadi 1b8f7f1
Disable unused functionality
CyrusNajmabadi 8949601
Disable unused functionality
CyrusNajmabadi 6c0f7ce
Remove priority concept
CyrusNajmabadi 54237ca
Merge pull request #64161 from CyrusNajmabadi/removeDescriptor
CyrusNajmabadi e60350e
Remove tracking of open/close events
CyrusNajmabadi 9fe9015
Merge remote-tracking branch 'upstream/features/solutionEvents' into …
CyrusNajmabadi 2d9c881
Merge pull request #64206 from dotnet/merges/main-to-features/solutio…
dotnet-bot 12b3d83
Merge pull request #64235 from dotnet/merges/main-to-features/solutio…
dotnet-bot fced456
Merge pull request #64271 from dotnet/merges/main-to-features/solutio…
dotnet-bot 6439873
Merge pull request #64301 from dotnet/merges/main-to-features/solutio…
dotnet-bot c8f2807
Merge remote-tracking branch 'upstream/features/solutionEvents' into …
CyrusNajmabadi 723687b
Merge branch 'newUnitTestingApis' of https://github.com/CyrusNajmabad…
CyrusNajmabadi e68b3b3
Merge branch 'newUnitTestingApis' into diabledUnusedFunctionality
CyrusNajmabadi b2a0fdb
Merge branch 'diabledUnusedFunctionality' into openCloseFunctionality
CyrusNajmabadi 3118bdc
NRT
CyrusNajmabadi 7128364
Remove unused functiuonality
CyrusNajmabadi 2cc4c64
Merge branch 'newUnitTestingApis' into diabledUnusedFunctionality
CyrusNajmabadi 6578dc0
Disable unused functionality
CyrusNajmabadi 90ce47b
Merge branch 'diabledUnusedFunctionality' into openCloseFunctionality
CyrusNajmabadi ff09ca2
remove open/close functionality
CyrusNajmabadi 14d201d
Merge pull request #64164 from CyrusNajmabadi/newUnitTestingApis
CyrusNajmabadi 524ac0c
Merge remote-tracking branch 'upstream/features/solutionEvents' into …
CyrusNajmabadi 939e249
Disable unused functionality
CyrusNajmabadi 1542b2f
Make synchronous
CyrusNajmabadi 8b88033
Disable unused functionality
CyrusNajmabadi 94238a4
Merge branch 'diabledUnusedFunctionality' into openCloseFunctionality
CyrusNajmabadi 89840f1
proper pattern
CyrusNajmabadi bfe5bdc
Merge branch 'diabledUnusedFunctionality' into openCloseFunctionality
CyrusNajmabadi dbf0f86
Fix formatting
CyrusNajmabadi 6dc2ec5
remove nested ifdefs
CyrusNajmabadi 40ab1c9
Add distinct feature attribute for tracking unit testing solution cra…
CyrusNajmabadi 6e189ab
Merge pull request #64330 from CyrusNajmabadi/diabledUnusedFunctionality
CyrusNajmabadi 6b26230
Merge remote-tracking branch 'upstream/features/solutionEvents' into …
CyrusNajmabadi 929d4d4
Inline
CyrusNajmabadi 06bdbd3
Inline
CyrusNajmabadi d52bb31
Merge pull request #64343 from CyrusNajmabadi/featureAttribute
CyrusNajmabadi b4ce8aa
reorder
CyrusNajmabadi 3e36f10
Remove unused reason
CyrusNajmabadi a024357
Remove unused reason
CyrusNajmabadi 9084c20
Remove unused reason
CyrusNajmabadi c44b759
Remove unused reason
CyrusNajmabadi d76af57
Remove unused reason
CyrusNajmabadi 568b095
Remove unused reason
CyrusNajmabadi 2c4ad50
Merge pull request #64339 from CyrusNajmabadi/openCloseFunctionality
CyrusNajmabadi a4cc6dd
Merge pull request #64358 from dotnet/merges/main-to-features/solutio…
dotnet-bot 9071c14
Merge remote-tracking branch 'upstream/features/solutionEvents' into …
CyrusNajmabadi b34e09c
remove code related to passing along method body
CyrusNajmabadi d2db219
ifdef properly
CyrusNajmabadi d9f1626
lint
CyrusNajmabadi b389bad
Merge remote-tracking branch 'upstream/main' into features/solutionEv…
CyrusNajmabadi c53c9bf
Wait until an analyzer is registered before streaming workspace event…
CyrusNajmabadi a27dc9d
Merge pull request #64372 from CyrusNajmabadi/features/solutionEvents
CyrusNajmabadi c9db38c
Merge pull request #64367 from CyrusNajmabadi/removeReasons
CyrusNajmabadi 47e37c4
Merge remote-tracking branch 'upstream/features/solutionEvents' into …
CyrusNajmabadi 3ac7d35
Update src/Workspaces/Remote/ServiceHub/Services/LegacySolutionEvents…
CyrusNajmabadi 7bbb85e
Update src/Workspaces/Remote/ServiceHub/Services/LegacySolutionEvents…
CyrusNajmabadi 72464d8
Merge pull request #64386 from dotnet/merges/main-to-features/solutio…
dotnet-bot b372de3
Add comment
CyrusNajmabadi e98afb1
Update src/EditorFeatures/Core/SolutionEvents/HostLegacySolutionEvent…
CyrusNajmabadi 428c1de
Merge pull request #64376 from CyrusNajmabadi/waitForReady
CyrusNajmabadi 8e56089
Merge pull request #64417 from dotnet/merges/main-to-features/solutio…
dotnet-bot a5bc62c
Merge pull request #64429 from dotnet/merges/main-to-features/solutio…
dotnet-bot ef7d1cf
Merge pull request #64434 from dotnet/merges/main-to-features/solutio…
dotnet-bot 93753ed
Update to use new internal API
CyrusNajmabadi af24e70
Merge pull request #64449 from CyrusNajmabadi/mergeFixes
CyrusNajmabadi cd618ef
Merge pull request #64458 from dotnet/merges/main-to-features/solutio…
dotnet-bot 493f410
Merge pull request #64493 from dotnet/merges/main-to-features/solutio…
dotnet-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/EditorFeatures/Core/SolutionEvents/HostLegacySolutionEventsWorkspaceEventListener.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// 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 System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Collections; | ||
using Microsoft.CodeAnalysis.Editor.Shared.Utilities; | ||
using Microsoft.CodeAnalysis.Host; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
using Microsoft.CodeAnalysis.Options; | ||
using Microsoft.CodeAnalysis.Remote; | ||
using Microsoft.CodeAnalysis.Shared.TestHooks; | ||
using Microsoft.CodeAnalysis.SolutionCrawler; | ||
using Roslyn.Utilities; | ||
|
||
namespace Microsoft.CodeAnalysis.LegacySolutionEvents | ||
{ | ||
[ExportEventListener(WellKnownEventListeners.Workspace, WorkspaceKind.Host), Shared] | ||
internal sealed partial class HostLegacySolutionEventsWorkspaceEventListener : IEventListener<object> | ||
{ | ||
private readonly IGlobalOptionService _globalOptions; | ||
private readonly IThreadingContext _threadingContext; | ||
private readonly AsyncBatchingWorkQueue<WorkspaceChangeEventArgs> _eventQueue; | ||
|
||
[ImportingConstructor] | ||
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] | ||
public HostLegacySolutionEventsWorkspaceEventListener( | ||
IGlobalOptionService globalOptions, | ||
IThreadingContext threadingContext, | ||
IAsynchronousOperationListenerProvider listenerProvider) | ||
{ | ||
_globalOptions = globalOptions; | ||
_threadingContext = threadingContext; | ||
_eventQueue = new AsyncBatchingWorkQueue<WorkspaceChangeEventArgs>( | ||
DelayTimeSpan.Short, | ||
ProcessWorkspaceChangeEventsAsync, | ||
listenerProvider.GetListener(FeatureAttribute.SolutionCrawlerUnitTesting), | ||
_threadingContext.DisposalToken); | ||
} | ||
|
||
public void StartListening(Workspace workspace, object? serviceOpt) | ||
{ | ||
if (_globalOptions.GetOption(SolutionCrawlerRegistrationService.EnableSolutionCrawler)) | ||
{ | ||
workspace.WorkspaceChanged += OnWorkspaceChanged; | ||
_threadingContext.DisposalToken.Register(() => | ||
{ | ||
workspace.WorkspaceChanged -= OnWorkspaceChanged; | ||
}); | ||
} | ||
} | ||
|
||
private void OnWorkspaceChanged(object? sender, WorkspaceChangeEventArgs e) | ||
=> _eventQueue.AddWork(e); | ||
|
||
private async ValueTask ProcessWorkspaceChangeEventsAsync(ImmutableSegmentedList<WorkspaceChangeEventArgs> events, CancellationToken cancellationToken) | ||
{ | ||
if (events.IsEmpty) | ||
return; | ||
|
||
var workspace = events[0].OldSolution.Workspace; | ||
Contract.ThrowIfTrue(events.Any(e => e.OldSolution.Workspace != workspace || e.NewSolution.Workspace != workspace)); | ||
|
||
var client = await RemoteHostClient.TryGetClientAsync(workspace, cancellationToken).ConfigureAwait(false); | ||
|
||
if (client is null) | ||
{ | ||
var aggregationService = workspace.Services.GetRequiredService<ILegacySolutionEventsAggregationService>(); | ||
var shouldReport = aggregationService.ShouldReportChanges(workspace.Services.SolutionServices); | ||
if (!shouldReport) | ||
return; | ||
|
||
foreach (var args in events) | ||
await aggregationService.OnWorkspaceChangedAsync(args, cancellationToken).ConfigureAwait(false); | ||
} | ||
else | ||
{ | ||
// Notifying OOP of workspace events can be expensive (there may be a lot of them, and they involve | ||
// syncing over entire solution snapshots). As such, do not bother to do this if the remote side says | ||
// that it's not interested in the events. This will happen, for example, when the unittesting | ||
// Test-Explorer window has not been shown yet, and so the unit testing system will not have registered | ||
// an incremental analyzer with us. | ||
var shouldReport = await client.TryInvokeAsync<IRemoteLegacySolutionEventsAggregationService, bool>( | ||
(service, cancellationToken) => service.ShouldReportChangesAsync(cancellationToken), | ||
cancellationToken).ConfigureAwait(false); | ||
if (!shouldReport.HasValue || !shouldReport.Value) | ||
return; | ||
|
||
foreach (var args in events) | ||
{ | ||
await client.TryInvokeAsync<IRemoteLegacySolutionEventsAggregationService>( | ||
args.OldSolution, args.NewSolution, | ||
(service, oldSolutionChecksum, newSolutionChecksum, cancellationToken) => | ||
service.OnWorkspaceChangedAsync(oldSolutionChecksum, newSolutionChecksum, args.Kind, args.ProjectId, args.DocumentId, cancellationToken), | ||
cancellationToken).ConfigureAwait(false); | ||
} | ||
} | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...rtable/ExternalAccess/UnitTesting/API/INewUnitTestingIncrementalAnalyzerImplementation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// 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.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.SolutionCrawler; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api | ||
{ | ||
internal interface INewUnitTestingIncrementalAnalyzerImplementation | ||
{ | ||
#if false // Not used in unit testing crawling | ||
// Task NewSolutionSnapshotAsync(Solution solution, CancellationToken cancellationToken); | ||
// Task DocumentOpenAsync(Document document, CancellationToken cancellationToken); | ||
// Task DocumentCloseAsync(Document document, CancellationToken cancellationToken); | ||
// Task DocumentResetAsync(Document document, CancellationToken cancellationToken); | ||
// void RemoveProject(ProjectId projectId); | ||
|
||
// [Obsolete] | ||
// bool NeedsReanalysisOnOptionChanged(object sender, UnitTestingOptionChangedEventArgsWrapper e); | ||
|
||
Task AnalyzeSyntaxAsync(Document document, UnitTestingInvocationReasons reasons, CancellationToken cancellationToken); | ||
#endif | ||
|
||
Task AnalyzeDocumentAsync( | ||
Document document, | ||
#if false // Not used in unit testing crawling | ||
SyntaxNode bodyOpt, | ||
#endif | ||
UnitTestingInvocationReasons reasons, | ||
CancellationToken cancellationToken); | ||
|
||
Task AnalyzeProjectAsync( | ||
Project project, | ||
#if false // Not used in unit testing crawling | ||
bool semanticsChanged, | ||
#endif | ||
UnitTestingInvocationReasons reasons, | ||
CancellationToken cancellationToken); | ||
|
||
void RemoveDocument(DocumentId documentId); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...xternalAccess/UnitTesting/API/INewUnitTestingIncrementalAnalyzerProviderImplementation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// 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. | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api | ||
{ | ||
internal interface INewUnitTestingIncrementalAnalyzerProviderImplementation | ||
{ | ||
INewUnitTestingIncrementalAnalyzerImplementation CreateIncrementalAnalyzer(); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
...eatures/Core/Portable/ExternalAccess/UnitTesting/API/NewUnitTestingIncrementalAnalyzer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// 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.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api; | ||
using Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.SolutionCrawler; | ||
using Microsoft.CodeAnalysis.Options; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api; | ||
|
||
internal sealed partial class NewUnitTestingIncrementalAnalyzerProvider | ||
{ | ||
private sealed class NewUnitTestingIncrementalAnalyzer : IUnitTestingIncrementalAnalyzer | ||
{ | ||
private readonly INewUnitTestingIncrementalAnalyzerImplementation _implementation; | ||
|
||
public NewUnitTestingIncrementalAnalyzer(INewUnitTestingIncrementalAnalyzerImplementation implementation) | ||
=> _implementation = implementation; | ||
|
||
public Task AnalyzeDocumentAsync( | ||
Document document, | ||
#if false // Not used in unit testing crawling | ||
SyntaxNode bodyOpt, | ||
#endif | ||
UnitTestingInvocationReasons reasons, | ||
CancellationToken cancellationToken) | ||
{ | ||
return _implementation.AnalyzeDocumentAsync( | ||
document, | ||
#if false // Not used in unit testing crawling | ||
bodyOpt, | ||
#endif | ||
reasons, | ||
cancellationToken); | ||
} | ||
|
||
public Task AnalyzeProjectAsync( | ||
Project project, | ||
#if false // Not used in unit testing crawling | ||
bool semanticsChanged, | ||
#endif | ||
UnitTestingInvocationReasons reasons, | ||
CancellationToken cancellationToken) | ||
{ | ||
return _implementation.AnalyzeProjectAsync( | ||
project, | ||
#if false // Not used in unit testing crawling | ||
semanticsChanged, | ||
#endif | ||
reasons, | ||
cancellationToken); | ||
} | ||
|
||
#if false // Not used in unit testing crawling | ||
public Task AnalyzeSyntaxAsync(Document document, UnitTestingInvocationReasons reasons, CancellationToken cancellationToken) | ||
=> Task.CompletedTask; | ||
|
||
public Task DocumentCloseAsync(Document document, CancellationToken cancellationToken) | ||
=> Task.CompletedTask; | ||
|
||
public Task DocumentOpenAsync(Document document, CancellationToken cancellationToken) | ||
=> Task.CompletedTask; | ||
|
||
public Task DocumentResetAsync(Document document, CancellationToken cancellationToken) | ||
=> Task.CompletedTask; | ||
|
||
public Task ActiveDocumentSwitchedAsync(TextDocument document, CancellationToken cancellationToken) | ||
=> Task.CompletedTask; | ||
|
||
public Task NewSolutionSnapshotAsync(Solution solution, CancellationToken cancellationToken) | ||
=> Task.CompletedTask; | ||
#endif | ||
|
||
public Task RemoveDocumentAsync(DocumentId documentId, CancellationToken cancellationToken) | ||
{ | ||
_implementation.RemoveDocument(documentId); | ||
return Task.CompletedTask; | ||
} | ||
|
||
#if false // Not used in unit testing crawling | ||
public Task RemoveProjectAsync(ProjectId projectId, CancellationToken cancellationToken) | ||
=> 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, UnitTestingInvocationReasons reasons, CancellationToken cancellationToken) | ||
=> Task.CompletedTask; | ||
|
||
public void LogAnalyzerCountSummary() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Order all incremental analyzers below DiagnosticIncrementalAnalyzer | ||
/// </summary> | ||
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() | ||
{ | ||
} | ||
#endif | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...Core/Portable/ExternalAccess/UnitTesting/API/NewUnitTestingIncrementalAnalyzerProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// 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.ExternalAccess.UnitTesting.SolutionCrawler; | ||
using Microsoft.CodeAnalysis.Host; | ||
using Roslyn.Utilities; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTesting.Api; | ||
|
||
internal sealed partial class NewUnitTestingIncrementalAnalyzerProvider : IUnitTestingIncrementalAnalyzerProvider | ||
{ | ||
private readonly string? _workspaceKind; | ||
private readonly SolutionServices _services; | ||
private readonly INewUnitTestingIncrementalAnalyzerProviderImplementation _incrementalAnalyzerProvider; | ||
|
||
private IUnitTestingIncrementalAnalyzer? _lazyAnalyzer; | ||
|
||
private NewUnitTestingIncrementalAnalyzerProvider( | ||
string? workspaceKind, | ||
SolutionServices services, | ||
INewUnitTestingIncrementalAnalyzerProviderImplementation incrementalAnalyzerProvider) | ||
{ | ||
_workspaceKind = workspaceKind; | ||
_services = services; | ||
_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. | ||
public IUnitTestingIncrementalAnalyzer CreateIncrementalAnalyzer() | ||
=> _lazyAnalyzer ??= new NewUnitTestingIncrementalAnalyzer(_incrementalAnalyzerProvider.CreateIncrementalAnalyzer()); | ||
|
||
public void Reanalyze() | ||
{ | ||
var solutionCrawlerService = _services.GetService<IUnitTestingSolutionCrawlerService>(); | ||
solutionCrawlerService?.Reanalyze( | ||
_workspaceKind, _services, this.CreateIncrementalAnalyzer(), projectIds: null, documentIds: null, highPriority: false); | ||
} | ||
|
||
public static NewUnitTestingIncrementalAnalyzerProvider? TryRegister(string? workspaceKind, SolutionServices services, string analyzerName, INewUnitTestingIncrementalAnalyzerProviderImplementation provider) | ||
{ | ||
Contract.ThrowIfNull(workspaceKind); | ||
var solutionCrawlerRegistrationService = services.GetService<IUnitTestingSolutionCrawlerRegistrationService>(); | ||
if (solutionCrawlerRegistrationService == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var analyzerProvider = new NewUnitTestingIncrementalAnalyzerProvider(workspaceKind, services, provider); | ||
|
||
var metadata = new UnitTestingIncrementalAnalyzerProviderMetadata( | ||
analyzerName, | ||
#if false // Not used in unit testing crawling | ||
highPriorityForActiveFile: false, | ||
#endif | ||
new[] { workspaceKind }); | ||
|
||
solutionCrawlerRegistrationService.AddAnalyzerProvider(analyzerProvider, metadata); | ||
return analyzerProvider; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why keep this?