Support "on type formatting" in Zed - #4133
Conversation
Zed doesn't support snippet syntax ($0) in `document/onTypeFormatting` responses, nor is it possible for its Ruby extension to implement it. For "end" and "heredoc end", we can work around this by inserting them in the line *below* the cursor. This prevents the cursor from moving after the inserted text, avoiding the need to rewind it. We can't support this at the EOF, as there is no next line, but that's the rarer scenario. This won't work for formatting on the same line, because Zed cannot rewind the cursor. Zed supports auto-closing brackets, so we skip closing curly braces. We do the same for pipes, because it's better not to add anything than to do it incorrectly.
|
Very eager to see this merged! |
|
Thank you for the PR. Can't we completely do without the cursor movement if we switch to the strategy you proposed for Zed? Even for other editors? Also, I do want to point out that the curly brace formatting is for occurrences inside interpolation |
Well, considering that I haven't found a way to do inline formatting (e.g.
Oh, didn't come to my mind, that makes sense 👍🏻 |
|
The |
Motivation
Zed doesn't support snippet syntax (
$0) indocument/onTypeFormattingresponses, nor is it possible for its Ruby extension to implement it. Because the cursor position isn't right after edits, Zed's Ruby extension currently hasonTypeFormattingdisabled by default for Ruby LSP.Fixes #2971
Implementation
For "end" and "heredoc end", we can work around this by inserting them in the line below the cursor. This prevents the cursor from moving after the inserted text, avoiding the need to rewind it. We can't support this at the EOF, as there is no next line, but that's the rarer scenario.
This won't work for formatting on the same line, because Zed cannot rewind the cursor. Zed already supports auto-closing brackets, so we skip closing curly braces. We also skip pipe auto-close, because it's better not to add anything than to end up with incorrect cursor placement.
Automated Tests
I've added unit tests.
Manual Tests
To test this in Zed, you first need to enable on type formatting in Zed settings: