Support "on type formatting" in Zed#4133
Open
janko wants to merge 1 commit into
Open
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.
This was referenced Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 do the same for pipes, because it's better not to add anything than to do it incorrectly.
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: