-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Simplify determination of live vs. build diagnostics #79691
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
Conversation
| warningLevel: 0, | ||
| customTags: ImmutableArray<string>.Empty, | ||
| // Mark these diagnostics as build errors so they can be overridden by diagnostics from an explicit build. | ||
| customTags: [WellKnownDiagnosticTags.Build], |
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.
We are hitting a debug assertion in DiagnosticSourceManager (see below) when attempting to aggregate document diagnostics from multiple sources when a client calls into us that does not support multiple sources (these are Razor, super old versions of VS/VSCode, or third party LSPs). We could not aggregate live and non-live diagnostic sources into a single source as the diagnostics returned are modified based on the source.
We recently introduced a new non-live document diagnostic source, which triggered the assert (see below) when Razor calls into us.
After looking at this, it appeared to me as though a diagnostic source being 'live' or 'not live' was not the correct abstraction. At the end of the day, IsLiveSource was only ever read to set a tag on the diagnostic indicating if it was a build diagnostic. Instead of having IsLiveSource be on the IDiagnosticSource, we can just create diagnostics with the correct build tag to begin with!
| // If tagged as build, mark this also as a build error. That way an explicitly kicked off build from a source like CPS can | ||
| // override it. | ||
| if (!isLiveSource) | ||
| result.Add(VSDiagnosticTags.BuildError); |
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.
as above, this was the only place IDiagnosticSource.isLiveSource eventually got read. And we already set the build tag based on our build tag below. So we can just set the build tag on the diagnostics directly instead of this whole method on the source.
| if (isDocument) | ||
| { | ||
| // Group all document sources into a single source. | ||
| Debug.Assert(sources.All(s => s.IsLiveSource()), "All document sources should be live"); |
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.
this was the assert that was firing. Now there is no concept of 'live' vs. non-live sources, just live vs. non-live diagnostics
| //This source provides the results of the *last* explicitly kicked off "run code analysis" command from the | ||
| // user. As such, it is definitely not "live" data, and it should be overridden by any subsequent fresh data | ||
| // that has been produced. | ||
| diagnostics = [.. diagnostics.Select(d => d.WithCustomTags(d.CustomTags.Add(WellKnownDiagnosticTags.Build)))]; |
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.
explicitly tag the diagnostics as build diagnostics in the impl, instead of using IsLiveSource
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.
Is there any possibility of the diagnostics already having Build tags?
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.
yeah. might want a helper that only adds if not alreadythere. and call that single helper from all these places.
jasonmalinowski
left a comment
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.
Seems reasonable to me, I'm not the expert here though.
...uageServer/Protocol/Handler/Diagnostics/DiagnosticSources/AbstractProjectDiagnosticSource.cs
Outdated
Show resolved
Hide resolved
| //This source provides the results of the *last* explicitly kicked off "run code analysis" command from the | ||
| // user. As such, it is definitely not "live" data, and it should be overridden by any subsequent fresh data | ||
| // that has been produced. | ||
| diagnostics = [.. diagnostics.Select(d => d.WithCustomTags(d.CustomTags.Add(WellKnownDiagnosticTags.Build)))]; |
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.
Is there any possibility of the diagnostics already having Build tags?
.../Protocol/Handler/Diagnostics/DiagnosticSources/AbstractWorkspaceDocumentDiagnosticSource.cs
Outdated
Show resolved
Hide resolved
.../Protocol/Handler/Diagnostics/DiagnosticSources/AbstractWorkspaceDocumentDiagnosticSource.cs
Outdated
Show resolved
Hide resolved
.../Protocol/Handler/Diagnostics/DiagnosticSources/AbstractWorkspaceDocumentDiagnosticSource.cs
Outdated
Show resolved
Hide resolved
...uageServer/Protocol/Handler/Diagnostics/DiagnosticSources/AbstractProjectDiagnosticSource.cs
Outdated
Show resolved
Hide resolved
...uageServer/Protocol/Handler/Diagnostics/DiagnosticSources/AbstractProjectDiagnosticSource.cs
Outdated
Show resolved
Hide resolved
src/LanguageServer/Protocol/Handler/Diagnostics/DiagnosticSources/IDiagnosticSource.cs
Show resolved
Hide resolved
CyrusNajmabadi
left a comment
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.
Overall seems good. tiny cleanup maybe.
src/Compilers/Core/Portable/Diagnostic/WellKnownDiagnosticTags.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Rikki Gibson <[email protected]>
Removes IsLive from the diagnostic source, and relies on diagnostic tags to correctly set the
Builddiagnostic tag.This fixes a debug assert crash when using Razor with the latest main changes
this bug was revealed in #79421 when a non-live doc diagnostic source was added