-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Produce 'invisible' squiggles for 'Remove Unnecessary Usings' and 'Simpl... #1243
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,32 +16,48 @@ internal abstract class RemoveUnnecessaryImportsDiagnosticAnalyzerBase : Diagnos | |
| // NOTE: This is a trigger diagnostic, which doesn't show up in the ruleset editor and hence doesn't need a conventional IDE Diagnostic ID string. | ||
| internal const string DiagnosticFixableId = "RemoveUnnecessaryImportsFixable"; | ||
|
|
||
| private static LocalizableString s_localizableMessageAndTitle = new LocalizableResourceString(nameof(WorkspacesResources.RemoveUnnecessaryImportsOrUsings), WorkspacesResources.ResourceManager, typeof(WorkspacesResources)); | ||
|
|
||
| private static readonly DiagnosticDescriptor s_classificationIdDescriptor = new DiagnosticDescriptor(IDEDiagnosticIds.RemoveUnnecessaryImportsDiagnosticId, | ||
| s_localizableMessageAndTitle, | ||
| s_localizableMessageAndTitle, | ||
| DiagnosticCategory.Style, | ||
| DiagnosticSeverity.Hidden, | ||
| isEnabledByDefault: true, | ||
| customTags: DiagnosticCustomTags.Unnecessary); | ||
|
|
||
| // The NotConfigurable custom tag ensures that user can't turn this diagnostic into a warning / error via | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to keep the descriptor here so that both of the descriptors are together instead of being spread across three files. Instead of the abstract GetClassificationIdDescriptor, you could simply have an abstract GetMessage(). That way if we make changes to the descriptor we can make it in one place.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure will change that.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
| // ruleset editor or solution explorer. Setting messageFormat to empty string ensures that we won't display | ||
| // this diagnostic in the preview pane header. | ||
| private static readonly DiagnosticDescriptor s_fixableIdDescriptor = new DiagnosticDescriptor(DiagnosticFixableId, | ||
| title: "", messageFormat: "", category: "", | ||
| defaultSeverity: DiagnosticSeverity.Hidden, | ||
| isEnabledByDefault: true, | ||
| customTags: WellKnownDiagnosticTags.NotConfigurable); | ||
| private static readonly DiagnosticDescriptor s_fixableIdDescriptor = | ||
| new DiagnosticDescriptor(DiagnosticFixableId, | ||
| title: "", messageFormat: "", category: "", | ||
| defaultSeverity: DiagnosticSeverity.Hidden, | ||
| isEnabledByDefault: true, | ||
| customTags: WellKnownDiagnosticTags.NotConfigurable); | ||
|
|
||
| protected abstract LocalizableString GetTitleAndMessageFormatForClassificationIdDescriptor(); | ||
|
|
||
| private static readonly ImmutableArray<DiagnosticDescriptor> s_descriptors = ImmutableArray.Create(s_fixableIdDescriptor, s_classificationIdDescriptor); | ||
| private DiagnosticDescriptor _classificationIdDescriptor; | ||
| private DiagnosticDescriptor GetClassificationIdDescriptor() | ||
| { | ||
| if (_classificationIdDescriptor == null) | ||
| { | ||
| var titleAndMessageFormat = GetTitleAndMessageFormatForClassificationIdDescriptor(); | ||
| _classificationIdDescriptor = | ||
| new DiagnosticDescriptor(IDEDiagnosticIds.RemoveUnnecessaryImportsDiagnosticId, | ||
| titleAndMessageFormat, | ||
| titleAndMessageFormat, | ||
| DiagnosticCategory.Style, | ||
| DiagnosticSeverity.Hidden, | ||
| isEnabledByDefault: true, | ||
| customTags: DiagnosticCustomTags.Unnecessary); | ||
| } | ||
|
|
||
| return _classificationIdDescriptor; | ||
| } | ||
|
|
||
| private ImmutableArray<DiagnosticDescriptor> _descriptors; | ||
| public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics | ||
| { | ||
| get | ||
| { | ||
| return s_descriptors; | ||
| if (_descriptors == null) | ||
| { | ||
| _descriptors = ImmutableArray.Create(s_fixableIdDescriptor, GetClassificationIdDescriptor()); | ||
| } | ||
|
|
||
| return _descriptors; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -85,7 +101,7 @@ protected virtual Func<SyntaxNode, SyntaxToken> GetLastTokenDelegateForContiguou | |
| continue; | ||
| } | ||
|
|
||
| yield return Diagnostic.Create(s_classificationIdDescriptor, tree.GetLocation(span)); | ||
| yield return Diagnostic.Create(GetClassificationIdDescriptor(), tree.GetLocation(span)); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
You could write
analyzerMap?.Count > 0and flip then/else branches.