Add support for incremental analysis for method body editing scenario…#63130
Add support for incremental analysis for method body editing scenario…#63130mavasani merged 9 commits intodotnet:mainfrom
Conversation
…s for LSP document pull diagnostics computation path, i.e. below APIs: https://github.com/dotnet/roslyn/blob/f6f1c7171ce27ad23fc3c87d1c996dedf2156f44/src/Features/Core/Portable/Diagnostics/IDiagnosticAnalyzerService.cs#L69-L91 The incremental analysis is currently guarded by a feature flag.
| { | ||
| internal partial class DiagnosticIncrementalAnalyzer | ||
| { | ||
| private sealed class MemberRangeMap |
There was a problem hiding this comment.
Almost all the code in this file is ported from the prior implementation of incremental method body analysis in DiagnosticIncrementalAnalyzer v1 engine.
| } | ||
| } | ||
|
|
||
| public MemberRanges GetOrCreateMemberRanges( |
There was a problem hiding this comment.
This is the only new method I have added on top of the previous implementation.
| /// If we are unable to perform this incremental diagnostics update, we fallback to computing | ||
| /// the diagnostics for the entire document. | ||
| /// </summary> | ||
| private sealed class IncrementalMemberEditAnalyzer |
There was a problem hiding this comment.
This type has the meat of the incremental analysis support.
| #endif | ||
| } | ||
|
|
||
| private static bool TryGetUpdatedDocumentDiagnostics( |
There was a problem hiding this comment.
This is the core logic that computes latest diagnostics using latest changed member diagnostics and cached diagnostics from document snapshot prior to member edit. Almost all the code in the method is borrowed from prior implementation. I primarily added additional location handling here as we were either dropping them or not updating the spans for those, both of them were leading to asserts.
...erver/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.MemberRangeMap.cs
Outdated
Show resolved
Hide resolved
...erver/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.MemberRangeMap.cs
Outdated
Show resolved
Hide resolved
...erver/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.MemberRangeMap.cs
Outdated
Show resolved
Hide resolved
...erver/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.MemberRangeMap.cs
Outdated
Show resolved
Hide resolved
...erver/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.MemberRangeMap.cs
Outdated
Show resolved
Hide resolved
...erver/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.MemberRangeMap.cs
Outdated
Show resolved
Hide resolved
...erver/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.MemberRangeMap.cs
Outdated
Show resolved
Hide resolved
...tures/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.cs
Show resolved
Hide resolved
...rotocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs
Show resolved
Hide resolved
...Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalMemberEditAnalysis.cs
Outdated
Show resolved
Hide resolved
...gnostics/EngineV2/DiagnosticIncrementalAnalyzer.IncrementalMemberEditAnalyzer_MemberSpans.cs
Show resolved
Hide resolved
...gnostics/EngineV2/DiagnosticIncrementalAnalyzer.IncrementalMemberEditAnalyzer_MemberSpans.cs
Show resolved
Hide resolved
...Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.IncrementalMemberEditAnalyzer.cs
Outdated
Show resolved
Hide resolved
...Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.IncrementalMemberEditAnalyzer.cs
Show resolved
Hide resolved
Fixes [AB#1618061](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1618061) This was introduced by me with dotnet#63130. Earlier we used to cache full document diagnostics computed only from background analysis, which also handles updating the error list simulataneously. With the above PR, we also do this caching from other code paths if we are computing full document diagnostics (diagnostic tagger, LSP pull diags, etc.), but we don't raise events to update the error list from these code paths - basically the code added here: https://github.com/mavasani/roslyn/blob/cd5e6895d3dc8dfad270505b37d28be70077a645/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs#L323-L329. So when background analysis gets to refreshing the document diagnostics, it founds cached items and ends up not updating the error list. With this PR, we now cache the computed full document diagnostics in the new code paths only in LSP pull diagnostics mode. Verified that the repro in the above bug is fixed after this change.
Fixes [AB#1618061](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1618061) This was introduced by me with dotnet#63130. Earlier we used to cache full document diagnostics computed only from background analysis, which also handles updating the error list simulataneously. With the above PR, we also do this caching from other code paths if we are computing full document diagnostics (diagnostic tagger, LSP pull diags, etc.), but we don't raise events to update the error list from these code paths - basically the code added here: https://github.com/mavasani/roslyn/blob/cd5e6895d3dc8dfad270505b37d28be70077a645/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs#L323-L329. So when background analysis gets to refreshing the document diagnostics, it founds cached items and ends up not updating the error list. With this PR, we now cache the computed full document diagnostics in the new code paths only in LSP pull diagnostics mode. Verified that the repro in the above bug is fixed after this change.
…s for LSP document pull diagnostics computation path, i.e. below APIs:
roslyn/src/Features/Core/Portable/Diagnostics/IDiagnosticAnalyzerService.cs
Lines 69 to 91 in f6f1c71
The incremental analysis is currently guarded by a feature flag.