提交 36ebc7f7 编写于 作者: A Artur Spychaj

Make use of InvocationReason in tests and analyzers

上级 52d00a2f
......@@ -176,7 +176,7 @@ private static async Task TestAsync(string codeWithMarker)
var document = workspace.Documents.First();
var documentId = document.Id;
var reasons = new InvocationReasons(PredefinedInvocationReasons.DocumentAdded);
await worker.AnalyzeSyntaxAsync(workspace.CurrentSolution.GetDocument(documentId), CancellationToken.None);
await worker.AnalyzeSyntaxAsync(workspace.CurrentSolution.GetDocument(documentId), InvocationReasons.Empty, CancellationToken.None);
var todoLists = worker.GetItems_TestingOnly(documentId);
var expectedLists = document.SelectedSpans;
......
......@@ -6,6 +6,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.SolutionCrawler;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
......@@ -31,9 +32,9 @@ public async Task TestHasSuccessfullyLoadedBeingFalse()
service.DiagnosticsUpdated += (s, a) => Assert.Empty(a.Diagnostics);
// now call each analyze method. none of them should run.
await analyzer.AnalyzeSyntaxAsync(document, CancellationToken.None).ConfigureAwait(false);
await analyzer.AnalyzeDocumentAsync(document, bodyOpt: null, cancellationToken: CancellationToken.None).ConfigureAwait(false);
await analyzer.AnalyzeProjectAsync(document.Project, semanticsChanged: true, cancellationToken: CancellationToken.None).ConfigureAwait(false);
await analyzer.AnalyzeSyntaxAsync(document, InvocationReasons.Empty, CancellationToken.None).ConfigureAwait(false);
await analyzer.AnalyzeDocumentAsync(document, bodyOpt: null, reasons: InvocationReasons.Empty, cancellationToken: CancellationToken.None).ConfigureAwait(false);
await analyzer.AnalyzeProjectAsync(document.Project, semanticsChanged: true, reasons: InvocationReasons.Empty, cancellationToken: CancellationToken.None).ConfigureAwait(false);
// wait for all events to raised
await listener.CreateWaitTask().ConfigureAwait(false);
......@@ -74,9 +75,9 @@ public async Task TestHasSuccessfullyLoadedBeingFalseWhenFileOpened()
};
// now call each analyze method. none of them should run.
await analyzer.AnalyzeSyntaxAsync(document, CancellationToken.None).ConfigureAwait(false);
await analyzer.AnalyzeDocumentAsync(document, bodyOpt: null, cancellationToken: CancellationToken.None).ConfigureAwait(false);
await analyzer.AnalyzeProjectAsync(document.Project, semanticsChanged: true, cancellationToken: CancellationToken.None).ConfigureAwait(false);
await analyzer.AnalyzeSyntaxAsync(document, InvocationReasons.Empty, CancellationToken.None).ConfigureAwait(false);
await analyzer.AnalyzeDocumentAsync(document, bodyOpt: null, reasons: InvocationReasons.Empty, cancellationToken: CancellationToken.None).ConfigureAwait(false);
await analyzer.AnalyzeProjectAsync(document.Project, semanticsChanged: true, reasons: InvocationReasons.Empty, cancellationToken: CancellationToken.None).ConfigureAwait(false);
// wait for all events to raised
await listener.CreateWaitTask().ConfigureAwait(false);
......
......@@ -1039,13 +1039,13 @@ public Analyzer(bool waitForCancellation = false, bool blockedRun = false)
this.RunningEvent = new ManualResetEventSlim(initialState: false);
}
public Task AnalyzeProjectAsync(Project project, bool semanticsChanged, CancellationToken cancellationToken)
public Task AnalyzeProjectAsync(Project project, bool semanticsChanged, InvocationReasons reasons, CancellationToken cancellationToken)
{
this.ProjectIds.Add(project.Id);
return SpecializedTasks.EmptyTask;
}
public Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, CancellationToken cancellationToken)
public Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, InvocationReasons reasons, CancellationToken cancellationToken)
{
if (bodyOpt == null)
{
......@@ -1055,7 +1055,7 @@ public Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, Cancella
return SpecializedTasks.EmptyTask;
}
public Task AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
public Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken)
{
this.SyntaxDocumentIds.Add(document.Id);
Process(document.Id, cancellationToken);
......
......@@ -11,6 +11,7 @@ Imports Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Imports Microsoft.CodeAnalysis.Options
Imports Microsoft.CodeAnalysis.Shared.Options
Imports Microsoft.CodeAnalysis.SolutionCrawler
Imports Microsoft.CodeAnalysis.Test.Utilities
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.UnitTests.Diagnostics
......@@ -1937,7 +1938,7 @@ class MyClass
Assert.Equal(HiddenDiagnosticsCompilationAnalyzer.Descriptor.Id, descriptors.Single().Id)
' Force project analysis
incrementalAnalyzer.AnalyzeProjectAsync(project, semanticsChanged:=True, cancellationToken:=CancellationToken.None).Wait()
incrementalAnalyzer.AnalyzeProjectAsync(project, semanticsChanged:=True, reasons:=InvocationReasons.Empty, cancellationToken:=CancellationToken.None).Wait()
' Get cached project diagnostics.
Dim diagnostics = diagnosticService.GetCachedDiagnosticsAsync(workspace, project.Id).WaitAndGetResult(CancellationToken.None)
......
......@@ -185,7 +185,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.TodoComment
Dim document = workspace.Documents.First()
Dim documentId = document.Id
Await worker.AnalyzeSyntaxAsync(workspace.CurrentSolution.GetDocument(documentId), CancellationToken.None)
Await worker.AnalyzeSyntaxAsync(workspace.CurrentSolution.GetDocument(documentId), InvocationReasons.Empty, CancellationToken.None)
Dim todoLists = worker.GetItems_TestingOnly(documentId)
......
......@@ -587,12 +587,9 @@
<Compile Include="SolutionCrawler\IncrementalAnalyzerBase.cs" />
<Compile Include="SolutionCrawler\IncrementalAnalyzerProviderBase.cs" />
<Compile Include="SolutionCrawler\InternalSolutionCrawlerOptionsProvider.cs" />
<Compile Include="SolutionCrawler\InvocationReasons.cs" />
<Compile Include="SolutionCrawler\InvocationReasons_Constants.cs" />
<Compile Include="SolutionCrawler\ISolutionCrawlerProgressReporter.cs" />
<Compile Include="SolutionCrawler\ISolutionCrawlerService.cs" />
<Compile Include="SolutionCrawler\IWorkCoordinatorPriorityService.cs" />
<Compile Include="SolutionCrawler\PredefinedInvocationReasons.cs" />
<Compile Include="SolutionCrawler\SolutionCrawlerLogger.cs" />
<Compile Include="SolutionCrawler\InternalSolutionCrawlerOptions.cs" />
<Compile Include="SolutionCrawler\SolutionCrawlerProgressReporter.cs" />
......
......@@ -531,7 +531,7 @@ private async Task ResetStatesAsync()
_currentSnapshotVersionTrackingSet.Clear();
_processingSolution = currentSolution;
await RunAnalyzersAsync(this.Analyzers, currentSolution, (a, s, c) => a.NewSolutionSnapshotAsync(s, c), this.CancellationToken).ConfigureAwait(false);
foreach (var id in this.Processor.GetOpenDocumentIds())
......
......@@ -103,9 +103,8 @@
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\..\Features\Core\Portable\Features.csproj">
<Project>{EDC68A0E-C68D-4A74-91B7-BF38EC909888}</Project>
<Project>{edc68a0e-c68d-4a74-91b7-bf38ec909888}</Project>
<Name>Features</Name>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
......
......@@ -3,6 +3,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.SolutionCrawler;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServices.Implementation.SolutionSize;
using Xunit;
......@@ -46,7 +47,7 @@ public async Task Test_SolutionSize_Update()
var text = SourceText.From(new string('2', 1000));
var newDocument = document.WithText(text);
await analyzer.AnalyzeSyntaxAsync(newDocument, CancellationToken.None);
await analyzer.AnalyzeSyntaxAsync(newDocument, InvocationReasons.DocumentChanged, CancellationToken.None);
var size = analyzer.GetSolutionSize(solution.Id);
Assert.Equal(expected - length + text.Length, size);
......@@ -78,7 +79,7 @@ private static async Task AddSolutionAsync(SolutionSizeTracker.IncrementalAnalyz
{
foreach (var document in solution.Projects.SelectMany(p => p.Documents))
{
await analyzer.AnalyzeSyntaxAsync(document, CancellationToken.None);
await analyzer.AnalyzeSyntaxAsync(document, InvocationReasons.Empty, CancellationToken.None);
}
}
......
// 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.Concurrent;
using System.Composition;
using System.Threading;
......
......@@ -55,7 +55,7 @@ public Analyzer(IForegroundNotificationService notificationService, IAsynchronou
_workspace = workspace;
}
public Task AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
public Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken)
{
FireEvents(document.Id, cancellationToken);
......@@ -124,12 +124,12 @@ public bool NeedsReanalysisOnOptionChanged(object sender, OptionChangedEventArgs
return false;
}
public Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, CancellationToken cancellationToken)
public Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, InvocationReasons reasons, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyTask;
}
public Task AnalyzeProjectAsync(Project project, bool semanticsChanged, CancellationToken cancellationToken)
public Task AnalyzeProjectAsync(Project project, bool semanticsChanged, InvocationReasons reasons, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyTask;
}
......
......@@ -11,6 +11,7 @@ Imports Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Imports Microsoft.CodeAnalysis.Options
Imports Microsoft.CodeAnalysis.Shared.TestHooks
Imports Microsoft.CodeAnalysis.SolutionCrawler
Imports Microsoft.CodeAnalysis.Text.Shared.Extensions
Imports Microsoft.VisualStudio.LanguageServices.Implementation.Diagnostics
Imports Microsoft.VisualStudio.Text.Tagging
......@@ -47,7 +48,7 @@ class 123 { }
Dim tagger = provider.CreateTagger(Of IErrorTag)(buffer)
Using disposable = TryCast(tagger, IDisposable)
Dim analyzer = miscService.CreateIncrementalAnalyzer(workspace)
Await analyzer.AnalyzeSyntaxAsync(workspace.CurrentSolution.Projects.First().Documents.First(), CancellationToken.None)
Await analyzer.AnalyzeSyntaxAsync(workspace.CurrentSolution.Projects.First().Documents.First(), InvocationReasons.Empty, CancellationToken.None)
Await listener.CreateWaitTask()
......@@ -87,8 +88,8 @@ class A
Dim document = workspace.CurrentSolution.Projects.First().Documents.First()
Dim analyzer = miscService.CreateIncrementalAnalyzer(workspace)
Await analyzer.AnalyzeSyntaxAsync(document, CancellationToken.None)
Await analyzer.AnalyzeDocumentAsync(document, Nothing, CancellationToken.None)
Await analyzer.AnalyzeSyntaxAsync(document, InvocationReasons.Empty, CancellationToken.None)
Await analyzer.AnalyzeDocumentAsync(document, Nothing, InvocationReasons.Empty, CancellationToken.None)
Await listener.CreateWaitTask()
......@@ -124,8 +125,8 @@ class A
Dim document = workspace.CurrentSolution.Projects.First().Documents.First()
Dim analyzer = miscService.CreateIncrementalAnalyzer(workspace)
Await analyzer.AnalyzeSyntaxAsync(document, CancellationToken.None)
Await analyzer.AnalyzeDocumentAsync(document, Nothing, CancellationToken.None)
Await analyzer.AnalyzeSyntaxAsync(document, InvocationReasons.Empty, CancellationToken.None)
Await analyzer.AnalyzeDocumentAsync(document, Nothing, InvocationReasons.Empty, CancellationToken.None)
Await listener.CreateWaitTask()
......@@ -161,8 +162,8 @@ class A
Dim document = workspace.CurrentSolution.Projects.First().Documents.First()
Dim analyzer = miscService.CreateIncrementalAnalyzer(workspace)
Await analyzer.AnalyzeSyntaxAsync(document, CancellationToken.None)
Await analyzer.AnalyzeDocumentAsync(document, Nothing, CancellationToken.None)
Await analyzer.AnalyzeSyntaxAsync(document, InvocationReasons.Empty, CancellationToken.None)
Await analyzer.AnalyzeDocumentAsync(document, Nothing, InvocationReasons.Empty, CancellationToken.None)
Await listener.CreateWaitTask()
......@@ -198,8 +199,8 @@ class A
Dim document = workspace.CurrentSolution.Projects.First().Documents.First()
Dim analyzer = miscService.CreateIncrementalAnalyzer(workspace)
Await analyzer.AnalyzeSyntaxAsync(document, CancellationToken.None)
Await analyzer.AnalyzeDocumentAsync(document, Nothing, CancellationToken.None)
Await analyzer.AnalyzeSyntaxAsync(document, InvocationReasons.Empty, CancellationToken.None)
Await analyzer.AnalyzeDocumentAsync(document, Nothing, InvocationReasons.Empty, CancellationToken.None)
analyzer.RemoveDocument(document.Id)
Await listener.CreateWaitTask()
......@@ -227,7 +228,7 @@ class 123 { }
End Sub
Dim analyzer = miscService.CreateIncrementalAnalyzer(workspace)
Await analyzer.AnalyzeSyntaxAsync(workspace.CurrentSolution.Projects.First().Documents.First(), CancellationToken.None)
Await analyzer.AnalyzeSyntaxAsync(workspace.CurrentSolution.Projects.First().Documents.First(), InvocationReasons.Empty, CancellationToken.None)
Assert.Equal(PredefinedBuildTools.Live, buildTool)
End Using
......@@ -252,7 +253,7 @@ End Class
End Sub
Dim analyzer = miscService.CreateIncrementalAnalyzer(workspace)
Await analyzer.AnalyzeSyntaxAsync(workspace.CurrentSolution.Projects.First().Documents.First(), CancellationToken.None)
Await analyzer.AnalyzeSyntaxAsync(workspace.CurrentSolution.Projects.First().Documents.First(), InvocationReasons.Empty, CancellationToken.None)
Assert.Equal(PredefinedBuildTools.Live, buildTool)
End Using
......
......@@ -350,6 +350,8 @@
<Compile Include="SolutionCrawler\IIncrementalAnalyzer.cs" />
<Compile Include="SolutionCrawler\IIncrementalAnalyzerProvider.cs" />
<Compile Include="SolutionCrawler\IncrementalAnalyzerProviderMetadata.cs" />
<Compile Include="SolutionCrawler\InvocationReasons.cs" />
<Compile Include="SolutionCrawler\InvocationReasons_Constants.cs" />
<Compile Include="SolutionCrawler\ISolutionCrawlerRegistrationService.cs" />
<Compile Include="Diagnostics\IWorkspaceVenusSpanMappingService.cs" />
<Compile Include="Diagnostics\WellKnownDiagnosticPropertyNames.cs" />
......@@ -414,6 +416,7 @@
<Compile Include="Options\DocumentOptionSet.cs" />
<Compile Include="Options\OptionSet.cs" />
<Compile Include="Packaging\IPackageInstallerService.cs" />
<Compile Include="SolutionCrawler\PredefinedInvocationReasons.cs" />
<Compile Include="SymbolSearch\ISymbolSearchService.cs" />
<Compile Include="FindSymbols\SymbolTree\ISymbolTreeInfoCacheService.cs" />
<Compile Include="FindSymbols\FindReferences\MetadataUnifyingEquivalenceComparer.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册