Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save actions does not save file after formatting #39

Closed
arngrimur opened this issue May 10, 2016 · 12 comments
Closed

Save actions does not save file after formatting #39

arngrimur opened this issue May 10, 2016 · 12 comments
Labels
Milestone

Comments

@arngrimur
Copy link

If the options to reformat code and organize imports are enabled and at least reformat code is triggered then the code is reformatted but the file is not saved so you have to press Ctrl+S twice.

Steps to reproduce: (Tested in a java file and java script file)
1: Write some correctly formatted code.
2: Add after a semicolon some more code so you get a line like
System.out.println("foo");System.out.println("bar");
3: Press Ctrl+S
Expected result:
The code shall look like
System.out.println("foo");
System.out.println("bar");
and
The file shall be saved.

Actual result:
The code looks like
System.out.println("foo");
System.out.println("bar");
and
The file is NOT saved.

@dubreuia
Copy link
Owner

Thanks for that. Can you give me your plugin version, idea version and the last lines of your ~/.IntelliJIdea2016.1/system/log/idea.log please I'll check it out

@dubreuia dubreuia added the bug label May 11, 2016
@dubreuia dubreuia self-assigned this May 11, 2016
@dubreuia
Copy link
Owner

dubreuia commented May 11, 2016

I can reproduce, don't worry about what I asked you, I'll be able to manage without it.

edit: I went back as far as v0.4, and that bug was always there and it is pretty serious. The problem is that I don't know when the file is written to disk, it seems like it is written too soon (before the plugin has finished working on the file) because it is done async.

edit2: actually not too bad since in the end the correct content is written to disk, but a bit later, I'll see if I can force it

@dubreuia dubreuia removed their assignment Aug 21, 2016
@bradcupit
Copy link

I've seen the same thing, but when I save the file the unformatted version gets written to disk.

First save: writes unformatted version to disk
Second save: writes formatted version to disk.

This only happens when the code needs to be formatted. If I type out a line of code and got the formatting correct myself, then it properly writes to disk the first time.

IntelliJ 2017.2
Save Action 0.16

Relevant preferences: Reformat File and Reformat only changed code (only if VCS configured) are both checked

@dubreuia
Copy link
Owner

dubreuia commented Aug 7, 2017

Thanks for the comment. I know this issue still exists but I haven't got around to fixing it. It also doesn't seem to happen all the time, but I definitely see it once in a while (when I commit to git then see a formatting change after the commit).

I'm pretty sure it has to do with multiple save event being thrown. I'm linking this old PR that filters duplicate events, it might help in that case: https://github.com/dubreuia/intellij-plugin-save-actions/pull/46/commits

@dubreuia
Copy link
Owner

This is a problem also when building / executing tests. It does: "build -> save actions -> tests -> fail with stack trace -> the stack trace lines are the old ones" (meaning the file was not saved at the proper time)

@blowsie
Copy link

blowsie commented Feb 15, 2018

I also have this issue with the most basic of settings
image

@dubreuia
Copy link
Owner

Hey @blowsie, thanks for reporting.

I know about this problem but I've been unable to fix it. It has something to do with how Intellij handles a file's life cycle. I'll probably find a way at some point but for now it doesn't work.

You can also see the problem with "Organize imports": if you have an unused import that is also a compile error (for example on a class that doesn't exists anymore), building the project will trigger save actions, that will clean the unused (and erroneous) import, but the build will still fail on the import that doesn't exist anymore. It happens to me a lot when I refactor code.

This is really annoying. If I get time at some point I'll seek help from Jetbrains.

@sniffertine
Copy link

Hey folks. This probably also happens when you use the feature to undo changes ("Rollback Lines") on the left panel. With this technique I can reproduce the described behaviour very consistently.

So maybe this helps to debug?

  1. Open a file that is commited to VCS
  2. Write a new line: new MalformedParameterizedTypeException();
  3. Notice on the left a green mark that there is a new added line
  4. Click on the green mark and undo the changes
  5. The now unused import of MalformedParameterizedTypeException will stay

@dubreuia
Copy link
Owner

Thanks for the information @sniffertine. It is similar to the fact that the plugin triggers only once per file. I'm pretty sure intellij keeps a list of dirty files, and removing a line from VCS (green square on the left) probably doesn't make the file dirty. No sure it is a save action bug in that case.

@sniffertine
Copy link

sniffertine commented Jul 13, 2018

I don‘t know if thats an auto save bug. There is definitely a file saved to the FS, but if IntelliJ doesn‘t trigger an event for plugins you cannot do much indeed.

Maybe you could subscribe to VFS changes using an event listener and be notified on more detailed file events that the usage of FILE_DOCUMENT_SYNC through message bus.
--> https://www.jetbrains.org/intellij/sdk/docs/basics/virtual_file_system.html#virtual-file-system-events

@dubreuia
Copy link
Owner

dubreuia commented Jan 17, 2019

Might be fixed by #207, reopen if necessary

@dubreuia dubreuia added the next label Jan 17, 2019
@dubreuia dubreuia removed the next label Jan 18, 2019
@dubreuia dubreuia added this to the 1.3.0 milestone Jan 18, 2019
@dubreuia
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants