alexsorokoletov/VisualStudioMac.SortRemoveUsings

Update Extension for Visual Studio for Mac

MKuckert opened this issue · 29 comments

The plugin is currently not installable in Visual Studio for Mac because of the following warning (tried to install the mpack using Install from file…):
image

The process states those are warnings, but the extension is not working (no usings are sorted or removed).

Can you update this extension to support VS for Mac? Or give me some hints how to create a pull request to update it?

I will update the plugin this week. VS for Mac should have this, agree 100% :)

Wow, that was quick 😄

I've installed the extension but it doesn't work correctly. The usings are resorted and optimized on hitting save and the file stays with the changed-indicator (close-button on the tab stays being the circle: image). Thats the same behavior as it was for Xamarin Studio.
Hitting save again results in no changed, but the file is not saved either – the file simply keeps the changed-indicator. Upon compilation VS raises the error The build has been aborted as the file '…DetailViewController.cs' could not be saved.

Seems like VS is behaving differently then XS did when observing the save event?

@MKuckert that might happen. Can you reproduce that on any file or just on this specific?
Would be great if you provide a sample file where you can see that behavior.

Fact is, the extension only calls built-in command to refactor code.

Yes, I can reproduce that on a all files I tested with. Here is a simple sample file:

using System;
using Akavache.Sqlite3;

// Note: This class file is *required* for iOS to work correctly, and is 
// also a good idea for Android if you enable "Link All Assemblies".
namespace Proj.Recipes.Droid
{
    [Preserve]
    public static class LinkerPreserve
    {
        static LinkerPreserve()
        {
            throw new Exception(typeof(SQLitePersistentBlobCache).FullName);
        }
    }


    public class PreserveAttribute : Attribute
    {
    }
}

@MKuckert I've added file to an Android project and installed Akavache Sqlite3 NuGet package. Everything works as expected.

I assume there something else what changes the file before or after save. Can you enable hidden characters in VS4Mac and see if there are any changes when you try to save it.

Btw, without package, when I save the file, 2nd using is being removed since namespace is not recognized.

I have the same problem as @MKuckert. The change files seem to always be unsaved. There is no way for make VS believe that the file is indeed saved.

@jschmid @MKuckert I'd be glad to have a short video to see the problem. I can't reproduce that issue though I feel fix is simple and I'm just missing something.

Sorry for the long answer, guys

No worries! I'm pretty sure the problem has vanished with the latest version of visual studio - I will check that and give you a hands up the end of next week.

never-saved

You will see that I scramble the imports manually, then I hit "save". You can notice that the file still appears unsaved in the editor. I have no way to close the file because it always says it's unsaved.

@jschmid it's a known thing that you have to press save sometimes twice since refactoring command changes file after it was saved (at least now it's how it is in the MonoDevelop extension, there is no PreSave). But if you press save again after extension it should allow you to save since there will be no changes (usings are already sorted).

Is it the case?

@alexsorokoletov Sadly no. I can press as many times as I want, the file always appears as unsaved. It does not change it I use the menu or the keyboard shortcut.

So it's something else then.

@jschmid would you be able to turn on all invisibles (Preferences -> Text Editor -> Markers and Rulers -> Show invisible characters = Always) and reproduce the problem on video on some tiny file where we can see all the content?

Also, wondering if on previous GIF you would enable invisibles, disable the extension and instead save file and then run the context command "Sort and Remove usings" manually.

Idea is that since that o round circle icon shows up, there is something being changed. Some whitespace or line ending or something else.
I can't reproduce that on my mac or any other I can reach :(

Really appreciate your help!

Hello,
I have the same problem. Can you fix it because your projet it's very useful ?
Cordially

@damienB if you could follow previous comment for me and see if something is happening with hidden characters?

@alexsorokoletov I try with a minimalist class and I still have the problem. I attach a screenshot of the code with the special characters.
capture d ecran 2017-12-27 a 10 02 10

@alexsorokoletov
Hello,
Have you found where the problem is coming from?
Thanks,

@damienB I'd be glad, I still can't repro. Let's connect and reproduce it on your system so that I can fix that annoying issue :)

would you be able to turn on all invisibles (Preferences -> Text Editor -> Markers and Rulers -> Show invisible characters = Always) and reproduce the problem on video on some tiny file where we can see all the content?

Also, wondering if on previous GIF you would enable invisibles, disable the extension and instead save file and then run the context command "Sort and Remove usings" manually.

Alternative would be a video or gif of these two scenarios.

@alexsorokoletov I think I have found where the problem comes from. When the box "Preferences -> Source code -> Code formating -> C # source code -> Convert tabs to spaces = Checked" it works but if it is unchecked then we have the problem described above (see gif) .

ezgif com-optimize

PS : est-il possible de sauvegarder automatiquement après le trie quand cela fonctionne pour ne pas avoir à sauvegarder deux fois comme sur le gif ?

@damienB looking! Thank you for the gif and research.
Regarding PS, yes I think it is possible to save you from doing it twice ;)

Reproduced, working on a fix

@damienB would you be able to zip this sample solution in a state when you can reproduce the problem? VS stores all settings inside .sln.

I might want to double check before I put an update out there.
Here is a preview of the update (needs to be unzipped)
SortAndRemoveOnSave.SortAndRemoveOnSave_1.2.mpack.zip

@alexsorokoletov
Here is my project for you to reproduce.
Test.zip

I have also tested the preview but I can not install it (see photo attached)
capture d ecran 2018-01-11 a 10 24 38

@damienB I see, recently updated my VS to the latest stable. If you plan to do so anyway - you can update VS and try again. If not - I will rebuild extension for an earlier version later today.

@alexsorokoletov With the new version of Visual Studio it's work fine for me :-)
Thanks you very much !

It works for me too !

Thanks guys for fixing or helping fixing it !

Perfect, I will prepare an update ;)

Thank you everyone for raising the issue and helping resolving it. New release is live https://github.com/alexsorokoletov/VisualStudioMac.SortRemoveUsings/releases