Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Folding Range functionality to air #146

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kv9898
Copy link

@kv9898 kv9898 commented Jan 12, 2025

This PR replicates my old PR to ark: posit-dev/ark#615.

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 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 kv9898 marked this pull request as ready for review January 12, 2025 17:24
@kv9898
Copy link
Author

kv9898 commented Jan 12, 2025

I'm sorry that the current form is not based on biome-rowan, but I struggled with the fact that the rowan ast does not treat comments as equivalent elements in the tree (rather as children of the next element?), and I didn't figure out how to extract the cursor location (line row and column), which are important for folding ranges. With tree-sitter, I can mimick a lot of existing AIR code and get it working quickly. Maybe we can talk about converting this tree-sitter-based protytype to biome_rowan later?

@kv9898
Copy link
Author

kv9898 commented Jan 15, 2025

@lionel- @DavisVaughan Let me know your thoughts when you guys are less busy.

None => String::new(),
};

let start = node.start_position();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find an equivalent of this using biome_rowan

);
folding_ranges.push(folding_range);
}
"comment" => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

biome_rowan treats comments as children of the next command. This is super annoying. Things are much neater with treesitter

let node_type = node.kind();

match node_type {
"parameters" | "arguments" | "braced_expression" => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if I miss some of other node types with brackets that I should take care of

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant