codemaid
codemaid copied to clipboard
When code maid is enabled, Visual Studio hangs with "Please wait for an editor command to finish" while performing property rename operation.
Environment
- Visual Studio version: Enterprise 2017 15.8.2
- CodeMaid version: 10.5.119
- Code language: C#
Description
Often times when renaming something in Visual Studio (via the CTRL+R, R chord), it will get completely stuck and just hang forever.
A little window comes up that says "Please wait for an editor command to finish..." and it just goes forever. There is a cancel button, but it is not functional.
At the VERY least, please make the cancel button functional, because having to force stop Visual Studio every time it decides to hang is super annoying. (This has happened about 4 times to me in a 3 hours period on 8/28 -- and several times a day for the prior week -- Disabling the Code Maid extension on that date has made the problem go away for me since then. -- Which is super unfortunate because I really like using code maid. 😢
Additionally, when the hang happens, after I restart Visual Studio, I get a message about my settings file being borked up, and all my toolbars get reset to default (which is even more annoying; I'd basically given up on customizing my toolbars, because the setting will just get lost the next time VS would crash).
It would be nice if you could at least fix it, so that the cancel button would work, so that we don't have to kill Visual Studio when this happens.
FYI: I originally thought this was a bug with Visual Studio, and logged the bug here; but since disabling code maid makes the issue go away, I'm going to assume this is a bug in code maid for now.
Thanks for reporting the issue and the additional details. What I suspect is happening is an infinite loop between Visual Studio, CodeMaid and potentially other extensions. One example in the past we've seen is:
- Visual Studio starts a rename operation, as part of that operation, Visual Studio triggers a save
- CodeMaid setup to automatic cleanup on save, kicks in and starts cleaning up and triggers "remove and sort using statements"
- Visual Studio processes "remove and sort using statements", triggering a save..
If you look in our settings, there's an option (off by default) at CodeMaid->Options->Cleaning->Visual Studio->Run remove and sort using statements->Skip during automatic cleanup on save that was specifically created because of this scenario. I'd recommend making sure that is still off if you have turned it on. Some users say it's not a problem for them since older versions (VS2012/VS2013).
The same infinite loop workflow can also happen if there are other extensions that are both monitoring and triggering save events.
The "cancel" button dialog is directly from Visual Studio, so it isn't something we can directly influence.. really by the time you get to that point things have already gone wrong so it's more of a symptom than a cause.
Please check that setting, and other extensions and I suspect we can figure out what the infinite loop is in your case.
I got same issue in VS 2019 16.5. version, this issue made edition very very very slow ....
Did you check the option mentioned above?
Above did not work for my case.....
Do you know if you have any other extensions that may be triggering during a save event?
I'm seeing this happen every time in both VS 2017 and VS 2019. I do have an extension that updates copyright information in each file on save, which may be contributing.
Disabling Automatic Cleanup on Save before the rename prevents the issue, but is easy to forget.
Thanks for the information. I suspect in that case the rename auto-saves, then CodeMaid is triggered and saves the document, which the other extension is triggered and saves the document, which goes back to triggering CodeMaid causing an endless loop of save reactions.
I tried disabling all extensions except CodeMaid, and I still get the freezing behavior. I restarted VS between disabling everything and testing. I don't think this is caused by interacting with another extension.
I've attached my CodeMaid configuration file in case that helps you reproduce the issue. CodeMaid.config.txt
I tried reset to default and after that disable CodeMaid -> Options -> Cleaning -> General -> Automatically save and close documents opened by cleanup. This helped to doesn't slow copy and paste on XAML files.
Just un-checking that setting didn't help with the freezing issue (even with all other extensions disabled). Resetting to the default settings does help, but only because the setting above that (Automatically run cleanup on file save) got disabled. That feature is one of the reasons I use CodeMaid, so I'd really rather not have to disable it to avoid this issue.
Is there more I could do to help track this problem down?
On the top options page there is a "Diagnostics mode" you can enable which will place some additional logging messages in the Output tool window. If you have that open while the presumed infinite loop is occurring maybe that will provide some additional information but I'm not sure.
Another option to figure out what is causing the cycle is to run CodeMaid in a debugger and set a break point within the cleaning logic to see if there is additional information in the call stack about how the cycle is occurring. There is some information here (http://www.codemaid.net/contribute/) on how to run CodeMaid that may be helpful.
The diagnostics mode doesn't appear to show anything once the loop starts (the last event I see is about an OnLineChanged event being raised). I'll need more time to get CodeMaid set up under a debugger to try that route.
Same problem, using Vs2019 16.6.1 (C++), CodeMaid 11.1.209. This issue appears randomly, while saving, renaming or building. "Spade" and Intellisence are loading endlessly.
appears randomly, while saving, renaming or building. "Spade" and Intellisence are loading endlessly.
That doesn't sound like the same issue I'm seeing, though I'm working mostly with C# and TypeScript code. I never see a hang on saving or building, just renaming, extracting methods, and other VS-manipulating-code actions.
I'm still working on the debugging. I hope to get something useful next week.
I have a stack trace:
Click to expand
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.RunCodeCleanupCSharp(EnvDTE.Document document) Line 230 C#
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.Cleanup.AnonymousMethod__0() Line 170 C#
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Helpers.UndoTransactionHelper.Run(System.Action tryAction, System.Action<System.Exception> catchAction) Line 55 C#
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.Cleanup(EnvDTE.Document document) Line 160 C#
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Integration.Commands.CleanupActiveCodeCommand.OnBeforeDocumentSave(EnvDTE.Document document) Line 66 C#
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Integration.Events.RunningDocumentTableEventListener.OnBeforeSave(uint docCookie) Line 124 C#
[Native to Managed Transition]
[Managed to Native Transition]
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Helpers.UndoTransactionHelper.Run(System.Action tryAction, System.Action<System.Exception> catchAction) Line 76 C#
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.Cleanup(EnvDTE.Document document) Line 160 C#
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Integration.Commands.CleanupActiveCodeCommand.OnBeforeDocumentSave(EnvDTE.Document document) Line 66 C#
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Integration.Events.RunningDocumentTableEventListener.OnBeforeSave(uint docCookie) Line 124 C#
[Native to Managed Transition]
[Managed to Native Transition]
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Helpers.UndoTransactionHelper.Run(System.Action tryAction, System.Action<System.Exception> catchAction) Line 76 C#
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.Cleanup(EnvDTE.Document document) Line 160 C#
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Integration.Commands.CleanupActiveCodeCommand.OnBeforeDocumentSave(EnvDTE.Document document) Line 66 C#
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Integration.Events.RunningDocumentTableEventListener.OnBeforeSave(uint docCookie) Line 124 C#
[Native to Managed Transition]
[Managed to Native Transition]
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Helpers.UndoTransactionHelper.Run(System.Action tryAction, System.Action<System.Exception> catchAction) Line 76 C#
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.Cleanup(EnvDTE.Document document) Line 160 C#
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Integration.Commands.CleanupActiveCodeCommand.OnBeforeDocumentSave(EnvDTE.Document document) Line 66 C#
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Integration.Events.RunningDocumentTableEventListener.OnBeforeSave(uint docCookie) Line 124 C#
[Native to Managed Transition]
[Managed to Native Transition]
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Helpers.UndoTransactionHelper.Run(System.Action tryAction, System.Action<System.Exception> catchAction) Line 76 C#
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.Cleanup(EnvDTE.Document document) Line 160 C#
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Integration.Commands.CleanupActiveCodeCommand.OnBeforeDocumentSave(EnvDTE.Document document) Line 66 C#
SteveCadwallader.CodeMaid.dll!SteveCadwallader.CodeMaid.Integration.Events.RunningDocumentTableEventListener.OnBeforeSave(uint docCookie) Line 124 C#
[Native to Managed Transition]
[Managed to Native Transition]
Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.GlobalUndoServiceFactory.WorkspaceUndoTransaction.Commit() Line 100 C#
Microsoft.CodeAnalysis.EditorFeatures.Wpf.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.ApplyRename(Microsoft.CodeAnalysis.Solution newSolution, Microsoft.CodeAnalysis.Editor.Host.IWaitContext waitContext) Line 842 C#
Microsoft.CodeAnalysis.EditorFeatures.Wpf.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.CommitCore(Microsoft.CodeAnalysis.Editor.Host.IWaitContext waitContext, bool previewChanges) Line 773 C#
Microsoft.CodeAnalysis.EditorFeatures.Wpf.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.CommitWorker.AnonymousMethod__0(Microsoft.CodeAnalysis.Editor.Host.IWaitContext waitContext) Line 708 C#
Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.Utilities.VisualStudioWaitIndicator.Wait(string title, string message, bool allowCancel, bool showProgress, System.Action<Microsoft.CodeAnalysis.Editor.Host.IWaitContext> action) Line 42 C#
Microsoft.CodeAnalysis.EditorFeatures.Wpf.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.CommitWorker(bool previewChanges) Line 704 C#
Microsoft.CodeAnalysis.EditorFeatures.Wpf.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.Dashboard.Commit() Line 329 C#
Microsoft.CodeAnalysis.EditorFeatures.Wpf.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.Dashboard.Apply_Click(object sender, System.Windows.RoutedEventArgs e) Line 322 C#
PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) Unknown
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) Unknown
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args) Unknown
PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs e) Unknown
PresentationFramework.dll!System.Windows.Controls.Primitives.ButtonBase.OnClick() Unknown
PresentationFramework.dll!System.Windows.Controls.Button.OnClick() Unknown
PresentationFramework.dll!System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e) Unknown
PresentationCore.dll!System.Windows.UIElement.OnMouseLeftButtonUpThunk(object sender, System.Windows.Input.MouseButtonEventArgs e) Unknown
PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) Unknown
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) Unknown
PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) Unknown
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) Unknown
PresentationCore.dll!System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args, System.Windows.RoutedEvent newEvent) Unknown
PresentationCore.dll!System.Windows.UIElement.OnMouseUpThunk(object sender, System.Windows.Input.MouseButtonEventArgs e) Unknown
PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) Unknown
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) Unknown
PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) Unknown
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) Unknown
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args) Unknown
PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args) Unknown
PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args, bool trusted) Unknown
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() Unknown
PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input) Unknown
PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport) Unknown
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel) Unknown
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd, MS.Internal.Interop.WindowMessage msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown
PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) Unknown
It appears that something about the call to _package.IDE.UndoContext.Close() in UndoTransactionHelper.cs triggers the OnBeforeSave handler in RunningDocumentTableEventListener.cs. I confirmed that skipping the undo transaction completely avoids the issue, but that doesn't seem like a viable fix.
Thanks for the call stack. As you mentioned there is an option (on by default) to skip undo transactions only during automatic cleanup on save because of the possibility of infinite loops. The undo transactions and context are a part of the IDE and not something we have a lot of control over.
I actually hadn't seen the option -- I skipped the transaction by editing the code. The option you pointed out does appear to work, and still allows undoing past an auto-cleanup. Thank you for bearing with my selective blindness.
I'm not sure when/why that option was toggled for me, but it's fixed now.
Awesome, I'm glad that's helpful for you. :)
In case it helps anyone else: I was having this problem because I had installed Mads Kristensen’s pack of extensions called The Essentials. On of the extensions is Tweaks, which has an auto save option which is on by default.
Uninstalling Tweaks or disabling the auto save setting avoids the problem.
Would it be possible for CodeMaid to avoid changing the file when the file is the same before and after the clean-up because it triggers autosave? I think this is the root cause of this infinite loop of cleaning up and saving the file.
I face the same issue with VS 2019 16.11.7 when renaming something.
I have not installed any other extensions except from Code Maid.
The issue only appears if Skip dirung automatic cleanup on save
is disabled.
But I would like to use the automatic cleanup on save, at the moment I have to disable this anytime when I rename something.
This keeps happening since osme of the updates of Visual Studio 2019, and now even more often on Visual Studio 2022. I noticed that on 2022 it just hapenes when you switch between documents fast and CodeMaid Spade did not finish to load the previous one.
I face the same issue with VS 2019 16.11.7 when renaming something. I have not installed any other extensions except from Code Maid. The issue only appears if
Skip dirung automatic cleanup on save
is disabled. But I would like to use the automatic cleanup on save, at the moment I have to disable this anytime when I rename something.
You can use automatic cleanup on save, you just have to disable the transaction. It messes up with the Undo but that's it.
Clear appdata local and appdata roaming ,it works for me