Skip to content

Support "on type formatting" in Zed#4133

Open
janko wants to merge 1 commit into
Shopify:mainfrom
janko:zed-on-type-formatting
Open

Support "on type formatting" in Zed#4133
janko wants to merge 1 commit into
Shopify:mainfrom
janko:zed-on-type-formatting

Conversation

@janko

@janko janko commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Motivation

Zed doesn't support snippet syntax ($0) in document/onTypeFormatting responses, 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 has onTypeFormatting disabled 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:

{
  "lsp": {
    "ruby-lsp": {
      "initialization_options": {
        "enabledFeatures": {
          "onTypeFormatting": true
        }
      }
    }
  }
}

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

On type formatting for blocks is unhelpful due to cursor placement

1 participant