Endless loop on File.SaveSelectedItems
denious opened this issue ยท 19 comments
I am trying to auto-format the document with R# and auto-save afterward, which results in a loop.
R# marks a document as edited even if no changes are made, so having ReSharper.ReSharper_ReformatCode as the only command simply makes saving any document impossible! :)
Two suggestions:
- Detect File.SaveSelectedItems in the commands.
- Have an OnBeforeSave and an OnAfterSave command lists, this way I could put ReSharper.ReSharper_ReformatCode in the OnBeforeSave and everything would work out great!
I will try to deliver it this week. Please be patient.
I am looking this right now.
What is the purpose of having File.SaveSelectedItems
in the commands? Basically the Commands
are triggered upon save and you are telling the document to be saved again. So if you remove File.SaveSelectedItems
and pres ctrl
+s
then first Resharper...
command will be executed and then the file will be saved.
I think I am missing something here... Please help me understand
@mynkow My bad, completely missed your first reply!
I don't know how Edit.FormatDocument (A) and ReSharper.ReSharper_ReformatCode (B) are different, but using A the document is saved after formatting, using B leaves the document in an edited state.
Here's a demo (YT: https://youtu.be/EI6cAfTKDIY), just follow the mouse and I hope it makes sense! I use both Ctrl-S and a manual File > Save to show the differences in behavior.
@mynkow Let me know what you find or if you need more information!
I am sure many people who use R# would be happy to find out this great extension works for them! ๐
@denious could you please try this version with the ReSharper.ReSharper_ReformatCode File.SaveSelectedItems
commands
@mynkow It works!! Works flawlessly even without explicitly adding File.SaveSelectedItems
.
Do you end up in a stackoverflow using r# command only in the previous version?
Or plugin crash?
Before I would either have to save twice (good scenario) for the save to take effect, or the save would never complete (document stays in edited mode).
@denious last question. If you execute r# command without format doc on save, is the doc saved afterwards?
Ps:you have to uninstall or disable the extension
@mynkow I'm not sure anymore if this works correctly. Today I tried using the R# silent cleanup command like so ReSharper.ReSharper_SilentCleanupCode File.SaveSelectedItems
and the formatting was not applied at all until I manually formatted the document. Then the plugin started "working", but the document is not being saved anymore, just like before.
To answer your question, the R# command does not auto-save the document.
Very inconsistent behavior... Here is another video:
https://youtu.be/Zz5c20N5ZdE
Original code:
using System.Threading.Tasks;
using PLPlusBot.Common.Requests;
using PLPlusBot.Common.Responses;
namespace PLPlusBot.Common
{
public interface IClient
{
Task<IStandardResponse> CreateOrderAsync(OrderRequest orderRequest);
Task<IStandardResponse> CancelPendingOrdersAsync( string instrument);
Task<IStandardResponse> CloseOpenPositionsAsync(CloseOpenPositionsRequest inputRequest);
}
}
Expected output, works when calling ReSharper_SilentCleanupCode
manually (Ctrl+E,F):
using System.Threading.Tasks;
using PLPlusBot.Common.Requests;
using PLPlusBot.Common.Responses;
namespace PLPlusBot.Common
{
public interface IClient
{
Task<IStandardResponse> CreateOrderAsync(OrderRequest orderRequest);
Task<IStandardResponse> CancelPendingOrdersAsync(string instrument);
Task<IStandardResponse> CloseOpenPositionsAsync(CloseOpenPositionsRequest inputRequest);
}
}
I see, do you experience this inconsistent behaviour with the command from the first post?
Yes, I must've been too excited last night and didn't notice ๐
There is something which R# is doing with the VisualStudio command workflow and I am not able to figure what it is doing. I have tried to find out how their commands operate but did not find anything. Whatever it is it just messes with VisualStudio.
My solution was to track which command was executed per file but I guess it will not help. The other option to execute a PreFormat command or PreSave command will not work at all because we are doing exactly this at the moment.
Well, you did something right! After formatting a document once the command starts taking effect and only the auto-save part is missing. Let me know if you want me to test another version in the future or if I can help out in any other way! :)
@mynkow There is another extension that claims to do what we want but it is not available for download anymore so I cannot test it. Here's the repo if you're curious to see the code:
https://github.com/PombeirP/ReSharper.AutoFormatOnSave
There is a report that this works OOB without any changes to the code. See the reviews in the extensions store
I never said that ReSharper.ReSharper_SilentCleanupCode doesn't work, it just doesn't auto-save, requires to hit Ctrl-S twice.