Skip to content

Fold: count enclosing multi-line nodes instead of raw AST depth - #9

Open
sonnix-msk wants to merge 1 commit into
Thorium:masterfrom
sonnix-msk:sonnix/folding
Open

sonnix-msk wants to merge 1 commit into
Thorium:masterfrom
sonnix-msk:sonnix/folding

Conversation

@sonnix-msk

Copy link
Copy Markdown

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:

for i in range(len(items)):
    do(i)
    log(i)

Before the change the for has 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.

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.
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.

Folding breaks when a header line contains an expression deeper than the body

1 participant