-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: main
Are you sure you want to change the base?
Conversation
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? |
@lionel- @DavisVaughan Let me know your thoughts when you guys are less busy. |
None => String::new(), | ||
}; | ||
|
||
let start = node.start_position(); |
There was a problem hiding this comment.
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" => { |
There was a problem hiding this comment.
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" => { |
There was a problem hiding this comment.
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
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)
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.