-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Stop showing smart tags for subsequent 'Unnecessary' diagnostics #41854
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
...Core/Portable/UseCollectionInitializer/AbstractUseCollectionInitializerDiagnosticAnalyzer.cs
Outdated
Show resolved
Hide resolved
...eatures/Core/Portable/UseObjectInitializer/AbstractUseObjectInitializerDiagnosticAnalyzer.cs
Outdated
Show resolved
Hide resolved
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.
@mavasani did we ever add the ability to specify faded regions without additional diagnostics?
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.
Yes, @dibarbet added the helper API to create a diagnostic with additional locations for fading also fixed up one of the analyzers. We should clean up all our IDE analyzers to use the same approach instead of using separate fading diagnostics.
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.
Would it make sense for me to add that cleanup as a commit to this PR?
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.
Would that fix mean removing just UnnecessaryWithoutSuggestion or both that and Unnecessary? (Guessing the latter)
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.
DiagnosticHelper.CreateWithLocationTags itself needs a helper
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.
Does 1812d31 seem like a good direction to go in? If not, let me know what you're thinking or just take over and I'll close the PR.
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.
I think UnnecessaryWithSuggestion is still needed, because it has a diagnostic ID that gets picked up by a code fix. UnnecessaryWithoutSuggestion exists solely for the fading.
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.
@sharwell @mavasani The helper API created by @dibarbet does not fade the additional locations unless the diagnostic descriptor used also has the 'Unnecessary' tag. The need to have the 'Unnecessary' tag both in the descriptor and in the additional locations seems redundant and possibly an oversight. This means that the new API can't be used to report a diagnostic on a non-faded span and additional faded spans at the same time: the first requires the descriptor to not have the 'Unnecessary' tag, and the second requires the opposite.
Plenty of analyzers using UnnecessaryWithoutSuggestion are just this kind: they are fading spans other than the main reported span which itself should not be faded, and one analyzer even uses UnnecessaryWithoutSuggestion to fade a span specifically without allowing Ctrl+. to register an action for that span.
I'm not sure what the best course of action is, but my first thought is that this new API is not ready to be used in the timeframe for this PR to be merged. Does this sound right to you?
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.
@CyrusNajmabadi Before you keep reviewing, I'm going to drop all but the first two commits (the ones that actually fix the titular bug).
@sharwell @mavasani @CyrusNajmabadi I can't do the cleanup mentioned above without direction. See the explanation of the situations I ran into that the new CreateWithLocationTags can't handle.
1812d31 to
d7e923f
Compare
...tures/CSharp/Portable/RemoveUnreachableCode/CSharpRemoveUnreachableCodeDiagnosticAnalyzer.cs
Outdated
Show resolved
Hide resolved
...tures/Core/Portable/SimplifyInterpolation/AbstractSimplifyInterpolationDiagnosticAnalyzer.cs
Outdated
Show resolved
Hide resolved
...alBasic/Portable/UseInferredMemberName/VisualBasicUseInferredMemberNameDiagnosticAnalyzer.vb
Outdated
Show resolved
Hide resolved
d7e923f to
6ce79b9
Compare
src/EditorFeatures/CSharpTest/SimplifyInterpolation/SimplifyInterpolationTests.cs
Outdated
Show resolved
Hide resolved
| var severity = option.Notification.Severity; | ||
|
|
||
| for (var i = 0; i < unnecessaryLocations.Length; i++) | ||
| foreach (var subsequentLocation in unnecessaryLocations.Skip(1)) |
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.
for (var i = 1; i < unnecessaryLocations.Length; i++)
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.
I can do this but I'm reluctant without knowing why this would be preferable.
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.
One reason is to just avoid the linq allocation. Second is just that it feels clearer to me. :)
...tures/Core/Portable/SimplifyInterpolation/AbstractSimplifyInterpolationDiagnosticAnalyzer.cs
Show resolved
Hide resolved
...tures/Core/Portable/SimplifyInterpolation/AbstractSimplifyInterpolationDiagnosticAnalyzer.cs
Show resolved
Hide resolved
|
thanks! |
...tures/Core/Portable/SimplifyInterpolation/AbstractSimplifyInterpolationDiagnosticAnalyzer.cs
Show resolved
Hide resolved
…ifyInterpolationDiagnosticAnalyzer.cs
ghost
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.
Auto-approval
…ut_repeated_smart_tag
|
Thanks @jnm2 ! |
Fixes #41849
Before (my 16.5-p3 installation):
After (debugging Roslyn):
The third commit attempt to fix the pit of failure I fell into originally. It removes access to
UnnecessaryWithoutSuggestionDescriptorand replaces it withCreateUnnecessaryWithoutSuggestionDiagnostic.(There could honestly be a helper that feeds
IEnumerable<Location>/params Location[]tocontext.ReportDiagnosticfor you, probably.)