codecadwallader / codemaid

CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding.
http://www.codemaid.net
GNU Lesser General Public License v3.0
1.89k stars 356 forks source link

Undesired jump away from code page tab to properties page tab on first save #354

Open NDeLancie opened 7 years ago

NDeLancie commented 7 years ago

Environment

On the first save of a code page edit after instantiating VS with Code Maid, the project's properties page tab gets jumped to if it is open.

Steps to recreate

  1. Instantate VS with Code Maid.
  2. Open a project (I'm working on a VB project).
  3. Have that project's properties page (its .vbproj file) as one of the open tabs of that project.
  4. On a code page tab of that project (one of its .vb files), make at least one edit (e.g., space and backspace).
  5. While still on that code page tab, perform a save (either of that file, by Ctrl+s, or the whole project, by Ctrl+S.
  6. Notice what happens.
  7. Repeat 4 and 5.
  8. Notice what doesn't happen.

    Current behavior

What happens the first time through 4. and 5. is that the project's properties page tab is activated--that is, focus jumps away from the code page tab being edited to the properties page tab. However, on subsequent times through 4. and 5., this does not happen--that is, there is no jump away from the code page tab. It also does not happen on the first edit and save if the properties page tab is not open to begin with.

Expected behavior

It shouldn't be doing anything--that is, after the first time through 4. and 5., one should be left on the code page tab being edited, just like one is left there on subsequent times through 4. and 5.

codecadwallader commented 7 years ago

Thanks for reporting the issue. One thing to check - if you invoke Edit->Advanced->Format Document on Step 5 (instead of invoking CodeMaid) do you see the same behavior? Part of CodeMaid's cleanup is to invoke Visual Studio's cleanup, and it would be helpful to know if the context switch is coming from that call or a part of CodeMaid.

CodeMaid does "activate" the document in order to make sure it is in the foreground so that some cleanup actions will work correctly. That would be the line of code I would consider most likely to be responsible, but one that is necessary. https://github.com/codecadwallader/codemaid/blob/master/CodeMaid/Logic/Cleaning/CodeCleanupManager.cs#L141

NDeLancie commented 7 years ago
                                                                                  Steve: Thanks for the quick response. I'll check per your request. Note, though, that I'm not invoking CodeMaid at step 5 (it's already been loaded automatically when VS starts), I'm just performing the first save (Ctrl-s or Ctrl-S) as normal in the Visual Studio IDE. I'll also see if the jump to the open project properties page occurs is the save is effected through the VS file menu‎. Also, as noted, the jump does not occur for a second or subsequent save in the same VS session--the odd behavior only occurs when the first save is made of a just opened project in a just started VS session. By the way, we're you able to repeat the problem?                                                                                                                                                                                                                                                                                                                                        Thanks,Nick____________________________________Nick De Lancie638 - 34th AvenueSan Francisco, California 94121(415) 668-3110 Home(415) 317-0875 Mobile(415) 984-9675 Office                                                                                                                                                                                                                From: Steve CadwalladerSent: Saturday, October 15, 2016 6:11 AMTo: codecadwallader/codemaidReply To: codecadwallader/codemaidCc: NDeLancie; AuthorSubject: Re: [codecadwallader/codemaid] Undesired jump away from code page tab to properties page tab on first save (#354)Thanks for reporting the issue.  One thing to check - if you invoke Edit->Advanced->Format Document on Step 5 (instead of invoking CodeMaid) do you see the same behavior?  Part of CodeMaid's cleanup is to invoke Visual Studio's cleanup, and it would be helpful to know if the context switch is coming from that call or a part of CodeMaid.

CodeMaid does "activate" the document in order to make sure it is in the foreground so that some cleanup actions will work correctly. That would be the line of code I would consider most likely to be responsible, but one that is necessary. https://github.com/codecadwallader/codemaid/blob/master/CodeMaid/Logic/Cleaning/CodeCleanupManager.cs#L141

—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or mute the thread.

{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/codecadwallader/codemaid","title":"codecadwallader/codemaid","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/codecadwallader/codemaid"}},"updates":{"snippets":[{"icon":"PERSON","message":"@codecadwallader in #354: Thanks for reporting the issue. One thing to check - if you invoke Edit-\u003eAdvanced-\u003eFormat Document on Step 5 (instead of invoking CodeMaid) do you see the same behavior? Part of CodeMaid's cleanup is to invoke Visual Studio's cleanup, and it would be helpful to know if the context switch is coming from that call or a part of CodeMaid.\r\n\r\nCodeMaid does \"activate\" the document in order to make sure it is in the foreground so that some cleanup actions will work correctly. That would be the line of code I would consider most likely to be responsible, but one that is necessary. https://github.com/codecadwallader/codemaid/blob/master/CodeMaid/Logic/Cleaning/CodeCleanupManager.cs#L141"}],"action":{"name":"View Issue","url":"https://github.com/codecadwallader/codemaid/issues/354#issuecomment-253983443"}}}

codecadwallader commented 7 years ago

I was assuming on Step 5, you have CodeMaid's automatic cleanup on save turned on. So when you save the file, CodeMaid steps in to activate. If that isn't the case, then CodeMaid should not be doing anything at Step 5.

I haven't been able to test reproducing it yet.. currently in the middle of a move.

NDeLancie commented 7 years ago

Steve, take your time moving. Don’t worry about this until you want.

Here is more information:

Under User Settings > Cleaning > General, (i) Automatically run cleanup on file save is not checked; (ii) Automatically save and close documents opened by cleanup is checked; and (iii) Perform partial cleanup … is set to ask.

In case there are other settings that might be important (though I have changed very few of the defaults), I have attached the exported CodeMaid.config file.

With CodeMaid enabled, following steps 1 to 4 (start new VS session, open existing project, have that project’s properties page open as one of the tabs—that’s how I save my projects, so they open that way automatically—and make a minor edit to it somewhere on a code page—space and then back space), invoking Edit > Advanced > Format Document does NOT produce the jump to the properties page tab.

With CodeMaid disabled (Tools > Extensions and Updates > CodeMaid > Disable > restart VS), following same steps 1 to 4, executing the save (Ctrl-s) does NOT produce the jump to the properties page tab.

With CodeMaid re-enabled (Tools > Extensions and Updates > CodeMaid > Enable > restart VS), following same steps 1 to 4, invoking Edit > Advanced > Format Document again does NOT produce the jump to the properties page tab, but executing the save (Ctrl-s) immediately thereafter does produce the jump. Again, making the same minor edit and executing the save a second time does NOT produce the jump.

No CodeMaid setting were changed in any of this from what’s noted above and in the config file.

Since the jump happens only when CodeMaid is enabled and all other things are the same, it looks like CodeMaid must be doing something (or causing VS to do something) on a save even if it isn’t running a code clean-up.

By the way, I’m an older commercial loan documentation lawyer with a good eye for detail, and I use VS just for my own, non-commercial purposes to make Windows or Office applications jump through hoops, so to speak, or to make other things happen, as a step up from VB Script, VBA, WinBatch, and various other programming languages (I’ve written thousands of lines of code over the years for myself). Computer programming has been one of my hobbies for a very long time—I just missed moving into tech since I was a lawyer doing what I had been trained to do. Oh well.

Last year I got Visual Studio 2015 and, while the Office VBA IDE was pretty good for me when that was what I had available to me, and I had had some exposure to Java and Eclipse some years ago, the VS environment was just fantastic for me for Visual Basic (and now, VB.Net) coding, and I became a pig in you know what. I think of contract writing and programming as very similar intellectual undertakings: both are abstract logical thought constructions and both should be well organized, easily readable, logically correct, and syntactically consistent. The big difference is that bad code will generally either fail or produce bad results right away, while bad contracts may not display their deficiencies until much time has passed, one party has breached, the other party had sued, and a court tries to sort it all out.

Recently, I stumbled on CodeMaid when I was looking for an easy way to sort lines of code (e.g., to put groups of Dim statements in alphabetical order) and the unexpected properties page jump just jumped out at me, so I thought I would let you know since anyone who would write something like CodeMade was likely highly obsessive-compulsive about how his code looks and works (like I am).

Best luck with the move.

                                  Nick 

Nicolas De Lancie 638 - 34th Avenue San Francisco, California 94121

(415) 984-9675 Office (415) 668-3110 Home (415) 317-0875 Cell

nde@jmbm.com mailto:Nick@delancie.org Nick@delancie.org

From: Steve Cadwallader [mailto:notifications@github.com] Sent: Monday, October 17, 2016 07:10 am To: codecadwallader/codemaid Cc: NDeLancie; Author Subject: Re: [codecadwallader/codemaid] Undesired jump away from code page tab to properties page tab on first save (#354)

I was assuming on Step 5, you have CodeMaid's automatic cleanup on save turned on. So when you save the file, CodeMaid steps in to activate. If that isn't the case, then CodeMaid should not be doing anything at Step 5.

I haven't been able to test reproducing it yet.. currently in the middle of a move.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/codecadwallader/codemaid/issues/354#issuecomment-254218152 , or mute the thread https://github.com/notifications/unsubscribe-auth/AVyu5TycTVANl2aYJXcrx1FOiICtcZ9pks5q04G6gaJpZM4KXo7k . https://github.com/notifications/beacon/AVyu5XHERmPIYycN3_sXiMngWqC0Xx4Gks5q04G6gaJpZM4KXo7k.gif

codecadwallader commented 7 years ago

Haha, well you are certainly very right about it requiring an obsessive personality to create something like CodeMaid. ;) I do appreciate bug reports as opportunities to make CodeMaid better, especially when they are clearly outlined like you have done so thank you. I'm also glad to hear of your passion for programming, I find it provides the same intellectual stimulation.

I have tried a few times, but have unfortunately been unable to reproduce the issue following your steps. I did also try a couple variations from your steps, such as turning on automatic cleanup on save at Step 5 but it still did not trigger a jump to the VB project properties page.

The way you have described the steps I certainly agree with you that it is logical to conclude CodeMaid's presence is affecting the environment. I don't see an obvious cause for why that would be the case, as with automatic cleanup on save disabled, CodeMaid should not be taking any action during a save event.

Since I can't reproduce it currently, that gives us three possible paths forwards:

  1. If you're game, you can get up to speed on how to debug Visual Studio extensions. It's really identical to how you debug anything else, you're simply invoking a second instance of Visual Studio as your running application.
  2. We can try to find differences between our environments/configurations/usage and look for reasons why the bug may reproduce differently.
  3. We leave this issue open until we have more information, for example someone else chiming in with their observations if they saw it too.