Issue #26 resolved

Refactor / Remove Usings

Svante Seleborg avatarSvante Seleborg created an issue

When Sort & Remove usings is enabled, and run at document save is enabled and for example the 'rename' refactoring is used things get broken.

Apparently the cleanup is run in the middle of the refactoring operation, causing the end-result to be missing it's appropriate usings.

Comments (4)

  1. Steve Cadwallader
    • changed status to open

    I have noticed this issue as well, and there are some other circumstances under which it can occur. If the code is in an invalid state (i.e. will not compile) then Visual Studio may remove using statements that are needed. Also if there are preprocessor directives defined but not active, and the associated using statements are not also bracketed in the same preprocessor directives, those using statements may get removed. These same issues will occur if you invoke the command directly or if CodeMaid invokes it for you.

    I have looked into detecting the renaming scenario but there is no information published from the API that it is occurring that I could find. Unfortunately that leaves me with little I can do to work around the native issues within Visual Studio's remove unused using statements command.

    If you are seeing this issue often and it is causing problems, you can either disabe the auto-save or the remove-usings option as a trade-off for losing that functionality. I wish I had a better alternative, but for now I'm just hoping for an improvement to the command in the next version of Visual Studio. I believe it is already reported on Microsoft Connect, but I can't recall for certain.

    Hope it helps, -Steve Cadwallader

  2. Svante Seleborg

    I was afraid it was something like that. How about not doing the 'remove' part of the using handling when doing save, since it can actually break things?

    It would work as normal when doing 'clean up'. That would facilitate usage, reduce the risk of breaking code at the expense of a slightly more complex behavior. It could be mitigated by adding an explanatory text to the 'remove usings' options, i.e: 'Remove Usings (Only at Manual CleanUp, not during Save)' or something like that.

    Regards,

    Svante

  3. Steve Cadwallader

    (Reply via stev...G-MAIL.com):

    Hi Svante -

    That's a very good suggestion, thanks for recommending it. I'll plan on doing that and probably extending it by providing an opt-in (defaulted off) option to remove usings during auto-save with an additional warning message.

    Thanks for the help :) -Steve Cadwallader

  4. Steve Cadwallader

    Hi Svante -

    The new v0.3.8 ALPHA release includes this configurable option defaulted to off with a warning message if users enable the behavior that it can cause issues under some circumstances.

    Thanks again for your input, -Steve Cadwallader

  5. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.