From e08c3efa3c6c44d760452d6d2b3b724182117b5a Mon Sep 17 00:00:00 2001 From: heku Date: Sat, 18 Mar 2023 16:31:14 +0800 Subject: [PATCH] Remove unnecessary async and await code (#989) --- CodeMaidShared/Helpers/SettingsMonitor.cs | 10 +++++----- CodeMaidShared/Integration/Commands/AboutCommand.cs | 4 ++-- .../Commands/BuildProgressToolWindowCommand.cs | 4 ++-- .../Integration/Commands/CleanupActiveCodeCommand.cs | 4 ++-- .../Integration/Commands/CleanupAllCodeCommand.cs | 4 ++-- .../Integration/Commands/CleanupOpenCodeCommand.cs | 4 ++-- .../Integration/Commands/CleanupSelectedCodeCommand.cs | 4 ++-- .../Integration/Commands/CloseAllReadOnlyCommand.cs | 4 ++-- .../Commands/CollapseAllSolutionExplorerCommand.cs | 4 ++-- .../CollapseSelectedSolutionExplorerCommand.cs | 4 ++-- .../Integration/Commands/CommentFormatCommand.cs | 4 ++-- .../Commands/FindInSolutionExplorerCommand.cs | 4 ++-- .../Integration/Commands/JoinLinesCommand.cs | 4 ++-- CodeMaidShared/Integration/Commands/OptionsCommand.cs | 4 ++-- .../Integration/Commands/ReadOnlyToggleCommand.cs | 6 +++--- .../Integration/Commands/RemoveRegionCommand.cs | 4 ++-- .../Commands/ReorganizeActiveCodeCommand.cs | 4 ++-- .../Commands/SettingCleanupOnSaveCommand.cs | 4 ++-- .../Integration/Commands/SortLinesCommand.cs | 4 ++-- .../Integration/Commands/SpadeContextDeleteCommand.cs | 4 ++-- .../Commands/SpadeContextFindReferencesCommand.cs | 4 ++-- .../Commands/SpadeContextInsertRegionCommand.cs | 4 ++-- .../Commands/SpadeContextRemoveRegionCommand.cs | 4 ++-- .../Integration/Commands/SpadeOptionsCommand.cs | 4 ++-- .../Integration/Commands/SpadeRefreshCommand.cs | 4 ++-- .../Integration/Commands/SpadeSearchCommand.cs | 4 ++-- .../Integration/Commands/SpadeSortOrderAlphaCommand.cs | 4 ++-- .../Integration/Commands/SpadeSortOrderFileCommand.cs | 4 ++-- .../Integration/Commands/SpadeSortOrderTypeCommand.cs | 4 ++-- .../Integration/Commands/SpadeToolWindowCommand.cs | 4 ++-- .../Integration/Commands/SwitchFileCommand.cs | 4 ++-- CodeMaidShared/Integration/Events/BaseEventListener.cs | 6 ++---- .../Integration/Events/BuildProgressEventListener.cs | 4 ++-- .../Integration/Events/DocumentEventListener.cs | 4 ++-- .../Events/RunningDocumentTableEventListener.cs | 9 +++------ .../Integration/Events/SolutionEventListener.cs | 4 ++-- .../Integration/Events/TextEditorEventListener.cs | 4 ++-- .../Integration/Events/WindowEventListener.cs | 4 ++-- CodeMaidShared/UI/ToolWindows/Spade/SpadeToolWindow.cs | 4 ++-- 39 files changed, 83 insertions(+), 88 deletions(-) diff --git a/CodeMaidShared/Helpers/SettingsMonitor.cs b/CodeMaidShared/Helpers/SettingsMonitor.cs index 6f5d4c916..4a46011ae 100644 --- a/CodeMaidShared/Helpers/SettingsMonitor.cs +++ b/CodeMaidShared/Helpers/SettingsMonitor.cs @@ -23,18 +23,18 @@ public SettingsMonitor(TSetting settings, JoinableTaskFactory joinableTaskFactor _settings.SettingsSaving += OnSettingsSaving; } - public async Task WatchAsync(Expression> setting, Func changedCallback) + public Task WatchAsync(Expression> setting, Func changedCallback) { var settingName = (setting.Body as MemberExpression).Member.Name; - await WatchAsync(new[] { settingName }, async values => await changedCallback(values[0])); + return WatchAsync(new[] { settingName }, values => changedCallback(values[0])); } - public async Task WatchAsync(string[] settings, Func changedCallback) + public Task WatchAsync(string[] settings, Func changedCallback) { - await WatchAsync(settings, async (object[] values) => + return WatchAsync(settings, (object[] values) => { var typedValues = Array.ConvertAll(values, v => (TValue)v); - await changedCallback(typedValues); + return changedCallback(typedValues); }); } diff --git a/CodeMaidShared/Integration/Commands/AboutCommand.cs b/CodeMaidShared/Integration/Commands/AboutCommand.cs index f7875136e..f78ac8444 100644 --- a/CodeMaidShared/Integration/Commands/AboutCommand.cs +++ b/CodeMaidShared/Integration/Commands/AboutCommand.cs @@ -27,10 +27,10 @@ private AboutCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new AboutCommand(package); - await Instance.SwitchAsync(on: true); + return Instance.SwitchAsync(on: true); } /// diff --git a/CodeMaidShared/Integration/Commands/BuildProgressToolWindowCommand.cs b/CodeMaidShared/Integration/Commands/BuildProgressToolWindowCommand.cs index 49f001e03..09891444c 100644 --- a/CodeMaidShared/Integration/Commands/BuildProgressToolWindowCommand.cs +++ b/CodeMaidShared/Integration/Commands/BuildProgressToolWindowCommand.cs @@ -46,10 +46,10 @@ private IVsWindowFrame BuildProgressWindowFrame /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new BuildProgressToolWindowCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_BuildProgressToolWindow, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_BuildProgressToolWindow, Instance.SwitchAsync); } public override async Task SwitchAsync(bool on) diff --git a/CodeMaidShared/Integration/Commands/CleanupActiveCodeCommand.cs b/CodeMaidShared/Integration/Commands/CleanupActiveCodeCommand.cs index 2aa47ab6b..731af468d 100644 --- a/CodeMaidShared/Integration/Commands/CleanupActiveCodeCommand.cs +++ b/CodeMaidShared/Integration/Commands/CleanupActiveCodeCommand.cs @@ -42,10 +42,10 @@ internal CleanupActiveCodeCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new CleanupActiveCodeCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_CleanupActiveCode, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_CleanupActiveCode, Instance.SwitchAsync); } /// diff --git a/CodeMaidShared/Integration/Commands/CleanupAllCodeCommand.cs b/CodeMaidShared/Integration/Commands/CleanupAllCodeCommand.cs index b6d29c6fc..4657d1050 100644 --- a/CodeMaidShared/Integration/Commands/CleanupAllCodeCommand.cs +++ b/CodeMaidShared/Integration/Commands/CleanupAllCodeCommand.cs @@ -46,10 +46,10 @@ private IEnumerable AllProjectItems /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new CleanupAllCodeCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_CleanupAllCode, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_CleanupAllCode, Instance.SwitchAsync); } /// diff --git a/CodeMaidShared/Integration/Commands/CleanupOpenCodeCommand.cs b/CodeMaidShared/Integration/Commands/CleanupOpenCodeCommand.cs index 39f1599f2..c2e676f07 100644 --- a/CodeMaidShared/Integration/Commands/CleanupOpenCodeCommand.cs +++ b/CodeMaidShared/Integration/Commands/CleanupOpenCodeCommand.cs @@ -50,10 +50,10 @@ private IEnumerable OpenDocuments /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new CleanupOpenCodeCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_CleanupOpenCode, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_CleanupOpenCode, Instance.SwitchAsync); } /// diff --git a/CodeMaidShared/Integration/Commands/CleanupSelectedCodeCommand.cs b/CodeMaidShared/Integration/Commands/CleanupSelectedCodeCommand.cs index 3d3dcb2d4..8c409017e 100644 --- a/CodeMaidShared/Integration/Commands/CleanupSelectedCodeCommand.cs +++ b/CodeMaidShared/Integration/Commands/CleanupSelectedCodeCommand.cs @@ -44,10 +44,10 @@ private IEnumerable SelectedProjectItems /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new CleanupSelectedCodeCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_CleanupSelectedCode, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_CleanupSelectedCode, Instance.SwitchAsync); } /// diff --git a/CodeMaidShared/Integration/Commands/CloseAllReadOnlyCommand.cs b/CodeMaidShared/Integration/Commands/CloseAllReadOnlyCommand.cs index 86ae54d53..79bb71f2b 100644 --- a/CodeMaidShared/Integration/Commands/CloseAllReadOnlyCommand.cs +++ b/CodeMaidShared/Integration/Commands/CloseAllReadOnlyCommand.cs @@ -28,10 +28,10 @@ internal CloseAllReadOnlyCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new CloseAllReadOnlyCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_CloseAllReadOnly, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_CloseAllReadOnly, Instance.SwitchAsync); } /// diff --git a/CodeMaidShared/Integration/Commands/CollapseAllSolutionExplorerCommand.cs b/CodeMaidShared/Integration/Commands/CollapseAllSolutionExplorerCommand.cs index 83178cbb9..69df0909e 100644 --- a/CodeMaidShared/Integration/Commands/CollapseAllSolutionExplorerCommand.cs +++ b/CodeMaidShared/Integration/Commands/CollapseAllSolutionExplorerCommand.cs @@ -39,10 +39,10 @@ internal CollapseAllSolutionExplorerCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new CollapseAllSolutionExplorerCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_CollapseAllSolutionExplorer, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_CollapseAllSolutionExplorer, Instance.SwitchAsync); } /// diff --git a/CodeMaidShared/Integration/Commands/CollapseSelectedSolutionExplorerCommand.cs b/CodeMaidShared/Integration/Commands/CollapseSelectedSolutionExplorerCommand.cs index 4bc7a8bb5..637ced67e 100644 --- a/CodeMaidShared/Integration/Commands/CollapseSelectedSolutionExplorerCommand.cs +++ b/CodeMaidShared/Integration/Commands/CollapseSelectedSolutionExplorerCommand.cs @@ -35,10 +35,10 @@ internal CollapseSelectedSolutionExplorerCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new CollapseSelectedSolutionExplorerCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_CollapseSelectedSolutionExplorer, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_CollapseSelectedSolutionExplorer, Instance.SwitchAsync); } /// diff --git a/CodeMaidShared/Integration/Commands/CommentFormatCommand.cs b/CodeMaidShared/Integration/Commands/CommentFormatCommand.cs index 1b178c268..ed3f5fb34 100644 --- a/CodeMaidShared/Integration/Commands/CommentFormatCommand.cs +++ b/CodeMaidShared/Integration/Commands/CommentFormatCommand.cs @@ -40,10 +40,10 @@ internal CommentFormatCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new CommentFormatCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_CommentFormat, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_CommentFormat, Instance.SwitchAsync); } /// diff --git a/CodeMaidShared/Integration/Commands/FindInSolutionExplorerCommand.cs b/CodeMaidShared/Integration/Commands/FindInSolutionExplorerCommand.cs index ac7fc2fc1..c64948af9 100644 --- a/CodeMaidShared/Integration/Commands/FindInSolutionExplorerCommand.cs +++ b/CodeMaidShared/Integration/Commands/FindInSolutionExplorerCommand.cs @@ -36,10 +36,10 @@ internal FindInSolutionExplorerCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new FindInSolutionExplorerCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_FindInSolutionExplorer, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_FindInSolutionExplorer, Instance.SwitchAsync); } /// diff --git a/CodeMaidShared/Integration/Commands/JoinLinesCommand.cs b/CodeMaidShared/Integration/Commands/JoinLinesCommand.cs index 13ce85f8e..a3543f650 100644 --- a/CodeMaidShared/Integration/Commands/JoinLinesCommand.cs +++ b/CodeMaidShared/Integration/Commands/JoinLinesCommand.cs @@ -37,10 +37,10 @@ internal JoinLinesCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new JoinLinesCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_JoinLines, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_JoinLines, Instance.SwitchAsync); } /// diff --git a/CodeMaidShared/Integration/Commands/OptionsCommand.cs b/CodeMaidShared/Integration/Commands/OptionsCommand.cs index 106bd7bc2..0080d25da 100644 --- a/CodeMaidShared/Integration/Commands/OptionsCommand.cs +++ b/CodeMaidShared/Integration/Commands/OptionsCommand.cs @@ -27,10 +27,10 @@ internal OptionsCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new OptionsCommand(package); - await Instance.SwitchAsync(on: true); + return Instance.SwitchAsync(on: true); } /// diff --git a/CodeMaidShared/Integration/Commands/ReadOnlyToggleCommand.cs b/CodeMaidShared/Integration/Commands/ReadOnlyToggleCommand.cs index 0ad79e358..1506e240e 100644 --- a/CodeMaidShared/Integration/Commands/ReadOnlyToggleCommand.cs +++ b/CodeMaidShared/Integration/Commands/ReadOnlyToggleCommand.cs @@ -31,10 +31,10 @@ internal ReadOnlyToggleCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new ReadOnlyToggleCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_ReadOnlyToggle, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_ReadOnlyToggle, Instance.SwitchAsync); } /// @@ -64,7 +64,7 @@ protected override void OnExecute() } catch (Exception ex) { - OutputWindowHelper.ExceptionWriteLine($"{ Resources.UnableToToggleReadOnlyStateOn}'{document.FullName}'", ex); + OutputWindowHelper.ExceptionWriteLine($"{Resources.UnableToToggleReadOnlyStateOn}'{document.FullName}'", ex); } } } diff --git a/CodeMaidShared/Integration/Commands/RemoveRegionCommand.cs b/CodeMaidShared/Integration/Commands/RemoveRegionCommand.cs index 3d63917e2..8a1003b01 100644 --- a/CodeMaidShared/Integration/Commands/RemoveRegionCommand.cs +++ b/CodeMaidShared/Integration/Commands/RemoveRegionCommand.cs @@ -52,10 +52,10 @@ private enum RegionCommandScope /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new RemoveRegionCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_RemoveRegion, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_RemoveRegion, Instance.SwitchAsync); } /// diff --git a/CodeMaidShared/Integration/Commands/ReorganizeActiveCodeCommand.cs b/CodeMaidShared/Integration/Commands/ReorganizeActiveCodeCommand.cs index d49c58de7..e4faecb7b 100644 --- a/CodeMaidShared/Integration/Commands/ReorganizeActiveCodeCommand.cs +++ b/CodeMaidShared/Integration/Commands/ReorganizeActiveCodeCommand.cs @@ -37,10 +37,10 @@ internal ReorganizeActiveCodeCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new ReorganizeActiveCodeCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_ReorganizeActiveCode, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_ReorganizeActiveCode, Instance.SwitchAsync); } /// diff --git a/CodeMaidShared/Integration/Commands/SettingCleanupOnSaveCommand.cs b/CodeMaidShared/Integration/Commands/SettingCleanupOnSaveCommand.cs index 1977cbbd9..76b85ee14 100644 --- a/CodeMaidShared/Integration/Commands/SettingCleanupOnSaveCommand.cs +++ b/CodeMaidShared/Integration/Commands/SettingCleanupOnSaveCommand.cs @@ -41,10 +41,10 @@ public bool CleanupOnSave /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new SettingCleanupOnSaveCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_SettingCleanupOnSave, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_SettingCleanupOnSave, Instance.SwitchAsync); } /// diff --git a/CodeMaidShared/Integration/Commands/SortLinesCommand.cs b/CodeMaidShared/Integration/Commands/SortLinesCommand.cs index 3e5dd0105..2fd632471 100644 --- a/CodeMaidShared/Integration/Commands/SortLinesCommand.cs +++ b/CodeMaidShared/Integration/Commands/SortLinesCommand.cs @@ -41,10 +41,10 @@ internal SortLinesCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new SortLinesCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_SortLines, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_SortLines, Instance.SwitchAsync); } /// diff --git a/CodeMaidShared/Integration/Commands/SpadeContextDeleteCommand.cs b/CodeMaidShared/Integration/Commands/SpadeContextDeleteCommand.cs index a96e358e1..c758bff7f 100644 --- a/CodeMaidShared/Integration/Commands/SpadeContextDeleteCommand.cs +++ b/CodeMaidShared/Integration/Commands/SpadeContextDeleteCommand.cs @@ -35,10 +35,10 @@ internal SpadeContextDeleteCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new SpadeContextDeleteCommand(package); - await Instance.SwitchAsync(on: true); + return Instance.SwitchAsync(on: true); } /// diff --git a/CodeMaidShared/Integration/Commands/SpadeContextFindReferencesCommand.cs b/CodeMaidShared/Integration/Commands/SpadeContextFindReferencesCommand.cs index c9cfae7be..11b0b8907 100644 --- a/CodeMaidShared/Integration/Commands/SpadeContextFindReferencesCommand.cs +++ b/CodeMaidShared/Integration/Commands/SpadeContextFindReferencesCommand.cs @@ -29,10 +29,10 @@ internal SpadeContextFindReferencesCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new SpadeContextFindReferencesCommand(package); - await Instance.SwitchAsync(on: true); + return Instance.SwitchAsync(on: true); } /// diff --git a/CodeMaidShared/Integration/Commands/SpadeContextInsertRegionCommand.cs b/CodeMaidShared/Integration/Commands/SpadeContextInsertRegionCommand.cs index c6e9e6f68..bb37d9aac 100644 --- a/CodeMaidShared/Integration/Commands/SpadeContextInsertRegionCommand.cs +++ b/CodeMaidShared/Integration/Commands/SpadeContextInsertRegionCommand.cs @@ -36,10 +36,10 @@ internal SpadeContextInsertRegionCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new SpadeContextInsertRegionCommand(package); - await Instance.SwitchAsync(on: true); + return Instance.SwitchAsync(on: true); } /// diff --git a/CodeMaidShared/Integration/Commands/SpadeContextRemoveRegionCommand.cs b/CodeMaidShared/Integration/Commands/SpadeContextRemoveRegionCommand.cs index c9af9945b..8f423c0df 100644 --- a/CodeMaidShared/Integration/Commands/SpadeContextRemoveRegionCommand.cs +++ b/CodeMaidShared/Integration/Commands/SpadeContextRemoveRegionCommand.cs @@ -32,10 +32,10 @@ internal SpadeContextRemoveRegionCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new SpadeContextRemoveRegionCommand(package); - await Instance.SwitchAsync(on: true); + return Instance.SwitchAsync(on: true); } /// diff --git a/CodeMaidShared/Integration/Commands/SpadeOptionsCommand.cs b/CodeMaidShared/Integration/Commands/SpadeOptionsCommand.cs index 6d3b69b46..4b8c27840 100644 --- a/CodeMaidShared/Integration/Commands/SpadeOptionsCommand.cs +++ b/CodeMaidShared/Integration/Commands/SpadeOptionsCommand.cs @@ -28,10 +28,10 @@ internal SpadeOptionsCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new SpadeOptionsCommand(package); - await Instance.SwitchAsync(on: true); + return Instance.SwitchAsync(on: true); } /// diff --git a/CodeMaidShared/Integration/Commands/SpadeRefreshCommand.cs b/CodeMaidShared/Integration/Commands/SpadeRefreshCommand.cs index 569cfb49b..036449313 100644 --- a/CodeMaidShared/Integration/Commands/SpadeRefreshCommand.cs +++ b/CodeMaidShared/Integration/Commands/SpadeRefreshCommand.cs @@ -26,10 +26,10 @@ internal SpadeRefreshCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new SpadeRefreshCommand(package); - await Instance.SwitchAsync(on: true); + return Instance.SwitchAsync(on: true); } /// diff --git a/CodeMaidShared/Integration/Commands/SpadeSearchCommand.cs b/CodeMaidShared/Integration/Commands/SpadeSearchCommand.cs index 9bdfa2d83..cefb6fec6 100644 --- a/CodeMaidShared/Integration/Commands/SpadeSearchCommand.cs +++ b/CodeMaidShared/Integration/Commands/SpadeSearchCommand.cs @@ -26,10 +26,10 @@ internal SpadeSearchCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new SpadeSearchCommand(package); - await Instance.SwitchAsync(on: true); + return Instance.SwitchAsync(on: true); } /// diff --git a/CodeMaidShared/Integration/Commands/SpadeSortOrderAlphaCommand.cs b/CodeMaidShared/Integration/Commands/SpadeSortOrderAlphaCommand.cs index cd3035f06..37fab0408 100644 --- a/CodeMaidShared/Integration/Commands/SpadeSortOrderAlphaCommand.cs +++ b/CodeMaidShared/Integration/Commands/SpadeSortOrderAlphaCommand.cs @@ -27,10 +27,10 @@ internal SpadeSortOrderAlphaCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new SpadeSortOrderAlphaCommand(package); - await Instance.SwitchAsync(on: true); + return Instance.SwitchAsync(on: true); } /// diff --git a/CodeMaidShared/Integration/Commands/SpadeSortOrderFileCommand.cs b/CodeMaidShared/Integration/Commands/SpadeSortOrderFileCommand.cs index b2b7e2691..1bc24d9e2 100644 --- a/CodeMaidShared/Integration/Commands/SpadeSortOrderFileCommand.cs +++ b/CodeMaidShared/Integration/Commands/SpadeSortOrderFileCommand.cs @@ -27,10 +27,10 @@ internal SpadeSortOrderFileCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new SpadeSortOrderFileCommand(package); - await Instance.SwitchAsync(on: true); + return Instance.SwitchAsync(on: true); } /// diff --git a/CodeMaidShared/Integration/Commands/SpadeSortOrderTypeCommand.cs b/CodeMaidShared/Integration/Commands/SpadeSortOrderTypeCommand.cs index 9b7fd918f..18d9e2380 100644 --- a/CodeMaidShared/Integration/Commands/SpadeSortOrderTypeCommand.cs +++ b/CodeMaidShared/Integration/Commands/SpadeSortOrderTypeCommand.cs @@ -27,10 +27,10 @@ internal SpadeSortOrderTypeCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new SpadeSortOrderTypeCommand(package); - await Instance.SwitchAsync(on: true); + return Instance.SwitchAsync(on: true); } /// diff --git a/CodeMaidShared/Integration/Commands/SpadeToolWindowCommand.cs b/CodeMaidShared/Integration/Commands/SpadeToolWindowCommand.cs index c574d99e8..6c2331622 100644 --- a/CodeMaidShared/Integration/Commands/SpadeToolWindowCommand.cs +++ b/CodeMaidShared/Integration/Commands/SpadeToolWindowCommand.cs @@ -28,10 +28,10 @@ internal SpadeToolWindowCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new SpadeToolWindowCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_SpadeToolWindow, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_SpadeToolWindow, Instance.SwitchAsync); } public override async Task SwitchAsync(bool on) diff --git a/CodeMaidShared/Integration/Commands/SwitchFileCommand.cs b/CodeMaidShared/Integration/Commands/SwitchFileCommand.cs index 0aa70c225..b2ca945e2 100644 --- a/CodeMaidShared/Integration/Commands/SwitchFileCommand.cs +++ b/CodeMaidShared/Integration/Commands/SwitchFileCommand.cs @@ -48,10 +48,10 @@ internal SwitchFileCommand(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new SwitchFileCommand(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_SwitchFile, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_SwitchFile, Instance.SwitchAsync); } /// diff --git a/CodeMaidShared/Integration/Events/BaseEventListener.cs b/CodeMaidShared/Integration/Events/BaseEventListener.cs index 49e9ecd47..7bbd6b10c 100644 --- a/CodeMaidShared/Integration/Events/BaseEventListener.cs +++ b/CodeMaidShared/Integration/Events/BaseEventListener.cs @@ -26,15 +26,12 @@ protected BaseEventListener(CodeMaidPackage package) /// protected CodeMaidPackage Package { get; private set; } -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - /// /// Switches the event listener on or off, registering/unregistering from events from the IDE. /// /// True if switching the event listener on, otherwise false. /// A task. - public async Task SwitchAsync(bool on) -#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously + public Task SwitchAsync(bool on) { if (on && !IsListening) { @@ -46,6 +43,7 @@ public async Task SwitchAsync(bool on) IsListening = false; UnRegisterListeners(); } + return Task.CompletedTask; } /// diff --git a/CodeMaidShared/Integration/Events/BuildProgressEventListener.cs b/CodeMaidShared/Integration/Events/BuildProgressEventListener.cs index f2f70afe3..6692622d1 100644 --- a/CodeMaidShared/Integration/Events/BuildProgressEventListener.cs +++ b/CodeMaidShared/Integration/Events/BuildProgressEventListener.cs @@ -55,10 +55,10 @@ private BuildProgressEventListener(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new BuildProgressEventListener(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_BuildProgressToolWindow, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_BuildProgressToolWindow, Instance.SwitchAsync); } /// diff --git a/CodeMaidShared/Integration/Events/DocumentEventListener.cs b/CodeMaidShared/Integration/Events/DocumentEventListener.cs index b27fd2a4b..3af15aa85 100644 --- a/CodeMaidShared/Integration/Events/DocumentEventListener.cs +++ b/CodeMaidShared/Integration/Events/DocumentEventListener.cs @@ -41,10 +41,10 @@ private DocumentEventListener(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new DocumentEventListener(package); - await Instance.SwitchAsync(on: true); + return Instance.SwitchAsync(on: true); } /// diff --git a/CodeMaidShared/Integration/Events/RunningDocumentTableEventListener.cs b/CodeMaidShared/Integration/Events/RunningDocumentTableEventListener.cs index a6d737766..dd746992a 100644 --- a/CodeMaidShared/Integration/Events/RunningDocumentTableEventListener.cs +++ b/CodeMaidShared/Integration/Events/RunningDocumentTableEventListener.cs @@ -61,18 +61,15 @@ private RunningDocumentTableEventListener(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new RunningDocumentTableEventListener(package); // This listener services multiple features, watching if any of them switched. - await package.SettingsMonitor.WatchAsync(new[] { + return package.SettingsMonitor.WatchAsync(new[] { nameof(Settings.Default.Feature_SettingCleanupOnSave), nameof(Settings.Default.Feature_SpadeToolWindow) - }, async values => - { - await Instance.SwitchAsync(values.Any(v => v)); - }); + }, values => Instance.SwitchAsync(values.Any(v => v))); } public int OnAfterAttributeChange(uint docCookie, uint grfAttribs) => VSConstants.S_OK; diff --git a/CodeMaidShared/Integration/Events/SolutionEventListener.cs b/CodeMaidShared/Integration/Events/SolutionEventListener.cs index 9f7e0f646..917d79eb6 100644 --- a/CodeMaidShared/Integration/Events/SolutionEventListener.cs +++ b/CodeMaidShared/Integration/Events/SolutionEventListener.cs @@ -46,10 +46,10 @@ private SolutionEventListener(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new SolutionEventListener(package); - await Instance.SwitchAsync(on: true); + return Instance.SwitchAsync(on: true); } /// diff --git a/CodeMaidShared/Integration/Events/TextEditorEventListener.cs b/CodeMaidShared/Integration/Events/TextEditorEventListener.cs index 18485f194..d57a5762a 100644 --- a/CodeMaidShared/Integration/Events/TextEditorEventListener.cs +++ b/CodeMaidShared/Integration/Events/TextEditorEventListener.cs @@ -42,10 +42,10 @@ private TextEditorEventListener(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new TextEditorEventListener(package); - await Instance.SwitchAsync(on: true); + return Instance.SwitchAsync(on: true); } /// diff --git a/CodeMaidShared/Integration/Events/WindowEventListener.cs b/CodeMaidShared/Integration/Events/WindowEventListener.cs index dff919a09..4d2b19d08 100644 --- a/CodeMaidShared/Integration/Events/WindowEventListener.cs +++ b/CodeMaidShared/Integration/Events/WindowEventListener.cs @@ -41,10 +41,10 @@ private WindowEventListener(CodeMaidPackage package) /// /// The hosting package. /// A task. - public static async Task InitializeAsync(CodeMaidPackage package) + public static Task InitializeAsync(CodeMaidPackage package) { Instance = new WindowEventListener(package); - await package.SettingsMonitor.WatchAsync(s => s.Feature_SpadeToolWindow, Instance.SwitchAsync); + return package.SettingsMonitor.WatchAsync(s => s.Feature_SpadeToolWindow, Instance.SwitchAsync); } /// diff --git a/CodeMaidShared/UI/ToolWindows/Spade/SpadeToolWindow.cs b/CodeMaidShared/UI/ToolWindows/Spade/SpadeToolWindow.cs index 9b69fc7f8..498696832 100644 --- a/CodeMaidShared/UI/ToolWindows/Spade/SpadeToolWindow.cs +++ b/CodeMaidShared/UI/ToolWindows/Spade/SpadeToolWindow.cs @@ -210,8 +210,8 @@ public override void OnToolWindowCreated() // Get an instance of the code model manager. _codeModelManager = CodeModelManager.GetInstance(Package); - Package.JoinableTaskFactory.RunAsync(async () => - await Package.SettingsMonitor.WatchAsync(s => s.Feature_SpadeToolWindow, on => + Package.JoinableTaskFactory.RunAsync(() => + Package.SettingsMonitor.WatchAsync(s => s.Feature_SpadeToolWindow, on => { if (on) {