codemaid icon indicating copy to clipboard operation
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.

Open BrainSlugs83 opened this issue 5 years ago • 24 comments

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.

Recording

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.

BrainSlugs83 avatar Sep 10 '18 21:09 BrainSlugs83

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.

codecadwallader avatar Sep 16 '18 12:09 codecadwallader

I got same issue in VS 2019 16.5. version, this issue made edition very very very slow ....

shhosh avatar Apr 14 '20 18:04 shhosh

Did you check the option mentioned above?

codecadwallader avatar Apr 18 '20 11:04 codecadwallader

Above did not work for my case.....

shhosh avatar Apr 18 '20 14:04 shhosh

Do you know if you have any other extensions that may be triggering during a save event?

codecadwallader avatar Apr 25 '20 11:04 codecadwallader

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.

klylesatepic avatar May 01 '20 17:05 klylesatepic

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.

codecadwallader avatar May 05 '20 19:05 codecadwallader

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

klylesatepic avatar May 05 '20 20:05 klylesatepic

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. CodeMaid Configuration

ronymesquita avatar May 09 '20 02:05 ronymesquita

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.

klylesatepic avatar May 11 '20 14:05 klylesatepic

Is there more I could do to help track this problem down?

klylesatepic avatar May 29 '20 17:05 klylesatepic

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.

codecadwallader avatar May 30 '20 11:05 codecadwallader

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.

klylesatepic avatar Jun 03 '20 18:06 klylesatepic

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.

Altyrost avatar Jun 26 '20 08:06 Altyrost

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.

klylesatepic avatar Jun 26 '20 13:06 klylesatepic

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.

klylesatepic avatar Jun 30 '20 23:06 klylesatepic

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.

image

codecadwallader avatar Sep 22 '20 12:09 codecadwallader

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.

klylesatepic avatar Sep 22 '20 12:09 klylesatepic

Awesome, I'm glad that's helpful for you. :)

codecadwallader avatar Sep 22 '20 13:09 codecadwallader

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.

smklancher avatar Jan 02 '21 20:01 smklancher

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.

valentin-p avatar Nov 25 '21 11:11 valentin-p

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.

Calfur avatar Nov 27 '21 18:11 Calfur

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.

mana8100 avatar Jan 05 '22 23:01 mana8100

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.

lflender avatar Mar 29 '22 14:03 lflender

Clear appdata local and appdata roaming ,it works for me

RM-Arunachalam avatar Dec 08 '22 15:12 RM-Arunachalam