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

Since https://github.com/helix-editor/helix/pull/8157 CSS, JSON and HTML language servers formatting creates extra unwanted undo points #8434

Open
David-Else opened this issue Oct 1, 2023 · 2 comments
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug

Comments

@David-Else
Copy link
Contributor

David-Else commented Oct 1, 2023

Summary

Now Helix automatically creates a trailing line ending if there is not one already, there is a problem in that the CSS, JSON and HTML language servers remove the last line ending when they format. This means that Helix adds a trailing line ending, then the servers remove it (or some other order of operations, the outcome is the same). Each step is added into the undo history which is a problem, especially if auto format is enabled.

Basically now you need to press undo several times in order to undo the last thing you changed. As Helix has format on save enabled by default then this happens constantly.

A quick partial fix would be to remove auto-save from the affected language servers, this would remove the majority of the problem. Not using the built in formatting, but instead using Prettier, is the current best full workaround.

What do people think the best solution is? #7155 describes it, I am not sure why it was closed. In the JSON language server you can add { "keepLines" = { "enable" = true } } to stop it removing the last line, but it also stops it getting rid of any blank lines which is not ideal. I have searched the APIs of the other language servers and can't seem to get anywhere with a command to stop them deleting the final line. I noticed some seem to have settings that suggest they might do the job, but then they do nothing when added to the Helix config.

Reproduction Steps

  1. Make a change in an HTML, CSS or JSON file such as selecting a word and deleting it.
  2. Save the file, autoformat is used by default (you can see the EOL character at the bottom of the file flicker)
  3. Press undo and you won't undo your last change, but instead undo the inserting and deleting of the final trailing line ending.

Helix log

NA

Platform

Linux

Terminal Emulator

Kitty

Helix Version

latest master

@David-Else David-Else added the C-bug Category: This is a bug label Oct 1, 2023
@kirawi kirawi added A-language-server Area: Language server client A-helix-term Area: Helix term improvements and removed A-language-server Area: Language server client labels Oct 3, 2023
@kirawi
Copy link
Member

kirawi commented Oct 6, 2023

One possible solution is to treat all edits on save as a single edit instead of multiple.

@pascalkuthe
Copy link
Member

That would be ideal but hard to implement because autofromatting is async. If you didn't add an undopoint after adding the trailing newline and some other change happened before the autoformatting fi ished. The autoformatting is aborted but then the trailing newline and that new change take-up a single undopoint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug
Projects
None yet
Development

No branches or pull requests

3 participants