Skip to content

Enabling onTypeFormatting LSP feature in Ruby LSP causes issues #38

Open

Description

@vitallium

It was reported via Reddit that onTypeFormatting (enabled by default) LSP feature in Ruby LSP causes issues:

Image

Why? Ruby LSP tries to improve UX and complete block params automatically. Here is how it look in VSCode:

Image

This is done by sending the following response:

[
    {
        "range": {
            "start": {
                "line": 1,
                "character": 12
            },
            "end": {
                "line": 1,
                "character": 12
            }
        },
        "newText": "|"
    },
    {
        "range": {
            "start": {
                "line": 1,
                "character": 12
            },
            "end": {
                "line": 1,
                "character": 12
            }
        },
        "newText": "$0"
    }
]

Specifically the last TextEdit command breaks bevahior in Zed:

    {
        "range": {
            "start": {
                "line": 1,
                "character": 12
            },
            "end": {
                "line": 1,
                "character": 12
            }
        },
        "newText": "$0"
    }

This commands moves the cursor to the $0 the final cursor position. $0 is a part of the LSP Snippets.

Workaround

The workaround is to disable onTypeFormatting via Zed settings like this:

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

Activity

  1. added and removed
    upstreamZed issue (not extension)
    on Apr 18, 2025
  2. added theissue type on Apr 24, 2025
  3. Hawkbawk commented on Jul 3, 2025

    @Hawkbawk
    Contributor

    Glad I finally found this, I was about to open a new issue. I thought it might be related to the treesitter queries somehow and was going mad trying to figure out how to stop it. Is there some kind of change that we need to make upstream in Zed to get this to work properly? onTypeFormatting is nice to have, especially to solve #72 , which we can't do ourselves with the current extension API.

  4. vitallium commented on Jul 13, 2025

    @vitallium
    CollaboratorAuthor

    Hi, until the upstream issue is fixed, the workaround disabling onTypeFormatting will now be applied automatically in #142. Thanks.

  5. janko commented on Nov 19, 2025

    @janko
    Contributor

    For those who are looking to re-enable on type formatting to test it out:

    {
      "lsp": {
        "ruby-lsp": {
          "initialization_options": {
            "enabledFeatures": {
              "onTypeFormatting": true
            }
          }
        }
      }
    }
  6. janko commented on Dec 26, 2025

    @janko
    Contributor

    The primary issue here is that document/onTypeFormatting LSP request doesn't officially support the snippet syntax, or any way to bring the cursor back after inserting text. Ruby LSP appends the $0 to the response for VSCode, which extends document/onTypeFormatting implementation to support snippet syntax.

    Zed doesn't appear to support snippet syntax here, which is technically correct, as it matches the LSP spec. But I think without this it's not possible for Ruby LSP or this extension to properly apply on type formatting features in Zed.

    So, either Zed adds support for snippet syntax in document/onTypeFormatting (even though it's not in the LSP spec), or Ruby LSP implements an alternate way to provide the same features (e.g. via diagnostics).

  7. janko commented on Jun 11, 2026

    @janko
    Contributor

    I found a way to support on type formatting in Zed without support for cursor rewinding ($0): Shopify/ruby-lsp#4133

    It supports "end" and "heredoc end" insertion everywhere except EOF. I disabled curly brace and pipe autoclose, as those cannot be supported without cursor rewinding, so it's better not to insert anything than to have wrong cursor position (and Zed already supports curly brace autoclose).

  8. JacobNWolf commented on Oct 18, 2026

    @JacobNWolf

    I saw that zed-industries/zed#61823 actually made some changes that make this a lot easier, but there is still a bug in both Zed and Ruby LSP. I've opened PRs to fix them that are minimally invasive and tested these locally and all is working 😄

    PRs:

    Once these merge, I feel pretty confident that a change could be made to this extension to enable on type formatting as a default.

    Could we prioritize these in Zed and Ruby LSP? @SomeoneToIgnore @vinistock

  9. JacobNWolf commented on Oct 20, 2026

    @JacobNWolf

    Ok, worked with @SomeoneToIgnore to get zed-industries/zed#65769 ready for the release after next (next week's). I've bumped some folks at Shopify on Shopify/ruby-lsp#4242.

    Once those two merge, release, and I can test, we can safely merge #351, which I've just opened now.

    cc: @vitallium

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions