ruby icon indicating copy to clipboard operation
ruby copied to clipboard

Enabling `onTypeFormatting` LSP feature in Ruby LSP causes issues

Open vitallium opened this issue 10 months ago • 3 comments

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
        }
      }
    }
  }
}

vitallium avatar Mar 01 '25 09:03 vitallium

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.

Hawkbawk avatar Jul 03 '25 18:07 Hawkbawk

Hi, until the upstream issue is fixed, the workaround disabling onTypeFormatting will now be applied automatically in https://github.com/zed-extensions/ruby/pull/142. Thanks.

vitallium avatar Jul 13 '25 09:07 vitallium

Is there a way for me to enable onTypeFormatting manually? I tried with:

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

But I'm still not seeing any document/onTypeFormatting requests sent to Ruby LSP when I type <enter> after def foo.

As I was writing this, I found https://github.com/zed-extensions/ruby/issues/72 which says Zed doesn't send those requests, but then I don't understand what "use_on_type_format": true setting does in Zed.

janko avatar Nov 19 '25 10:11 janko