Enabling `onTypeFormatting` LSP feature in Ruby LSP causes issues
It was reported via Reddit that onTypeFormatting (enabled by default) LSP feature in Ruby LSP causes issues:
Why? Ruby LSP tries to improve UX and complete block params automatically. Here is how it look in VSCode:
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
}
}
}
}
}
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.
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.
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.