-
Notifications
You must be signed in to change notification settings - Fork 189
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
Neoformat with svelte is causing unwritten changes to be undone #375
Comments
I ran into the same problem. Thanks for this issue, I couldn't for the life of me figure out what was causing this. I'm using the autocmd specified in #134, but with your autocmd BufWritePre * try | undojoin | silent noautocmd w | Neoformat | catch /^Vim\%((\a\+)\)\=:E790/ | finally | silent Neoformat | endtry
Edit: actually this isn't ideal either, it gives you the same issue but in reverse. If you try and undo then it'll redo your changes on save. Edit 2: I figured out the issue and submitted a PR (auto linked below) |
See #375. When making changes and then saving an unsaved buffer (like one would do with a BufWritePre autocmd to format on save) on a Svelte file the changes that haven't yet been saved get undone. I noticed the Svelte formatter used a different order of prettier arguments than all of the other formatters that use prettier. The `--stdin-filepath` argument had a couple other arguments before the file path. I reordered them so the file path immediately follows `--stdin-filepath` and that seems to have fixed the issue for me. I'm pretty sure what's happening is that Prettier ignores the buffer passed as stdin because it doesn't see the file path in the arguments as the value to `--stdin-filepath`, but instead as the file path to the file to format, so it just ignores the buffer text sent over stdin and loads the file from the filesystem which naturally won't have the buffer's changes as they haven't been saved yet. (You can see this by running the commands in the two different orders with `--loglevel debug` to see what it interpreted the cli arguments as.) The current order is doing something like this: ![image](https://user-images.githubusercontent.com/3468630/139522331-e805670f-bf0e-488a-a3e5-6d0232d8696a.png) The changed order is doing something like this: ![image](https://user-images.githubusercontent.com/3468630/139522352-74da6539-c4bd-4812-b9b0-e64fcb545b3d.png)
@itmecho This should work now. |
See sbdchd#375. When making changes and then saving an unsaved buffer (like one would do with a BufWritePre autocmd to format on save) on a Svelte file the changes that haven't yet been saved get undone. I noticed the Svelte formatter used a different order of prettier arguments than all of the other formatters that use prettier. The `--stdin-filepath` argument had a couple other arguments before the file path. I reordered them so the file path immediately follows `--stdin-filepath` and that seems to have fixed the issue for me. I'm pretty sure what's happening is that Prettier ignores the buffer passed as stdin because it doesn't see the file path in the arguments as the value to `--stdin-filepath`, but instead as the file path to the file to format, so it just ignores the buffer text sent over stdin and loads the file from the filesystem which naturally won't have the buffer's changes as they haven't been saved yet. (You can see this by running the commands in the two different orders with `--loglevel debug` to see what it interpreted the cli arguments as.) The current order is doing something like this: ![image](https://user-images.githubusercontent.com/3468630/139522331-e805670f-bf0e-488a-a3e5-6d0232d8696a.png) The changed order is doing something like this: ![image](https://user-images.githubusercontent.com/3468630/139522352-74da6539-c4bd-4812-b9b0-e64fcb545b3d.png)
I have a basic svelte component:
If I make a change and then run
Neoformat
, that change gets undone. For example, changing<p>{errorMessage}</p>
to<p>Error: {errorMessage}</p>
then runningNeoformat
reverts it back to<p>{errorMessage}</p>
.Here's the verbose output:
If however, I run
noautocmd w
first, thenNeoformat
it works perfectlyThe text was updated successfully, but these errors were encountered: