ruby
ruby copied to clipboard
Collapsing ruby functions with `ensure` blocks don't fully collapse
When I collapse a function in a Ruby function in Zed, it shows ensure, rescue, etc. blocks.
Here's an example:
https://github.com/user-attachments/assets/0bd09d6e-7059-446f-8e23-c9f129b94381
You can recreate with a function like this:
def foo
puts "hi"
rescue
puts "Rescued!"
ensure
puts "bye ya'll"
end
I don't know if its a bug, bit it is surprising when I first collapse the function.
If Zed implemented language server support for textDocument/foldingRange then it could use Ruby LSP's implementation which collapses the whole def.
Doesn't seem on the radar though: https://github.com/zed-industries/zed/issues/26916
- https://github.com/zed-industries/zed/issues/26916#issuecomment-2752637321
- https://github.com/zed-industries/zed/issues/28091
I looked into whether this could be implemented directly in the Zed extension and it looks like it’s not possible. Zed folds based on the indentation level.
We can control which syntax queries trigger indents and outdents, which is why when you type ensure it is automatically outdented. But there’s no way to write queries for folding ranges as far as I can tell.