ruby icon indicating copy to clipboard operation
ruby copied to clipboard

Collapsing ruby functions with `ensure` blocks don't fully collapse

Open bradgessler opened this issue 1 year ago • 4 comments

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.

bradgessler avatar Oct 29 '24 06:10 bradgessler

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

andyw8 avatar Mar 24 '25 02:03 andyw8

  • https://github.com/zed-industries/zed/issues/26916#issuecomment-2752637321

andyw8 avatar Mar 25 '25 21:03 andyw8

  • https://github.com/zed-industries/zed/issues/28091

andyw8 avatar Apr 04 '25 14:04 andyw8

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.

joeldrapper avatar Apr 28 '25 22:04 joeldrapper