Skip to content

Conversation

@kv9898
Copy link
Contributor

@kv9898 kv9898 commented May 28, 2025

Moving back from posit-dev/air#146.

Old description:

It seems that the call for folding ranges has been quite a while: posit-dev/positron#18, posit-dev/positron#2924, posit-dev/positron#3822.

I was initially only thinking about adding foldable comments, but it seems that doing this will disable the existing folding support for things like regions and brackets. Therefore, I rewrote these functionalities also.

The PR already supports the folding-range-handling of brackets, regions, code cells, indentations and nested comment sections:

(The screenshot is new, though)
image

Note that, compared to the old PR, this PR no longer relies on a naive search for brackets. Instead it uses the new tree_sitter of air to walk down the AST for node handling.

@kv9898
Copy link
Contributor Author

kv9898 commented Jun 3, 2025

are we good to go?

@lionel-
Copy link
Contributor

lionel- commented Jun 4, 2025

Let's try this out.

When this is ported to Rowan we should also consider a simple loop over an iterator that walks each node in DFS, like this: https://github.com/rust-lang/rust-analyzer/blob/789d9153e4615c63027305299f3a33d933e96464/crates/ide/src/folding_ranges.rs#L52

For nodes you can easily find the ending, and for sections we'd just match the next closing section within the current node. This way we avoid recursing (slower due to function calls, potential for overflow) and we simplify the logic (for instance no need to maintain stacks).

Thanks for the contribution!

@lionel- lionel- merged commit 63e1c15 into posit-dev:main Jun 4, 2025
6 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jun 4, 2025
@DavisVaughan
Copy link
Contributor

Thanks for playing ping pong with us @kv9898, sorry again about that!

@kv9898 kv9898 deleted the folding-range branch October 28, 2025 21:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants