diff --git a/src/EditorFeatures/Core/Implementation/Suggestions/CodeFixSuggestedAction.cs b/src/EditorFeatures/Core/Implementation/Suggestions/CodeFixSuggestedAction.cs index 3539948c20dc2aa7fbea1bd6876c0448185dd17a..667466e8f28129753ebe0be3792700243ea6996b 100644 --- a/src/EditorFeatures/Core/Implementation/Suggestions/CodeFixSuggestedAction.cs +++ b/src/EditorFeatures/Core/Implementation/Suggestions/CodeFixSuggestedAction.cs @@ -59,7 +59,7 @@ internal class CodeFixSuggestedAction : SuggestedActionWithFlavors, ITelemetryDi foreach (var scope in fixAllCodeActionContext.SupportedScopes) { var fixAllContext = fixAllCodeActionContext.GetContextForScopeAndActionId(scope, action.EquivalenceKey); - var fixAllAction = new FixAllCodeAction(fixAllContext, fixAllCodeActionContext.FixAllProvider); + var fixAllAction = new FixAllCodeAction(fixAllContext, fixAllCodeActionContext.FixAllProvider, showPreviewChangesDialog: true); var fixAllSuggestedAction = new FixAllSuggestedAction(workspace, subjectBuffer, editHandler, fixAllAction, fixAllCodeActionContext.FixAllProvider, fixAllCodeActionContext.OriginalDiagnostics.First()); fixAllSuggestedActions.Add(fixAllSuggestedAction); diff --git a/src/EditorFeatures/Core/Implementation/Suggestions/FixAllGetFixesService.cs b/src/EditorFeatures/Core/Implementation/Suggestions/FixAllGetFixesService.cs index b6d5c3edd150019796c9bdfaf6f799f507b72d9b..0edb3467aec15d67c0c6c36a920487d0e1cb7912 100644 --- a/src/EditorFeatures/Core/Implementation/Suggestions/FixAllGetFixesService.cs +++ b/src/EditorFeatures/Core/Implementation/Suggestions/FixAllGetFixesService.cs @@ -31,7 +31,7 @@ public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices) return this; } - public async Task> GetFixAllOperationsAsync(FixAllProvider fixAllProvider, FixAllContext fixAllContext, string fixAllPreviewChangesTitle, string waitDialogMessage) + public async Task> GetFixAllOperationsAsync(FixAllProvider fixAllProvider, FixAllContext fixAllContext, string fixAllTitle, string waitDialogMessage, bool showPreviewChangesDialog) { // Compute fix all occurrences code fix for the given fix all context. // Bring up a cancellable wait dialog. @@ -40,7 +40,7 @@ public async Task> GetFixAllOperationsAsync(Fix using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesComputation, fixAllContext.CancellationToken)) { var result = _waitIndicator.Wait( - fixAllPreviewChangesTitle, + fixAllTitle, waitDialogMessage, allowCancel: true, action: waitContext => @@ -75,10 +75,10 @@ public async Task> GetFixAllOperationsAsync(Fix } FixAllLogger.LogComputationResult(completed: true); - return await GetFixAllOperationsAsync(codeAction, fixAllContext, fixAllPreviewChangesTitle).ConfigureAwait(false); + return await GetFixAllOperationsAsync(codeAction, fixAllContext, fixAllTitle, showPreviewChangesDialog).ConfigureAwait(false); } - private async Task> GetFixAllOperationsAsync(CodeAction codeAction, FixAllContext fixAllContext, string fixAllPreviewChangesTitle) + private async Task> GetFixAllOperationsAsync(CodeAction codeAction, FixAllContext fixAllContext, string fixAllPreviewChangesTitle, bool showPreviewChangesDialog) { // We have computed the fix all occurrences code fix. // Now fetch the new solution with applied fix and bring up the Preview changes dialog. @@ -96,32 +96,35 @@ private async Task> GetFixAllOperationsAsync(Co cancellationToken.ThrowIfCancellationRequested(); var newSolution = await codeAction.GetChangedSolutionInternalAsync(cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); - using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesPreviewChanges, cancellationToken)) + if (showPreviewChangesDialog) { - var previewService = workspace.Services.GetService(); - var glyph = fixAllContext.Project.Language == LanguageNames.CSharp ? - Glyph.CSharpProject : - Glyph.BasicProject; - - var changedSolution = previewService.PreviewChanges( - string.Format(EditorFeaturesResources.PreviewChangesOf, fixAllPreviewChangesTitle), - "vs.codefix.fixall", - codeAction.Title, - fixAllPreviewChangesTitle, - glyph, - newSolution, - fixAllContext.Project.Solution); - - if (changedSolution == null) + cancellationToken.ThrowIfCancellationRequested(); + using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesPreviewChanges, cancellationToken)) { - // User clicked cancel. - FixAllLogger.LogPreviewChangesResult(applied: false); - return null; - } + var previewService = workspace.Services.GetService(); + var glyph = fixAllContext.Project.Language == LanguageNames.CSharp ? + Glyph.CSharpProject : + Glyph.BasicProject; + + var changedSolution = previewService.PreviewChanges( + string.Format(EditorFeaturesResources.PreviewChangesOf, fixAllPreviewChangesTitle), + "vs.codefix.fixall", + codeAction.Title, + fixAllPreviewChangesTitle, + glyph, + newSolution, + fixAllContext.Project.Solution); - FixAllLogger.LogPreviewChangesResult(applied: true, allChangesApplied: changedSolution == newSolution); - newSolution = changedSolution; + if (changedSolution == null) + { + // User clicked cancel. + FixAllLogger.LogPreviewChangesResult(applied: false); + return null; + } + + FixAllLogger.LogPreviewChangesResult(applied: true, allChangesApplied: changedSolution == newSolution); + newSolution = changedSolution; + } } // Get a code action, with apply changes operation replaced with the newSolution. diff --git a/src/EditorFeatures/Core/Implementation/Suggestions/FixMultipleOccurrencesService.cs b/src/EditorFeatures/Core/Implementation/Suggestions/FixMultipleOccurrencesService.cs index f3d4d90b39b88eee5fc4987d5193eb2e813159b8..c2d49aa9cc5f501b067d753bbd50c29917353707 100644 --- a/src/EditorFeatures/Core/Implementation/Suggestions/FixMultipleOccurrencesService.cs +++ b/src/EditorFeatures/Core/Implementation/Suggestions/FixMultipleOccurrencesService.cs @@ -35,12 +35,13 @@ public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices) CodeFixProvider fixProvider, FixAllProvider fixAllProvider, string equivalenceKey, - string previewChangesTitle, + string waitDialogAndPreviewChangesTitle, string waitDialogMessage, + bool showPreviewChangesDialog, CancellationToken cancellationToken) { var fixMultipleContext = FixMultipleContext.Create(diagnosticsToFix, fixProvider, equivalenceKey, cancellationToken); - ComputeAndApplyFix(fixMultipleContext, workspace, fixAllProvider, previewChangesTitle, waitDialogMessage, cancellationToken); + ComputeAndApplyFix(fixMultipleContext, workspace, fixAllProvider, waitDialogAndPreviewChangesTitle, waitDialogMessage, showPreviewChangesDialog, cancellationToken); } public void ComputeAndApplyFix( @@ -49,23 +50,25 @@ public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices) CodeFixProvider fixProvider, FixAllProvider fixAllProvider, string equivalenceKey, - string previewChangesTitle, + string waitDialogAndPreviewChangesTitle, string waitDialogMessage, + bool showPreviewChangesDialog, CancellationToken cancellationToken) { var fixMultipleContext = FixMultipleContext.Create(diagnosticsToFix, fixProvider, equivalenceKey, cancellationToken); - ComputeAndApplyFix(fixMultipleContext, workspace, fixAllProvider, previewChangesTitle, waitDialogMessage, cancellationToken); + ComputeAndApplyFix(fixMultipleContext, workspace, fixAllProvider, waitDialogAndPreviewChangesTitle, waitDialogMessage, showPreviewChangesDialog, cancellationToken); } private void ComputeAndApplyFix( FixMultipleContext fixMultipleContext, Workspace workspace, FixAllProvider fixAllProvider, - string previewChangesTitle, + string waitDialogAndPreviewChangesTitle, string waitDialogMessage, + bool showPreviewChangesDialog, CancellationToken cancellationToken) { - var fixMultipleCodeAction = new FixMultipleCodeAction(fixMultipleContext, fixAllProvider, title: previewChangesTitle, previewChangesDialogTitle: previewChangesTitle, computingFixWaitDialogMessage: waitDialogMessage); + var fixMultipleCodeAction = new FixMultipleCodeAction(fixMultipleContext, fixAllProvider, title: waitDialogAndPreviewChangesTitle, previewChangesDialogTitle: waitDialogAndPreviewChangesTitle, computingFixWaitDialogMessage: waitDialogMessage, showPreviewChangesDialog: showPreviewChangesDialog); var fixMultipleSuggestedAction = new FixMultipleSuggestedAction(workspace, _editHandler, fixMultipleCodeAction, fixAllProvider); fixMultipleSuggestedAction.Invoke(cancellationToken); } diff --git a/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/FixAllCodeAction.cs b/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/FixAllCodeAction.cs index 74e0e5d3a163b775584e7502a0bc7836f34366ce..e772b39fbc82d5781aa385a54e2f5dd50b816f96 100644 --- a/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/FixAllCodeAction.cs +++ b/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/FixAllCodeAction.cs @@ -17,12 +17,14 @@ internal partial class FixAllCodeAction : CodeAction { private readonly FixAllContext _fixAllContext; private readonly FixAllProvider _fixAllProvider; + private readonly bool _showPreviewChangesDialog; private static readonly HashSet s_predefinedCodeFixProviderNames = GetPredefinedCodeFixProviderNames(); - internal FixAllCodeAction(FixAllContext fixAllContext, FixAllProvider fixAllProvider) + internal FixAllCodeAction(FixAllContext fixAllContext, FixAllProvider fixAllProvider, bool showPreviewChangesDialog) { _fixAllContext = fixAllContext; _fixAllProvider = fixAllProvider; + _showPreviewChangesDialog = showPreviewChangesDialog; } public override string Title @@ -54,7 +56,7 @@ protected override async Task> ComputeOperation var service = _fixAllContext.Project.Solution.Workspace.Services.GetService(); // Use the new cancellation token instead of the stale one present inside _fixAllContext. - return await service.GetFixAllOperationsAsync(_fixAllProvider, _fixAllContext.WithCancellationToken(cancellationToken), FixAllPreviewChangesTitle, ComputingFixAllWaitDialogMessage).ConfigureAwait(false); + return await service.GetFixAllOperationsAsync(_fixAllProvider, _fixAllContext.WithCancellationToken(cancellationToken), FixAllPreviewChangesTitle, ComputingFixAllWaitDialogMessage, _showPreviewChangesDialog).ConfigureAwait(false); } private static bool IsInternalCodeFixProvider(CodeFixProvider fixer) diff --git a/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/FixMultipleCodeAction.cs b/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/FixMultipleCodeAction.cs index c980f79dbd635519ef3e5c7efa7e0503bae85bb1..e59f44d7f4e902a375c2607608c03c05dbc800dc 100644 --- a/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/FixMultipleCodeAction.cs +++ b/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/FixMultipleCodeAction.cs @@ -11,8 +11,8 @@ internal partial class FixMultipleCodeAction : FixAllCodeAction private readonly string _previewChangesDialogTitle; private readonly string _computingFixWaitDialogMessage; - internal FixMultipleCodeAction(FixMultipleContext fixMultipleContext, FixAllProvider fixAllProvider, string title, string previewChangesDialogTitle, string computingFixWaitDialogMessage) - : base (fixMultipleContext, fixAllProvider) + internal FixMultipleCodeAction(FixMultipleContext fixMultipleContext, FixAllProvider fixAllProvider, string title, string previewChangesDialogTitle, string computingFixWaitDialogMessage, bool showPreviewChangesDialog) + : base (fixMultipleContext, fixAllProvider, showPreviewChangesDialog) { _title = title; _previewChangesDialogTitle = previewChangesDialogTitle; diff --git a/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/IFixAllGetFixesService.cs b/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/IFixAllGetFixesService.cs index febf9b09a3c6131e6d745dc451d8210f7a8a9283..3b858b1f83003dbf8bb0027a183f113a27eb2841 100644 --- a/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/IFixAllGetFixesService.cs +++ b/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/IFixAllGetFixesService.cs @@ -13,6 +13,6 @@ internal interface IFixAllGetFixesService : IWorkspaceService /// Computes the fix all occurrences code fix, brings up the preview changes dialog for the fix and /// returns the code action operations corresponding to the fix. /// - Task> GetFixAllOperationsAsync(FixAllProvider fixAllProvider, FixAllContext fixAllContext, string fixAllPreviewChangesTitle, string waitDialogMessage); + Task> GetFixAllOperationsAsync(FixAllProvider fixAllProvider, FixAllContext fixAllContext, string fixAllTitle, string waitDialogMessage, bool showPreviewChangesDialog); } } diff --git a/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/IFixMultipleOccurrencesService.cs b/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/IFixMultipleOccurrencesService.cs index 68aba384eba574ba1904f4d5fb86698a409a4c0c..ff2d76a566b98bd8af751aadd461fbe8a9bf9b81 100644 --- a/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/IFixMultipleOccurrencesService.cs +++ b/src/Features/Core/Portable/CodeFixes/FixAllOccurrences/IFixMultipleOccurrencesService.cs @@ -18,8 +18,9 @@ internal interface IFixMultipleOccurrencesService : IWorkspaceService CodeFixProvider fixProvider, FixAllProvider fixAllProvider, string equivalenceKey, - string previewChangesTitle, + string waitDialogAndPreviewChangesTitle, string waitDialogMessage, + bool showPreviewChangesDialog, CancellationToken cancellationToken); /// @@ -32,8 +33,9 @@ internal interface IFixMultipleOccurrencesService : IWorkspaceService CodeFixProvider fixProvider, FixAllProvider fixAllProvider, string equivalenceKey, - string previewChangesTitle, + string waitDialogAndPreviewChangesTitle, string waitDialogMessage, + bool showPreviewChangesDialog, CancellationToken cancellationToken); } } diff --git a/src/Features/Core/Portable/Diagnostics/EngineV1/DiagnosticAnalyzerDriver.cs b/src/Features/Core/Portable/Diagnostics/EngineV1/DiagnosticAnalyzerDriver.cs index bd356e6bce6a090d9e095cb3f2d9e04359d92f9f..cf679bf92ae275cc15908e890eba09ae5b0b5905 100644 --- a/src/Features/Core/Portable/Diagnostics/EngineV1/DiagnosticAnalyzerDriver.cs +++ b/src/Features/Core/Portable/Diagnostics/EngineV1/DiagnosticAnalyzerDriver.cs @@ -57,7 +57,7 @@ internal class DiagnosticAnalyzerDriver owner.GetOnAnalyzerException(project.Id), concurrentAnalysis: false, logAnalyzerExecutionTime: true, - reportDiagnosticsWithSourceSuppression: true); + reportSuppressedDiagnostics: true); _lazyCompilationWithAnalyzers = null; } diff --git a/src/VisualStudio/Core/Def/Implementation/TableDataSource/DiagnosticTableControlEventProcessorProvider.cs b/src/VisualStudio/Core/Def/Implementation/TableDataSource/DiagnosticTableControlEventProcessorProvider.cs index f510a7cb7721d08986cca89ce626970ff5e4f4b5..95b8d31dec75415d5e5bf5f7d77c0e93dc29bd36 100644 --- a/src/VisualStudio/Core/Def/Implementation/TableDataSource/DiagnosticTableControlEventProcessorProvider.cs +++ b/src/VisualStudio/Core/Def/Implementation/TableDataSource/DiagnosticTableControlEventProcessorProvider.cs @@ -20,9 +20,9 @@ internal partial class DiagnosticTableControlEventProcessorProvider : AbstractTa [ImportingConstructor] public DiagnosticTableControlEventProcessorProvider( - VisualStudioDiagnosticListSuppressionStateService suppressionStateService) + IVisualStudioDiagnosticListSuppressionStateService suppressionStateService) { - _suppressionStateService = suppressionStateService; + _suppressionStateService = (VisualStudioDiagnosticListSuppressionStateService)suppressionStateService; } protected override EventProcessor CreateEventProcessor() diff --git a/src/VisualStudio/Core/Def/Implementation/TableDataSource/Suppression/IVisualStudioSuppressionFixService.cs b/src/VisualStudio/Core/Def/Implementation/TableDataSource/Suppression/IVisualStudioSuppressionFixService.cs index 701f8749095449aaeefc91979053c542f641ae53..c688900d56b785f6d9a360b93cada028245b8eeb 100644 --- a/src/VisualStudio/Core/Def/Implementation/TableDataSource/Suppression/IVisualStudioSuppressionFixService.cs +++ b/src/VisualStudio/Core/Def/Implementation/TableDataSource/Suppression/IVisualStudioSuppressionFixService.cs @@ -10,6 +10,12 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.Suppression /// TODO: Move to the core platform layer. internal interface IVisualStudioSuppressionFixService { + /// + /// Adds source suppressions for all the diagnostics in the error list, i.e. baseline all active issues. + /// + /// An optional project hierarchy object in the solution explorer. If non-null, then only the diagnostics from the project will be suppressed. + void AddSuppressions(IVsHierarchy projectHierarchyOpt); + /// /// Adds source suppressions for diagnostics. /// diff --git a/src/VisualStudio/Core/Def/Implementation/TableDataSource/Suppression/VisualStudioDiagnosticListSuppressionStateService.cs b/src/VisualStudio/Core/Def/Implementation/TableDataSource/Suppression/VisualStudioDiagnosticListSuppressionStateService.cs index 8b1fcb17408629fc1b255c16f7a9a301bec5a1d6..85c8721598cfc07891dad24deca3003844201b97 100644 --- a/src/VisualStudio/Core/Def/Implementation/TableDataSource/Suppression/VisualStudioDiagnosticListSuppressionStateService.cs +++ b/src/VisualStudio/Core/Def/Implementation/TableDataSource/Suppression/VisualStudioDiagnosticListSuppressionStateService.cs @@ -18,8 +18,8 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.TableDataSource /// /// Service to maintain information about the suppression state of specific set of items in the error list. /// - [Export(typeof(VisualStudioDiagnosticListSuppressionStateService))] - internal class VisualStudioDiagnosticListSuppressionStateService + [Export(typeof(IVisualStudioDiagnosticListSuppressionStateService))] + internal class VisualStudioDiagnosticListSuppressionStateService : IVisualStudioDiagnosticListSuppressionStateService { private readonly VisualStudioWorkspace _workspace; private readonly IVsUIShell _shellService; @@ -171,7 +171,7 @@ private static AbstractTableEntriesSnapshot GetEntriesSnapshot(I /// /// Gets objects for error list entries, filtered based on the given parameters. /// - public ImmutableArray GetItems(bool selectedEntriesOnly, bool isAddSuppression, bool isSuppressionInSource, CancellationToken cancellationToken) + public ImmutableArray GetItems(bool selectedEntriesOnly, bool isAddSuppression, bool isSuppressionInSource, bool onlyCompilerDiagnostics, CancellationToken cancellationToken) { var builder = ImmutableArray.CreateBuilder(); var entries = selectedEntriesOnly ? _tableControl.SelectedEntries : _tableControl.Entries; @@ -187,11 +187,17 @@ public ImmutableArray GetItems(bool selectedEntriesOnly, bool is diagnosticData = roslynSnapshot.GetItem(index)?.Primary; if (diagnosticData != null && diagnosticData.HasTextSpan) { + var isCompilerDiagnostic = SuppressionHelpers.IsCompilerDiagnostic(diagnosticData); + if (onlyCompilerDiagnostics && !isCompilerDiagnostic) + { + continue; + } + if (isAddSuppression) { // Compiler diagnostics can only be suppressed in source. if (!diagnosticData.IsSuppressed && - (isSuppressionInSource || !SuppressionHelpers.IsCompilerDiagnostic(diagnosticData))) + (isSuppressionInSource || !isCompilerDiagnostic)) { builder.Add(diagnosticData); } diff --git a/src/VisualStudio/Core/Def/Implementation/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs b/src/VisualStudio/Core/Def/Implementation/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs index adb29a2cfd294b30f2258c92aa9540a3f4a02939..d6c8af97e6a1c58f8767625dc1afc29070d8d909 100644 --- a/src/VisualStudio/Core/Def/Implementation/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs +++ b/src/VisualStudio/Core/Def/Implementation/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs @@ -16,11 +16,11 @@ internal partial class VisualStudioDiagnosticListTableCommandHandler [ImportingConstructor] public VisualStudioDiagnosticListTableCommandHandler( - VisualStudioSuppressionFixService suppressionFixService, - VisualStudioDiagnosticListSuppressionStateService suppressionStateService) + IVisualStudioSuppressionFixService suppressionFixService, + IVisualStudioDiagnosticListSuppressionStateService suppressionStateService) { - _suppressionFixService = suppressionFixService; - _suppressionStateService = suppressionStateService; + _suppressionFixService = (VisualStudioSuppressionFixService)suppressionFixService; + _suppressionStateService = (VisualStudioDiagnosticListSuppressionStateService)suppressionStateService; } public void Initialize(IServiceProvider serviceProvider) diff --git a/src/VisualStudio/Core/Def/Implementation/TableDataSource/Suppression/VisualStudioSuppressionFixService.cs b/src/VisualStudio/Core/Def/Implementation/TableDataSource/Suppression/VisualStudioSuppressionFixService.cs index efb1be0fcf2a7db79775761c444e15f3c12b269d..63a05cf238288075043cee74476052ab932eea19 100644 --- a/src/VisualStudio/Core/Def/Implementation/TableDataSource/Suppression/VisualStudioSuppressionFixService.cs +++ b/src/VisualStudio/Core/Def/Implementation/TableDataSource/Suppression/VisualStudioSuppressionFixService.cs @@ -23,8 +23,8 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.Suppression /// /// Service to compute and apply bulk suppression fixes. /// - [Export(typeof(VisualStudioSuppressionFixService))] - internal sealed class VisualStudioSuppressionFixService + [Export(typeof(IVisualStudioSuppressionFixService))] + internal sealed class VisualStudioSuppressionFixService : IVisualStudioSuppressionFixService { private readonly VisualStudioWorkspaceImpl _workspace; private readonly IWpfTableControl _tableControl; @@ -40,13 +40,13 @@ internal sealed class VisualStudioSuppressionFixService VisualStudioWorkspaceImpl workspace, IDiagnosticAnalyzerService diagnosticService, ICodeFixService codeFixService, - VisualStudioDiagnosticListSuppressionStateService suppressionStateService, + IVisualStudioDiagnosticListSuppressionStateService suppressionStateService, IWaitIndicator waitIndicator) { _workspace = workspace; _diagnosticService = diagnosticService; _codeFixService = codeFixService; - _suppressionStateService = suppressionStateService; + _suppressionStateService = (VisualStudioDiagnosticListSuppressionStateService)suppressionStateService; _waitIndicator = waitIndicator; _fixMultipleOccurencesService = workspace.Services.GetService(); @@ -54,6 +54,16 @@ internal sealed class VisualStudioSuppressionFixService _tableControl = errorList?.TableControl; } + public void AddSuppressions(IVsHierarchy projectHierarchyOpt) + { + Func shouldFixInProject = GetShouldFixInProjectDelegate(_workspace, projectHierarchyOpt); + + // Apply suppressions fix in global suppressions file for non-compiler diagnostics and + // in source only for compiler diagnostics. + ApplySuppressionFix(shouldFixInProject, selectedEntriesOnly: false, isAddSuppression: true, isSuppressionInSource: false, onlyCompilerDiagnostics: false, showPreviewChangesDialog: false); + ApplySuppressionFix(shouldFixInProject, selectedEntriesOnly: false, isAddSuppression: true, isSuppressionInSource: true, onlyCompilerDiagnostics: true, showPreviewChangesDialog: false); + } + public void AddSuppressions(bool selectedErrorListEntriesOnly, bool suppressInSource, IVsHierarchy projectHierarchyOpt) { if (_tableControl == null) @@ -62,7 +72,7 @@ public void AddSuppressions(bool selectedErrorListEntriesOnly, bool suppressInSo } Func shouldFixInProject = GetShouldFixInProjectDelegate(_workspace, projectHierarchyOpt); - ApplySuppressionFix(selectedErrorListEntriesOnly, suppressInSource, shouldFixInProject); + ApplySuppressionFix(shouldFixInProject, selectedErrorListEntriesOnly, isAddSuppression: true, isSuppressionInSource: suppressInSource, onlyCompilerDiagnostics: false, showPreviewChangesDialog: true); } private static Func GetShouldFixInProjectDelegate(VisualStudioWorkspaceImpl workspace, IVsHierarchy projectHierarchyOpt) @@ -92,7 +102,7 @@ public void RemoveSuppressions(bool selectedErrorListEntriesOnly, IVsHierarchy p // TODO } - private void ApplySuppressionFix(bool selectedEntriesOnly, bool suppressInSource, Func shouldFixInProject) + private void ApplySuppressionFix(Func shouldFixInProject, bool selectedEntriesOnly, bool isAddSuppression, bool isSuppressionInSource, bool onlyCompilerDiagnostics, bool showPreviewChangesDialog) { ImmutableDictionary> diagnosticsToFixMap = null; @@ -107,9 +117,10 @@ private void ApplySuppressionFix(bool selectedEntriesOnly, bool suppressInSource { var diagnosticsToFix = _suppressionStateService.GetItems( selectedEntriesOnly, - isAddSuppression: true, - isSuppressionInSource: suppressInSource, - cancellationToken: waitContext.CancellationToken); + isAddSuppression, + isSuppressionInSource, + onlyCompilerDiagnostics, + waitContext.CancellationToken); if (diagnosticsToFix.IsEmpty) { @@ -131,7 +142,7 @@ private void ApplySuppressionFix(bool selectedEntriesOnly, bool suppressInSource return; } - var equivalenceKey = suppressInSource ? FeaturesResources.SuppressWithPragma : FeaturesResources.SuppressWithGlobalSuppressMessage; + var equivalenceKey = isSuppressionInSource ? FeaturesResources.SuppressWithPragma : FeaturesResources.SuppressWithGlobalSuppressMessage; // We have different suppression fixers for every language. // So we need to group diagnostics by the containing project language and apply fixes separately. @@ -144,7 +155,7 @@ private void ApplySuppressionFix(bool selectedEntriesOnly, bool suppressInSource foreach (var group in groups) { var language = group.Key; - var previewChangesTitle = hasMultipleLangauges ? string.Format(ServicesVSResources.SuppressMultipleOccurrencesForLanguage, language) : ServicesVSResources.SuppressMultipleOccurrences; + var waitDialogAndPreviewChangesTitle = hasMultipleLangauges ? string.Format(ServicesVSResources.SuppressMultipleOccurrencesForLanguage, language) : ServicesVSResources.SuppressMultipleOccurrences; var waitDialogMessage = hasMultipleLangauges ? string.Format(ServicesVSResources.ComputingSuppressionFixForLanguage, language) : ServicesVSResources.ComputingSuppressionFix; ImmutableDictionary> documentDiagnosticsPerLanguage = null; @@ -192,8 +203,9 @@ private void ApplySuppressionFix(bool selectedEntriesOnly, bool suppressInSource suppressionFixer, suppressionFixer.GetFixAllProvider(), equivalenceKey, - previewChangesTitle, + waitDialogAndPreviewChangesTitle, waitDialogMessage, + showPreviewChangesDialog, CancellationToken.None); newSolution = _workspace.CurrentSolution;