Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/diffr-core/src/parse/fold_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ mod folds {
// A function whose body is one `match`: the block the shared query
// folds and the `match` the context query folds cover the same
// lines, so they are one fold. It is the `match`'s, the innermost
// node whose extent that region is, and it carries both tags.
// node whose extent that region is, and it carries both tags and
// the block's braces, since the `match` has no opener of its own.
let src =
"fn f(x: u32) -> u32 {\n match x {\n 1 => 2,\n _ => 3,\n }\n}\n";
let params = crate::config::Config::from_toml("")
Expand All @@ -349,6 +350,11 @@ mod folds {
"{:?}",
same_lines[0].tags
);
let syntax = same_lines[0].syntax.expect("the block's opener and closer");
assert_eq!(
text(src, &syntax),
"\n match x {\n 1 => 2,\n _ => 3,\n }\n"
);
}

#[test]
Expand Down
6 changes: 5 additions & 1 deletion crates/diffr-core/src/parse/folds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ fn depth(node: tree_sitter::Node<'_>) -> usize {
/// Merge folds of different nodes that cover the same whole lines, such as a
/// Rust `Self { … }` tail expression and the `{ … }` field list inside it.
/// The merged fold keeps the innermost node's range, indent and syntax (the
/// deepest among equal ranges), plus every fold's tags and relations.
/// deepest among equal ranges), plus every fold's tags and relations. When
/// the innermost node has no opener, as a lone statement in a block has none,
/// the fold keeps the opener and closer of the node it merged: they delimit
/// the same lines, so frontends still find the brackets and the rail.
/// A fold with no whole line merges with nothing.
fn merge_by_lines(
mut folds: Vec<(usize, usize, FoldMetadata)>,
Expand Down Expand Up @@ -275,6 +278,7 @@ fn merge_by_lines(
} else {
(owner, held, metadata)
};
kept.syntax = kept.syntax.or(lost.syntax);
kept.tags.extend(lost.tags);
kept.tags.sort();
kept.tags.dedup();
Expand Down
Loading