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

Can't save files after updating (if file formatting is not changed by Atom Beautify when saving) #1949

Closed
dalirnet opened this issue Nov 22, 2017 · 26 comments

Comments

@dalirnet
Copy link

Can't save files after updating!

@ghost
Copy link

ghost commented Nov 22, 2017

same!

@jromerob
Copy link

jromerob commented Nov 22, 2017

same , i have Beautify on Save option checked on Typescript

@aibeb
Copy link

aibeb commented Nov 22, 2017

same

@ejpcmac
Copy link

ejpcmac commented Nov 22, 2017

Same for C, C++ and Rust with Beautify on Save enabled. Works correctly when beautifying by hand before saving with the option disabled.

@lalilalai
Copy link

same!

@stevenzeck
Copy link
Contributor

stevenzeck commented Nov 22, 2017

Can you describe what happens when you try to save? Does it beautify and not save? Something else? Can you also confirm you are on Atom 1.21 or later?

@johanvanhelden
Copy link

johanvanhelden commented Nov 22, 2017

In my case the beautifying works, it's just that the file is not saved. As if atom-beautify prevents it. Because as soon as I disable the beautifying on save it works fine.

@ejpcmac
Copy link

ejpcmac commented Nov 22, 2017

@szeck87 Doing some tests with the Beautify on Save option enabled:

  • If I edit the code in a way it is not correctly formatted, it formats the code and saves the file correctly.
  • If I edit the code in a way it is correctly formatted, but different, it does not save.

@stevenzeck
Copy link
Contributor

Can you check the console to see if it's throwing an error?

@ejpcmac
Copy link

ejpcmac commented Nov 22, 2017

Wether it works or not, I get the same warning:

(node:2941) DeprecationWarning: Calling an asynchronous function without callback is deprecated.

However, I get a maybe more interesting error following these steps:

  1. edit a file in a way it is different but correctly formated,
  2. (optional) try to save the file: it does not work,
  3. with auto-save enabled, focus on another window or the console.

You then get the following error:

Uncaught Error: ENOENT: no such file or directory, unlink '/home/***/***/.atom-beautify.myfile.c'

@ejpcmac
Copy link

ejpcmac commented Nov 22, 2017

I see in the last commits there was a change to use the onWillSave event. There could be some problems there.

@exoticorn
Copy link

From what I can gather stepping through the code, is that the beautify function never resolves the Promise it returns unless the beautify process either fails or if oldText isnt text. (So if the beautification doesn't change the text, the promise is not resolved.)

The 'will-save' event is emitted in a function called Emitter.prototype.emitAsync which collects the promises the event callbacks return. I guess Atom will then wait for all the promises to resolve before writing the final text to disc.

So if the formatter doesn't change the text, that prevents Atom from saving the file.

@stevenzeck
Copy link
Contributor

Correct, there was a change. Before that change, it would save files twice: once after telling it to save, after it does that Atom Beautify beauties the file, then Atom Beautify saves it again. With the change last night, Atom waits for Atom Beautify to beautify the file, then saves.

@exoticorn
Copy link

And indeed, adding

        else
          setTimeout( -> resolve(text), 0)

to that if oldText isnt text allows correctly formatted text to save again.

@stevenzeck stevenzeck changed the title Can't save files after updating Can't save files after updating (if file formatting is not changed by Atom Beautify when saving) Nov 22, 2017
@stevenzeck
Copy link
Contributor

@exoticorn thanks for the findings. So in a nutshell, if you make changes to the file but in a way it's formatted properly (in which case Atom Beautify doesn't make changes), it fails. Correct?

@exoticorn
Copy link

Yes exactly. The workaround (other than my temporary fix above) is to just insert a random space somewhere that gets removed by the formatter. Then the file saves correctly. ;)

@Glavin001
Copy link
Owner

Bug related to #1924

I'm working on a fix right now.

@Glavin001
Copy link
Owner

Please provide an example code so I can quickly reproduce and ensure the bug fix works.

@Glavin001
Copy link
Owner

Glavin001 commented Nov 22, 2017

Reproduce:

<!doctype html>
<html>

<head>
<title>Test Page</title>
</head>

<body>
<h1>Hello</h1>
<p>
World!
</p>
</body>

</html>
  1. Save, which results in:
<!doctype html>
<html>

  <head>
    <title>Test Page</title>
  </head>

  <body>
    <h1>Hello</h1>
    <p>
      World!
    </p>
  </body>

</html>
  1. Change <p> tag to <a> tag, such that a change is detected, however the formatting is still correct:

image

  1. File is unsaved. Saving does not work.

@Glavin001
Copy link
Owner

Published the fix recommended by @exoticorn : #1949 (comment)

Patch version 0.30.8

Please try and let me know!

@stevenzeck
Copy link
Contributor

Sorry all, missed that use case when I made this change. Please test the fix @Glavin001 put out and let us know if there are any more issues.

@johanvanhelden
Copy link

Cheers @Glavin001 !

Just updated and everything works great again - it saves with and without beautifying.

No worries @szeck87 - we are, after all, only human. It's blazing fast tho. So I love the change :-)

@ejpcmac
Copy link

ejpcmac commented Nov 22, 2017

I get this error after updating, on Atom start:

nexpected , in /home/***/.atom/packages/atom-beautify/src/beautify.coffee:138:43
Hide Stack Trace
SyntaxError: unexpected ,
  at /home/***/.atom/packages/atom-beautify/src/beautify.coffee:138:43

Edit: After uninstalling and reinstalling the package, it works! Thanks!

@Glavin001
Copy link
Owner

Glavin001 commented Nov 22, 2017

Update: Please try v0.30.9

cc @ejpcmac

@jonathan-dejong
Copy link

jonathan-dejong commented Nov 22, 2017

Chiming in, Im not sure wether this is related or if there is by chance an issue with another package at the exact same time.. but right now, with 0.30.9, Atom freezes with just a busy-signal and the text "Autocomplete failure".

EDIT: I tried disabling this package and the issue is still there.. so nvm, seems to be issues with a different package.

@ejpcmac
Copy link

ejpcmac commented Nov 22, 2017

Ok @Glavin001, reinstallation made it work because I am now indeed at v0.30.9. Works great! Thanks again :)

@Glavin001 Glavin001 added this to the v0.30.9 milestone Nov 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants