提交 602156e9 编写于 作者: A Artur Spychaj

Merge pull request #11353 from drognanar/reasonstofuture

Include invocation reasons when analyzing documents by solution crawler
......@@ -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;
......
......@@ -42,7 +42,7 @@ public Task DocumentResetAsync(Document document, CancellationToken cancellation
return _state.PersistAsync(document, new Data(VersionStamp.Default, VersionStamp.Default, ImmutableArray<TodoItem>.Empty), cancellationToken);
}
public async Task AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
public async Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken)
{
// it has an assumption that this will not be called concurrently for same document.
// in fact, in current design, it won't be even called concurrently for different documents.
......@@ -220,12 +220,12 @@ public Task DocumentCloseAsync(Document document, CancellationToken cancellation
return SpecializedTasks.EmptyTask;
}
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;
}
......
......@@ -49,8 +49,8 @@ public async void Register(Workspace workspace)
await Task.Delay(workerBackOffTimeSpanInMS).ConfigureAwait(false);
// do actual analysis
await analyzer.AnalyzeSyntaxAsync(document, source.Token).ConfigureAwait(false);
await analyzer.AnalyzeDocumentAsync(document, bodyOpt: null, cancellationToken: source.Token).ConfigureAwait(false);
await analyzer.AnalyzeSyntaxAsync(document, InvocationReasons.Empty, source.Token).ConfigureAwait(false);
await analyzer.AnalyzeDocumentAsync(document, bodyOpt: null, reasons: InvocationReasons.Empty, cancellationToken: source.Token).ConfigureAwait(false);
// don't call project one.
}
......
......@@ -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)
......
......@@ -35,9 +35,10 @@ protected BaseDiagnosticIncrementalAnalyzer(DiagnosticAnalyzerService owner, Wor
/// </summary>
/// <param name="document">The document to analyze.</param>
/// <param name="bodyOpt">If present, indicates a portion (e.g. a method body) of the document to analyze.</param>
/// <param name="reasons">The reason(s) this analysis was triggered.</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public abstract Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, CancellationToken cancellationToken);
public abstract Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, InvocationReasons reasons, CancellationToken cancellationToken);
/// <summary>
/// Analyze a single project such that diagnostics for the entire project become available.
/// Calls <see cref="DiagnosticAnalyzerService.RaiseDiagnosticsUpdated(DiagnosticsUpdatedArgs)"/> for each
......@@ -45,18 +46,20 @@ protected BaseDiagnosticIncrementalAnalyzer(DiagnosticAnalyzerService owner, Wor
/// </summary>
/// <param name="project">The project to analyze.</param>
/// <param name="semanticsChanged">Indicates a change to the declarative semantics of the project.</param>
/// <param name="reasons">The reason(s) this analysis was triggered.</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public abstract Task AnalyzeProjectAsync(Project project, bool semanticsChanged, CancellationToken cancellationToken);
public abstract Task AnalyzeProjectAsync(Project project, bool semanticsChanged, InvocationReasons reasons, CancellationToken cancellationToken);
/// <summary>
/// Apply syntax tree actions (that have not already been applied) to a document.
/// Calls <see cref="DiagnosticAnalyzerService.RaiseDiagnosticsUpdated(DiagnosticsUpdatedArgs)"/> for each
/// unique group of diagnostics, where a group is identified by analysis classification (syntax), document, and analyzer.
/// </summary>
/// <param name="document">The document to analyze.</param>
/// <param name="reasons">The reason(s) this analysis was triggered.</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public abstract Task AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken);
public abstract Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken);
/// <summary>
/// Respond to a document being opened for editing in the host.
/// </summary>
......
......@@ -82,7 +82,7 @@ public bool NeedsReanalysisOnOptionChanged(object sender, OptionChangedEventArgs
return false;
}
public async Task AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
public async Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken)
{
// right now, there is no way to observe diagnostics for closed file.
if (!_workspace.IsDocumentOpen(document.Id) ||
......@@ -103,7 +103,7 @@ public async Task AnalyzeSyntaxAsync(Document document, CancellationToken cancel
_workspace, document.Project.Solution, document.Project.Id, document.Id, diagnosticData));
}
public async Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, CancellationToken cancellationToken)
public async Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, InvocationReasons reasons, CancellationToken cancellationToken)
{
// right now, there is no way to observe diagnostics for closed file.
if (!_workspace.IsDocumentOpen(document.Id) ||
......@@ -150,7 +150,7 @@ private void RaiseEmptyDiagnosticUpdated(int kind, DocumentId documentId)
new DefaultUpdateArgsId(_workspace.Kind, kind, documentId), _workspace, null, documentId.ProjectId, documentId));
}
public Task AnalyzeProjectAsync(Project project, bool semanticsChanged, CancellationToken cancellationToken)
public Task AnalyzeProjectAsync(Project project, bool semanticsChanged, InvocationReasons reasons, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyTask;
}
......
......@@ -76,19 +76,19 @@ public IncrementalAnalyzerDelegatee(DiagnosticAnalyzerService owner, Workspace w
}
#region IIncrementalAnalyzer
public override Task AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
public override Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken)
{
return Analyzer.AnalyzeSyntaxAsync(document, cancellationToken);
return Analyzer.AnalyzeSyntaxAsync(document, reasons, cancellationToken);
}
public override Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, CancellationToken cancellationToken)
public override Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, InvocationReasons reasons, CancellationToken cancellationToken)
{
return Analyzer.AnalyzeDocumentAsync(document, bodyOpt, cancellationToken);
return Analyzer.AnalyzeDocumentAsync(document, bodyOpt, reasons, cancellationToken);
}
public override Task AnalyzeProjectAsync(Project project, bool semanticsChanged, CancellationToken cancellationToken)
public override Task AnalyzeProjectAsync(Project project, bool semanticsChanged, InvocationReasons reasons, CancellationToken cancellationToken)
{
return Analyzer.AnalyzeProjectAsync(project, semanticsChanged, cancellationToken);
return Analyzer.AnalyzeProjectAsync(project, semanticsChanged, reasons, cancellationToken);
}
public override Task DocumentOpenAsync(Document document, CancellationToken cancellationToken)
......
......@@ -13,6 +13,7 @@
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Options;
using Microsoft.CodeAnalysis.SolutionCrawler;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Versions;
using Roslyn.Utilities;
......@@ -198,7 +199,7 @@ private bool CheckOptions(Project project, bool forceAnalysis)
return new CompilationWithAnalyzers(compilation, filteredAnalyzers, analysisOptions);
}
public override async Task AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
public override async Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken)
{
await AnalyzeSyntaxAsync(document, diagnosticIds: null, cancellationToken: cancellationToken).ConfigureAwait(false);
}
......@@ -257,7 +258,7 @@ private async Task AnalyzeSyntaxAsync(Document document, ImmutableHashSet<string
}
}
public override async Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, CancellationToken cancellationToken)
public override async Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, InvocationReasons reasons, CancellationToken cancellationToken)
{
await AnalyzeDocumentAsync(document, bodyOpt, diagnosticIds: null, cancellationToken: cancellationToken).ConfigureAwait(false);
}
......@@ -398,7 +399,7 @@ private async Task AnalyzeDocumentAsync(Document document, VersionArgument versi
}
}
public override async Task AnalyzeProjectAsync(Project project, bool semanticsChanged, CancellationToken cancellationToken)
public override async Task AnalyzeProjectAsync(Project project, bool semanticsChanged, InvocationReasons reasons, CancellationToken cancellationToken)
{
await AnalyzeProjectAsync(project, cancellationToken).ConfigureAwait(false);
}
......
......@@ -10,6 +10,7 @@
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Options;
using Microsoft.CodeAnalysis.SolutionCrawler;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Diagnostics.EngineV2
......@@ -17,12 +18,12 @@ namespace Microsoft.CodeAnalysis.Diagnostics.EngineV2
// TODO: make it to use cache
internal partial class DiagnosticIncrementalAnalyzer : BaseDiagnosticIncrementalAnalyzer
{
public override Task AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
public override Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken)
{
return AnalyzeDocumentForKindAsync(document, AnalysisKind.Syntax, cancellationToken);
}
public override Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, CancellationToken cancellationToken)
public override Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, InvocationReasons reasons, CancellationToken cancellationToken)
{
return AnalyzeDocumentForKindAsync(document, AnalysisKind.Semantic, cancellationToken);
}
......@@ -65,7 +66,7 @@ private async Task AnalyzeDocumentForKindAsync(Document document, AnalysisKind k
}
}
public override async Task AnalyzeProjectAsync(Project project, bool semanticsChanged, CancellationToken cancellationToken)
public override async Task AnalyzeProjectAsync(Project project, bool semanticsChanged, InvocationReasons reasons, CancellationToken cancellationToken)
{
try
{
......
......@@ -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" />
......
......@@ -190,7 +190,7 @@ private class IncrementalAnalyzer : IncrementalAnalyzerBase
_metadataPathToInfo = metadataPathToInfo;
}
public override Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, CancellationToken cancellationToken)
public override Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, InvocationReasons reasons, CancellationToken cancellationToken)
{
if (!document.SupportsSyntaxTree)
{
......@@ -208,7 +208,7 @@ public override Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt,
return UpdateSymbolTreeInfoAsync(document.Project, cancellationToken);
}
public override Task AnalyzeProjectAsync(Project project, bool semanticsChanged, CancellationToken cancellationToken)
public override Task AnalyzeProjectAsync(Project project, bool semanticsChanged, InvocationReasons reasons, CancellationToken cancellationToken)
{
return UpdateSymbolTreeInfoAsync(project, cancellationToken);
}
......
......@@ -18,7 +18,7 @@ public IIncrementalAnalyzer CreateIncrementalAnalyzer(Workspace workspace)
private class IncrementalAnalyzer : IncrementalAnalyzerBase
{
public override Task AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
public override Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken)
{
return SyntaxTreeInfo.PrecalculateAsync(document, cancellationToken);
}
......
......@@ -72,7 +72,7 @@ public bool NeedsReanalysisOnOptionChanged(object sender, OptionChangedEventArgs
return false;
}
public async Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, CancellationToken cancellationToken)
public async Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, InvocationReasons reasons, CancellationToken cancellationToken)
{
// method body change
if (bodyOpt != null || !document.IsOpen())
......@@ -106,12 +106,12 @@ public Task NewSolutionSnapshotAsync(Solution solution, CancellationToken cancel
return SpecializedTasks.EmptyTask;
}
public Task AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
public Task AnalyzeSyntaxAsync(Document document, 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;
}
......
......@@ -64,30 +64,30 @@ public bool NeedsReanalysisOnOptionChanged(object sender, OptionChangedEventArgs
return false;
}
public async Task AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
public async Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken)
{
IIncrementalAnalyzer analyzer;
if (TryGetAnalyzer(document.Project, out analyzer))
{
await analyzer.AnalyzeSyntaxAsync(document, cancellationToken).ConfigureAwait(false);
await analyzer.AnalyzeSyntaxAsync(document, reasons, cancellationToken).ConfigureAwait(false);
}
}
public async Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, CancellationToken cancellationToken)
public async Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, InvocationReasons reasons, CancellationToken cancellationToken)
{
IIncrementalAnalyzer analyzer;
if (TryGetAnalyzer(document.Project, out analyzer))
{
await analyzer.AnalyzeDocumentAsync(document, bodyOpt, cancellationToken).ConfigureAwait(false);
await analyzer.AnalyzeDocumentAsync(document, bodyOpt, reasons, cancellationToken).ConfigureAwait(false);
}
}
public async Task AnalyzeProjectAsync(Project project, bool semanticsChanged, CancellationToken cancellationToken)
public async Task AnalyzeProjectAsync(Project project, bool semanticsChanged, InvocationReasons reasons, CancellationToken cancellationToken)
{
IIncrementalAnalyzer analyzer;
if (TryGetAnalyzer(project, out analyzer))
{
await analyzer.AnalyzeProjectAsync(project, semanticsChanged, cancellationToken).ConfigureAwait(false);
await analyzer.AnalyzeProjectAsync(project, semanticsChanged, reasons, cancellationToken).ConfigureAwait(false);
}
}
......
......@@ -39,17 +39,17 @@ public bool NeedsReanalysisOnOptionChanged(object sender, OptionChangedEventArgs
return false;
}
public virtual Task AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
public virtual Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyTask;
}
public virtual Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, CancellationToken cancellationToken)
public virtual Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, InvocationReasons reasons, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyTask;
}
public virtual Task AnalyzeProjectAsync(Project project, bool semanticsChanged, CancellationToken cancellationToken)
public virtual Task AnalyzeProjectAsync(Project project, bool semanticsChanged, InvocationReasons reasons, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyTask;
}
......
......@@ -166,14 +166,15 @@ private void ResetLogAggregator()
Document document, ImmutableArray<IIncrementalAnalyzer> analyzers, WorkItem workItem, CancellationToken cancellationToken)
{
// process all analyzers for each categories in this order - syntax, body, document
if (workItem.MustRefresh || workItem.InvocationReasons.Contains(PredefinedInvocationReasons.SyntaxChanged))
var reasons = workItem.InvocationReasons;
if (workItem.MustRefresh || reasons.Contains(PredefinedInvocationReasons.SyntaxChanged))
{
await RunAnalyzersAsync(analyzers, document, (a, d, c) => a.AnalyzeSyntaxAsync(d, c), cancellationToken).ConfigureAwait(false);
await RunAnalyzersAsync(analyzers, document, (a, d, c) => a.AnalyzeSyntaxAsync(d, reasons, c), cancellationToken).ConfigureAwait(false);
}
if (workItem.MustRefresh || workItem.InvocationReasons.Contains(PredefinedInvocationReasons.SemanticChanged))
if (workItem.MustRefresh || reasons.Contains(PredefinedInvocationReasons.SemanticChanged))
{
await RunAnalyzersAsync(analyzers, document, (a, d, c) => a.AnalyzeDocumentAsync(d, null, c), cancellationToken).ConfigureAwait(false);
await RunAnalyzersAsync(analyzers, document, (a, d, c) => a.AnalyzeDocumentAsync(d, null, reasons, c), cancellationToken).ConfigureAwait(false);
}
else
{
......@@ -207,10 +208,11 @@ private static async Task RunBodyAnalyzersAsync(ImmutableArray<IIncrementalAnaly
{
var root = await GetOrDefaultAsync(document, (d, c) => d.GetSyntaxRootAsync(c), cancellationToken).ConfigureAwait(false);
var syntaxFactsService = document.Project.LanguageServices.GetService<ISyntaxFactsService>();
var reasons = workItem.InvocationReasons;
if (root == null || syntaxFactsService == null)
{
// as a fallback mechanism, if we can't run one method body due to some missing service, run whole document analyzer.
await RunAnalyzersAsync(analyzers, document, (a, d, c) => a.AnalyzeDocumentAsync(d, null, c), cancellationToken).ConfigureAwait(false);
await RunAnalyzersAsync(analyzers, document, (a, d, c) => a.AnalyzeDocumentAsync(d, null, reasons, c), cancellationToken).ConfigureAwait(false);
return;
}
......@@ -221,12 +223,12 @@ private static async Task RunBodyAnalyzersAsync(ImmutableArray<IIncrementalAnaly
{
// no active member means, change is out side of a method body, but it didn't affect semantics (such as change in comment)
// in that case, we update whole document (just this document) so that we can have updated locations.
await RunAnalyzersAsync(analyzers, document, (a, d, c) => a.AnalyzeDocumentAsync(d, null, c), cancellationToken).ConfigureAwait(false);
await RunAnalyzersAsync(analyzers, document, (a, d, c) => a.AnalyzeDocumentAsync(d, null, reasons, c), cancellationToken).ConfigureAwait(false);
return;
}
// re-run just the body
await RunAnalyzersAsync(analyzers, document, (a, d, c) => a.AnalyzeDocumentAsync(d, activeMember, c), cancellationToken).ConfigureAwait(false);
await RunAnalyzersAsync(analyzers, document, (a, d, c) => a.AnalyzeDocumentAsync(d, activeMember, reasons, c), cancellationToken).ConfigureAwait(false);
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
......
......@@ -145,12 +145,13 @@ private async Task ProcessProjectAsync(ImmutableArray<IIncrementalAnalyzer> anal
var project = processingSolution.GetProject(projectId);
if (project != null)
{
var semanticsChanged = workItem.InvocationReasons.Contains(PredefinedInvocationReasons.SemanticChanged) ||
workItem.InvocationReasons.Contains(PredefinedInvocationReasons.SolutionRemoved);
var reasons = workItem.InvocationReasons;
var semanticsChanged = reasons.Contains(PredefinedInvocationReasons.SemanticChanged) ||
reasons.Contains(PredefinedInvocationReasons.SolutionRemoved);
using (Processor.EnableCaching(project.Id))
{
await RunAnalyzersAsync(analyzers, project, (a, p, c) => a.AnalyzeProjectAsync(p, semanticsChanged, c), cancellationToken).ConfigureAwait(false);
await RunAnalyzersAsync(analyzers, project, (a, p, c) => a.AnalyzeProjectAsync(p, semanticsChanged, reasons, c), cancellationToken).ConfigureAwait(false);
}
}
else
......
......@@ -472,15 +472,16 @@ private async Task ProcessReanalyzeDocumentAsync(WorkItem workItem, Document doc
await RunAnalyzersAsync(reanalyzers, document, (a, d, c) => a.DocumentResetAsync(d, c), cancellationToken).ConfigureAwait(false);
// no request to re-run syntax change analysis. run it here
if (!workItem.InvocationReasons.Contains(PredefinedInvocationReasons.SyntaxChanged))
var reasons = workItem.InvocationReasons;
if (!reasons.Contains(PredefinedInvocationReasons.SyntaxChanged))
{
await RunAnalyzersAsync(reanalyzers, document, (a, d, c) => a.AnalyzeSyntaxAsync(d, c), cancellationToken).ConfigureAwait(false);
await RunAnalyzersAsync(reanalyzers, document, (a, d, c) => a.AnalyzeSyntaxAsync(d, reasons, c), cancellationToken).ConfigureAwait(false);
}
// no request to re-run semantic change analysis. run it here
if (!workItem.InvocationReasons.Contains(PredefinedInvocationReasons.SemanticChanged))
{
await RunAnalyzersAsync(reanalyzers, document, (a, d, c) => a.AnalyzeDocumentAsync(d, null, c), cancellationToken).ConfigureAwait(false);
await RunAnalyzersAsync(reanalyzers, document, (a, d, c) => a.AnalyzeDocumentAsync(d, null, reasons, c), cancellationToken).ConfigureAwait(false);
}
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
......
......@@ -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);
}
}
......
......@@ -11,6 +11,7 @@
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.SolutionCrawler;
using Microsoft.CodeAnalysis.Versions;
using Microsoft.VisualStudio.Designer.Interfaces;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
......@@ -63,7 +64,7 @@ public bool NeedsReanalysisOnOptionChanged(object sender, OptionChangedEventArgs
return false;
}
public async System.Threading.Tasks.Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, CancellationToken cancellationToken)
public async System.Threading.Tasks.Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, InvocationReasons reasons, CancellationToken cancellationToken)
{
Contract.ThrowIfFalse(document.IsFromPrimaryBranch());
......@@ -309,12 +310,12 @@ public System.Threading.Tasks.Task DocumentCloseAsync(Document document, Cancell
return SpecializedTasks.EmptyTask;
}
public System.Threading.Tasks.Task AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
public System.Threading.Tasks.Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyTask;
}
public System.Threading.Tasks.Task AnalyzeProjectAsync(Project project, bool semanticsChanged, CancellationToken cancellationToken)
public System.Threading.Tasks.Task AnalyzeProjectAsync(Project project, bool semanticsChanged, InvocationReasons reasons, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyTask;
}
......
// 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;
......@@ -64,7 +65,7 @@ public Task NewSolutionSnapshotAsync(Solution solution, CancellationToken cancel
return SpecializedTasks.EmptyTask;
}
public async Task AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
public async Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken)
{
if (!document.SupportsSyntaxTree)
{
......@@ -110,7 +111,7 @@ public void RemoveDocument(DocumentId documentId)
}
#region Not Used
public Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, CancellationToken cancellationToken)
public Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, InvocationReasons reasons, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyTask;
}
......@@ -135,7 +136,7 @@ public bool NeedsReanalysisOnOptionChanged(object sender, OptionChangedEventArgs
return false;
}
public Task AnalyzeProjectAsync(Project project, bool semanticsChanged, CancellationToken cancellationToken)
public Task AnalyzeProjectAsync(Project project, bool semanticsChanged, InvocationReasons reasons, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyTask;
}
......
......@@ -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
......
......@@ -18,9 +18,9 @@ internal interface IIncrementalAnalyzer
/// </summary>
Task DocumentResetAsync(Document document, CancellationToken cancellationToken);
Task AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken);
Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, CancellationToken cancellationToken);
Task AnalyzeProjectAsync(Project project, bool semanticsChanged, CancellationToken cancellationToken);
Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken);
Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, InvocationReasons reasons, CancellationToken cancellationToken);
Task AnalyzeProjectAsync(Project project, bool semanticsChanged, InvocationReasons reasons, CancellationToken cancellationToken);
void RemoveDocument(DocumentId documentId);
void RemoveProject(ProjectId projectId);
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册