From 067bf523fc4dba9b84b012a10f729630dc690dbe Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 3 Jul 2024 13:31:50 -0700 Subject: [PATCH 1/5] Remove more unused code --- .../Core/Def/ID.RoslynCommands.cs | 7 -- src/VisualStudio/Core/Def/RoslynPackage.cs | 2 +- ...StudioDiagnosticListTableCommandHandler.cs | 94 +------------------ 3 files changed, 2 insertions(+), 101 deletions(-) diff --git a/src/VisualStudio/Core/Def/ID.RoslynCommands.cs b/src/VisualStudio/Core/Def/ID.RoslynCommands.cs index a4f3cb0924c6b..35b69bdf39809 100644 --- a/src/VisualStudio/Core/Def/ID.RoslynCommands.cs +++ b/src/VisualStudio/Core/Def/ID.RoslynCommands.cs @@ -36,13 +36,6 @@ public static class RoslynCommands public const int AddSuppressionsInSource = 0x011f; public const int AddSuppressionsInSuppressionFile = 0x0120; public const int RemoveSuppressions = 0x0121; - public const int ErrorListSetSeveritySubMenu = 0x0122; - public const int ErrorListSetSeverityError = 0x0124; - public const int ErrorListSetSeverityWarning = 0x0125; - public const int ErrorListSetSeverityInfo = 0x0126; - public const int ErrorListSetSeverityHidden = 0x0127; - public const int ErrorListSetSeverityNone = 0x0128; - public const int ErrorListSetSeverityDefault = 0x0129; // Analyze and Code Cleanup menu IDs public const int AnalysisScopeDefault = 0x0131; diff --git a/src/VisualStudio/Core/Def/RoslynPackage.cs b/src/VisualStudio/Core/Def/RoslynPackage.cs index 7db8d50df8e0d..8dfd128dd3e99 100644 --- a/src/VisualStudio/Core/Def/RoslynPackage.cs +++ b/src/VisualStudio/Core/Def/RoslynPackage.cs @@ -228,7 +228,7 @@ protected override async Task LoadComponentsAsync(CancellationToken cancellation // we need to load it as early as possible since we can have errors from // package from each language very early await this.ComponentModel.GetService().InitializeAsync(this).ConfigureAwait(false); - await this.ComponentModel.GetService().InitializeAsync(this, cancellationToken).ConfigureAwait(false); + await this.ComponentModel.GetService().InitializeAsync(this).ConfigureAwait(false); await this.ComponentModel.GetService().InitializeAsync(this, cancellationToken).ConfigureAwait(false); await this.ComponentModel.GetService().InitializeAsync(this, cancellationToken).ConfigureAwait(false); diff --git a/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs b/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs index 39e1915142a9d..d5fb85a789cd9 100644 --- a/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs +++ b/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs @@ -7,12 +7,10 @@ using System.ComponentModel.Composition; using System.ComponentModel.Design; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Threading; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes.Configuration; -using Microsoft.CodeAnalysis.CodeFixes.Suppression; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.ErrorReporting; @@ -25,7 +23,6 @@ using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell.TableControl; using Microsoft.VisualStudio.Utilities; -using Roslyn.Utilities; using Task = System.Threading.Tasks.Task; namespace Microsoft.VisualStudio.LanguageServices.Implementation.TableDataSource; @@ -67,40 +64,10 @@ public VisualStudioDiagnosticListTableCommandHandler( _listener = listenerProvider.GetListener(FeatureAttribute.ErrorList); } - public async Task InitializeAsync(IAsyncServiceProvider serviceProvider, CancellationToken cancellationToken) + public async Task InitializeAsync(IAsyncServiceProvider serviceProvider) { var errorList = await serviceProvider.GetServiceAsync(_threadingContext.JoinableTaskFactory, throwOnFailure: false).ConfigureAwait(false); _tableControl = errorList?.TableControl; - - // Add command handlers for bulk suppression commands. - var menuCommandService = await serviceProvider.GetServiceAsync(_threadingContext.JoinableTaskFactory, throwOnFailure: false).ConfigureAwait(false); - if (menuCommandService != null) - { - await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); - AddErrorListSetSeverityMenuHandlers(menuCommandService); - - // The Add/Remove suppression(s) have been moved to the VS code analysis layer, so we don't add the commands here. - - // TODO: Figure out how to access menu commands registered by CodeAnalysisPackage and - // add the commands here if we cannot find the new command(s) in the code analysis layer. - - // AddSuppressionsCommandHandlers(menuCommandService); - } - } - - private void AddErrorListSetSeverityMenuHandlers(IMenuCommandService menuCommandService) - { - Contract.ThrowIfFalse(_threadingContext.HasMainThread); - - AddCommand(menuCommandService, ID.RoslynCommands.ErrorListSetSeveritySubMenu, delegate { }, OnErrorListSetSeveritySubMenuStatus); - - // Severity menu items - AddCommand(menuCommandService, ID.RoslynCommands.ErrorListSetSeverityDefault, SetSeverityHandler, delegate { }); - AddCommand(menuCommandService, ID.RoslynCommands.ErrorListSetSeverityError, SetSeverityHandler, delegate { }); - AddCommand(menuCommandService, ID.RoslynCommands.ErrorListSetSeverityWarning, SetSeverityHandler, delegate { }); - AddCommand(menuCommandService, ID.RoslynCommands.ErrorListSetSeverityInfo, SetSeverityHandler, delegate { }); - AddCommand(menuCommandService, ID.RoslynCommands.ErrorListSetSeverityHidden, SetSeverityHandler, delegate { }); - AddCommand(menuCommandService, ID.RoslynCommands.ErrorListSetSeverityNone, SetSeverityHandler, delegate { }); } /// @@ -155,41 +122,6 @@ private void OnAddSuppressionsInSuppressionFile(object sender, EventArgs e) private void OnRemoveSuppressions(object sender, EventArgs e) => _suppressionFixService.RemoveSuppressions(selectedErrorListEntriesOnly: true, projectHierarchy: null); - private void OnErrorListSetSeveritySubMenuStatus(object sender, EventArgs e) - { - // For now, we only enable the Set severity menu when a single configurable diagnostic is selected in the error list - // and we can update/create an editorconfig file for the configuration entry. - // In future, we can enable support for configuring in presence of multi-selection. - var command = (MenuCommand)sender; - var selectedEntry = TryGetSingleSelectedEntry(); - command.Visible = selectedEntry != null && - !SuppressionHelpers.IsNotConfigurableDiagnostic(selectedEntry) && - TryGetPathToAnalyzerConfigDoc(selectedEntry, out _, out _); - command.Enabled = command.Visible && !KnownUIContexts.SolutionBuildingContext.IsActive; - } - - private void SetSeverityHandler(object sender, EventArgs args) - { - var selectedItem = (MenuCommand)sender; - var reportDiagnostic = TryMapSelectedItemToReportDiagnostic(selectedItem); - if (reportDiagnostic == null) - { - return; - } - - var selectedDiagnostic = TryGetSingleSelectedEntry(); - if (selectedDiagnostic == null) - { - return; - } - - if (TryGetPathToAnalyzerConfigDoc(selectedDiagnostic, out var project, out _)) - { - // Fire and forget. - _ = SetSeverityHandlerAsync(reportDiagnostic.Value, selectedDiagnostic, project); - } - } - private async Task SetSeverityHandlerAsync(ReportDiagnostic reportDiagnostic, DiagnosticData selectedDiagnostic, Project project) { try @@ -234,34 +166,10 @@ async System.Threading.Tasks.Task ConfigureSeverityAsync(CancellationT } } - private static DiagnosticData? TryGetSingleSelectedEntry() - { - return null; - } - private bool TryGetPathToAnalyzerConfigDoc(DiagnosticData selectedDiagnostic, [NotNullWhen(true)] out Project? project, [NotNullWhen(true)] out string? pathToAnalyzerConfigDoc) { project = _workspace.CurrentSolution.GetProject(selectedDiagnostic.ProjectId); pathToAnalyzerConfigDoc = project?.TryGetAnalyzerConfigPathForProjectConfiguration(); return pathToAnalyzerConfigDoc is not null; } - - private static ReportDiagnostic? TryMapSelectedItemToReportDiagnostic(MenuCommand selectedItem) - { - if (selectedItem.CommandID.Guid == Guids.RoslynGroupId) - { - return selectedItem.CommandID.ID switch - { - ID.RoslynCommands.ErrorListSetSeverityDefault => ReportDiagnostic.Default, - ID.RoslynCommands.ErrorListSetSeverityError => ReportDiagnostic.Error, - ID.RoslynCommands.ErrorListSetSeverityWarning => ReportDiagnostic.Warn, - ID.RoslynCommands.ErrorListSetSeverityInfo => ReportDiagnostic.Info, - ID.RoslynCommands.ErrorListSetSeverityHidden => ReportDiagnostic.Hidden, - ID.RoslynCommands.ErrorListSetSeverityNone => ReportDiagnostic.Suppress, - _ => (ReportDiagnostic?)null - }; - } - - return null; - } } From a6fa0b8c9b21e4e298ce5f2047fe7fa72d5c00b4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 3 Jul 2024 13:36:11 -0700 Subject: [PATCH 2/5] Remove more unused code --- ...StudioDiagnosticListTableCommandHandler.cs | 59 ------------------- 1 file changed, 59 deletions(-) diff --git a/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs b/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs index d5fb85a789cd9..853d69a7b3c7b 100644 --- a/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs +++ b/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs @@ -70,58 +70,6 @@ public async Task InitializeAsync(IAsyncServiceProvider serviceProvider) _tableControl = errorList?.TableControl; } - /// - /// Add a command handler and status query handler for a menu item - /// - private static OleMenuCommand AddCommand( - IMenuCommandService menuCommandService, - int commandId, - EventHandler invokeHandler, - EventHandler beforeQueryStatus) - { - var commandIdWithGroupId = new CommandID(Guids.RoslynGroupId, commandId); - var command = new OleMenuCommand(invokeHandler, delegate { }, beforeQueryStatus, commandIdWithGroupId); - menuCommandService.AddCommand(command); - return command; - } - - private void OnAddSuppressionsStatus(object sender, EventArgs e) - { - var command = (MenuCommand)sender; - command.Visible = _suppressionStateService.CanSuppressSelectedEntries; - command.Enabled = command.Visible && !KnownUIContexts.SolutionBuildingContext.IsActive; - } - - private void OnRemoveSuppressionsStatus(object sender, EventArgs e) - { - var command = (MenuCommand)sender; - command.Visible = _suppressionStateService.CanRemoveSuppressionsSelectedEntries; - command.Enabled = command.Visible && !KnownUIContexts.SolutionBuildingContext.IsActive; - } - - private void OnAddSuppressionsInSourceStatus(object sender, EventArgs e) - { - var command = (MenuCommand)sender; - command.Visible = _suppressionStateService.CanSuppressSelectedEntriesInSource; - command.Enabled = command.Visible && !KnownUIContexts.SolutionBuildingContext.IsActive; - } - - private void OnAddSuppressionsInSuppressionFileStatus(object sender, EventArgs e) - { - var command = (MenuCommand)sender; - command.Visible = _suppressionStateService.CanSuppressSelectedEntriesInSuppressionFiles; - command.Enabled = command.Visible && !KnownUIContexts.SolutionBuildingContext.IsActive; - } - - private void OnAddSuppressionsInSource(object sender, EventArgs e) - => _suppressionFixService.AddSuppressions(selectedErrorListEntriesOnly: true, suppressInSource: true, projectHierarchy: null); - - private void OnAddSuppressionsInSuppressionFile(object sender, EventArgs e) - => _suppressionFixService.AddSuppressions(selectedErrorListEntriesOnly: true, suppressInSource: false, projectHierarchy: null); - - private void OnRemoveSuppressions(object sender, EventArgs e) - => _suppressionFixService.RemoveSuppressions(selectedErrorListEntriesOnly: true, projectHierarchy: null); - private async Task SetSeverityHandlerAsync(ReportDiagnostic reportDiagnostic, DiagnosticData selectedDiagnostic, Project project) { try @@ -165,11 +113,4 @@ async System.Threading.Tasks.Task ConfigureSeverityAsync(CancellationT return await ConfigurationUpdater.ConfigureSeverityAsync(reportDiagnostic, diagnostic, project, cancellationToken).ConfigureAwait(false); } } - - private bool TryGetPathToAnalyzerConfigDoc(DiagnosticData selectedDiagnostic, [NotNullWhen(true)] out Project? project, [NotNullWhen(true)] out string? pathToAnalyzerConfigDoc) - { - project = _workspace.CurrentSolution.GetProject(selectedDiagnostic.ProjectId); - pathToAnalyzerConfigDoc = project?.TryGetAnalyzerConfigPathForProjectConfiguration(); - return pathToAnalyzerConfigDoc is not null; - } } From 6f6824c69345040e8ad4a6d8920aa123506410ea Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 3 Jul 2024 13:50:28 -0700 Subject: [PATCH 3/5] Remove uncalled method --- ...StudioDiagnosticListTableCommandHandler.cs | 44 ------------------- 1 file changed, 44 deletions(-) diff --git a/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs b/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs index 853d69a7b3c7b..40f4381256c18 100644 --- a/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs +++ b/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs @@ -69,48 +69,4 @@ public async Task InitializeAsync(IAsyncServiceProvider serviceProvider) var errorList = await serviceProvider.GetServiceAsync(_threadingContext.JoinableTaskFactory, throwOnFailure: false).ConfigureAwait(false); _tableControl = errorList?.TableControl; } - - private async Task SetSeverityHandlerAsync(ReportDiagnostic reportDiagnostic, DiagnosticData selectedDiagnostic, Project project) - { - try - { - using var token = _listener.BeginAsyncOperation(nameof(SetSeverityHandlerAsync)); - using var context = _uiThreadOperationExecutor.BeginExecute( - title: ServicesVSResources.Updating_severity, - defaultDescription: ServicesVSResources.Updating_severity, - allowCancellation: true, - showProgress: true); - - var newSolution = await ConfigureSeverityAsync(context.UserCancellationToken).ConfigureAwait(false); - var operations = ImmutableArray.Create(new ApplyChangesOperation(newSolution)); - using var scope = context.AddScope(allowCancellation: true, ServicesVSResources.Updating_severity); - await _editHandlerService.ApplyAsync( - _workspace, - project.Solution, - fromDocument: null, - operations, - title: ServicesVSResources.Updating_severity, - scope.GetCodeAnalysisProgress(), - context.UserCancellationToken).ConfigureAwait(false); - - // Kick off diagnostic re-analysis for affected document so that the configured diagnostic gets refreshed. - if (selectedDiagnostic.DocumentId != null) - _diagnosticService.RequestDiagnosticRefresh(); - } - catch (OperationCanceledException) - { - } - catch (Exception ex) when (FatalError.ReportAndCatch(ex)) - { - } - - return; - - // Local functions. - async System.Threading.Tasks.Task ConfigureSeverityAsync(CancellationToken cancellationToken) - { - var diagnostic = await selectedDiagnostic.ToDiagnosticAsync(project, cancellationToken).ConfigureAwait(false); - return await ConfigurationUpdater.ConfigureSeverityAsync(reportDiagnostic, diagnostic, project, cancellationToken).ConfigureAwait(false); - } - } } From a1cb67cea27ce0a53ab978a657f25fa051893117 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 3 Jul 2024 13:52:12 -0700 Subject: [PATCH 4/5] remove type that now serves no purpose --- src/VisualStudio/Core/Def/RoslynPackage.cs | 2 - ...StudioDiagnosticListTableCommandHandler.cs | 72 ------------------- 2 files changed, 74 deletions(-) delete mode 100644 src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs diff --git a/src/VisualStudio/Core/Def/RoslynPackage.cs b/src/VisualStudio/Core/Def/RoslynPackage.cs index 8dfd128dd3e99..1ec2bec5601c6 100644 --- a/src/VisualStudio/Core/Def/RoslynPackage.cs +++ b/src/VisualStudio/Core/Def/RoslynPackage.cs @@ -13,7 +13,6 @@ using Microsoft.CodeAnalysis.Common; using Microsoft.CodeAnalysis.EditAndContinue; using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.AsyncCompletion; -using Microsoft.CodeAnalysis.Editor.QuickInfo; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.Notification; @@ -228,7 +227,6 @@ protected override async Task LoadComponentsAsync(CancellationToken cancellation // we need to load it as early as possible since we can have errors from // package from each language very early await this.ComponentModel.GetService().InitializeAsync(this).ConfigureAwait(false); - await this.ComponentModel.GetService().InitializeAsync(this).ConfigureAwait(false); await this.ComponentModel.GetService().InitializeAsync(this, cancellationToken).ConfigureAwait(false); await this.ComponentModel.GetService().InitializeAsync(this, cancellationToken).ConfigureAwait(false); diff --git a/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs b/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs deleted file mode 100644 index 40f4381256c18..0000000000000 --- a/src/VisualStudio/Core/Def/TableDataSource/Suppression/VisualStudioDiagnosticListTableCommandHandler.cs +++ /dev/null @@ -1,72 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Immutable; -using System.ComponentModel.Composition; -using System.ComponentModel.Design; -using System.Diagnostics.CodeAnalysis; -using System.Threading; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CodeActions; -using Microsoft.CodeAnalysis.CodeFixes.Configuration; -using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Editor.Shared.Utilities; -using Microsoft.CodeAnalysis.ErrorReporting; -using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Progress; -using Microsoft.CodeAnalysis.Shared.Extensions; -using Microsoft.CodeAnalysis.Shared.TestHooks; -using Microsoft.VisualStudio.LanguageServices.Implementation.Suppression; -using Microsoft.VisualStudio.Shell; -using Microsoft.VisualStudio.Shell.Interop; -using Microsoft.VisualStudio.Shell.TableControl; -using Microsoft.VisualStudio.Utilities; -using Task = System.Threading.Tasks.Task; - -namespace Microsoft.VisualStudio.LanguageServices.Implementation.TableDataSource; - -[Export(typeof(VisualStudioDiagnosticListTableCommandHandler))] -internal partial class VisualStudioDiagnosticListTableCommandHandler -{ - private readonly IThreadingContext _threadingContext; - private readonly VisualStudioWorkspace _workspace; - private readonly VisualStudioSuppressionFixService _suppressionFixService; - private readonly VisualStudioDiagnosticListSuppressionStateService _suppressionStateService; - private readonly IUIThreadOperationExecutor _uiThreadOperationExecutor; - private readonly IDiagnosticAnalyzerService _diagnosticService; - private readonly ICodeActionEditHandlerService _editHandlerService; - private readonly IAsynchronousOperationListener _listener; - - private IWpfTableControl? _tableControl; - - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public VisualStudioDiagnosticListTableCommandHandler( - IThreadingContext threadingContext, - SVsServiceProvider serviceProvider, - VisualStudioWorkspace workspace, - IVisualStudioSuppressionFixService suppressionFixService, - VisualStudioDiagnosticListSuppressionStateService suppressionStateService, - IUIThreadOperationExecutor uiThreadOperationExecutor, - IDiagnosticAnalyzerService diagnosticService, - ICodeActionEditHandlerService editHandlerService, - IAsynchronousOperationListenerProvider listenerProvider) - { - _threadingContext = threadingContext; - _workspace = workspace; - _suppressionFixService = (VisualStudioSuppressionFixService)suppressionFixService; - _suppressionStateService = suppressionStateService; - _uiThreadOperationExecutor = uiThreadOperationExecutor; - _diagnosticService = diagnosticService; - _editHandlerService = editHandlerService; - _listener = listenerProvider.GetListener(FeatureAttribute.ErrorList); - } - - public async Task InitializeAsync(IAsyncServiceProvider serviceProvider) - { - var errorList = await serviceProvider.GetServiceAsync(_threadingContext.JoinableTaskFactory, throwOnFailure: false).ConfigureAwait(false); - _tableControl = errorList?.TableControl; - } -} From a1007090a49a4680eb7e47d72f17391644bfc2f3 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Jul 2024 16:24:31 -0700 Subject: [PATCH 5/5] Remove more --- src/VisualStudio/Core/Def/ID.RoslynCommands.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/VisualStudio/Core/Def/ID.RoslynCommands.cs b/src/VisualStudio/Core/Def/ID.RoslynCommands.cs index 35b69bdf39809..3b35d239777e2 100644 --- a/src/VisualStudio/Core/Def/ID.RoslynCommands.cs +++ b/src/VisualStudio/Core/Def/ID.RoslynCommands.cs @@ -31,12 +31,6 @@ public static class RoslynCommands public const int SetActiveRuleSet = 0x0118; public const int SetSeverityDefault = 0x011b; - // Error list context menu command IDs for suppressions and setting severity - public const int AddSuppressions = 0x011d; - public const int AddSuppressionsInSource = 0x011f; - public const int AddSuppressionsInSuppressionFile = 0x0120; - public const int RemoveSuppressions = 0x0121; - // Analyze and Code Cleanup menu IDs public const int AnalysisScopeDefault = 0x0131; public const int AnalysisScopeCurrentDocument = 0x0132;