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

Formatting on save does not work with lsp based formatters #332

Open
vikigenius opened this issue Nov 28, 2024 · 0 comments
Open

Formatting on save does not work with lsp based formatters #332

vikigenius opened this issue Nov 28, 2024 · 0 comments

Comments

@vikigenius
Copy link

I opened an issue about this in doom-emacs doomemacs/doomemacs#8182

But this could also be a bug potentially in how apheleia handles buffer change detection

On Save Formatting:

  1. Set a custom formatter that uses lsp to format the buffer.
  2. Make some edit and save the file.

If the formatter was run, the file shows as saved. But if you open in another editor, you see that the formatter edits have not been applied.

The debug logs produce:

2024-11-28 13:42:20.388 <format-buffer>: Invoking apheleia-format-buffer on #<buffer about.tsx> with formatter (lsp)
2024-11-28 13:42:20.388 <run-formatter>: Running formatters (lsp) on buffer #<buffer about.tsx>
2024-11-28 13:42:20.418 <format-buffer>: Aborting in "about.tsx" because contents have changed

Manual Format and Save:

  1. Set a custom formatter that uses lsp to format the buffer.
  2. Manually call the formatter using apheleia-format-buffer
  3. Save after the edits have been applied.

This causes the file to be saved correctly and produces the following logs.

2024-11-28 12:45:21.914 <format-buffer>: Invoking apheleia-format-buffer on #<buffer about.tsx> with formatter (lsp)
2024-11-28 12:45:21.914 <run-formatter>: Running formatters (lsp) on buffer #<buffer about.tsx>
2024-11-28 12:45:21.937 <format-buffer>: Aborting in "about.tsx" because contents have changed
2024-11-28 12:45:29.143 <format-buffer>: Invoking apheleia-format-buffer on #<buffer about.tsx> with formatter (lsp)
2024-11-28 12:45:29.143 <run-formatter>: Running formatters (lsp) on buffer #<buffer about.tsx>
2024-11-28 12:45:29.166 <rcs>: Creating RCS patch between buffers with 572 and 572 bytes
2024-11-28 12:45:29.167 <process>: Trying to execute formatter process nil with ("diff" "--rcs" "--strip-trailing-cr" "--" "/home/void/Projects/Python/chatpyre/resources/pages/about.tsx" "-")
2024-11-28 12:45:29.167 <process>: Using make-process to create process apheleia-diff with ("diff" "--rcs" "--strip-trailing-cr" "--" "/home/void/Projects/Python/chatpyre/resources/pages/about.tsx" "-")
2024-11-28 12:45:29.168 <process>: Sending 572 bytes to stdin of process apheleia-diff
2024-11-28 12:45:29.208 <process>: Process diff exited with status 0 (not interrupted)
2024-11-28 12:45:29.210 <rcs>: Applying RCS patch from #<buffer  *apheleia-diff-stdout*> to #<buffer about.tsx>

I am still not sure about why the Aborting in "about.tsx" because contents have changed shows up when I just run the formatter manually.

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

No branches or pull requests

1 participant