Repository navigation
Fold: count enclosing multi-line nodes instead of raw AST depth - #9
Open
sonnix-msk wants to merge 1 commit into
Open
sonnix-msk wants to merge 1 commit into
sonnix-msk wants to merge 1 commit into
Conversation
Fixes the empty/truncated folds when a header line contains an expression deeper than the body (upstream issue Thorium#8). Extract the fix as a standalone PR to Thorium/NppTreeSitter when verified.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8.
Fold()derived a line's fold level from the node's absolute depth in the AST (the deepest node touching the line). A header line that contains a nested expression therefore gets a level higher than its own body, and Scintilla renders an empty fold. That is why folding only "sometimes" worked: it worked only when the body happened to be deeper than the deepest token of the header.This changes the level to count enclosing multi-line nodes instead: every multi-line node with children is exactly one fold level, and its body is one level deeper, regardless of how deep the expressions inside the header are. The tree root (the whole module) is skipped so it does not wrap the entire document in one fold.
Repro with the bundled Python grammar:
Before the change the
forhas an empty fold; afterwards it folds correctly. The same fix also covers the blank-line case (#3), since a blank line now inherits the level of the following non-blank line as before.Tested by reimplementing
Fold()against the bundled grammar DLLs (Python, C++, Java, Rust, Go, Ruby all stop producing empty folds) and live in Notepad++ 8.9.1 x64.