Update Editor::select_larger_syntax_node (#36971)

When the cursor was sitting on a syntactically insignificant character,
like a `{` or `,`, this function was selecting only that character, when
what the user likely wanted was to select the next larger syntax node.

Those punctuation characters all seemed to be not "named", in
tree-sitter terminology, so I updated the function to walk up the node
tree until it found a node where `is_named()` is true.

Closes #4555 

Also, while writing the tests, the output of a failing test with the
wrong thing selected was harder to read than it needed to be.

It used to output a diff of ranges, like this:

<img width="217" height="111" alt="image"
src="https://github.com/user-attachments/assets/00de53a8-8776-47aa-8101-5a5b5bc3fa5e"
/>

I leveraged the existing `generate_marked_text` helper function and
updated the assertion to output a diff of the text with the selection
markers:

<img width="211" height="116" alt="image"
src="https://github.com/user-attachments/assets/53b2b882-2676-4c70-8718-e2e2ba6f254e"
/>

Happy to make that a separate PR, if needed.

Release Notes:

- Fixed Editor select_larger_syntax_node to be smart about punctuation.
This commit is contained in:
Paul Sadauskas
2025-09-09 12:13:20 -06:00
committed by GitHub
parent 61d4718f2b
commit b2d7e34e80
4 changed files with 204 additions and 14 deletions
+9 -2
View File
@@ -214,8 +214,15 @@ pub fn generate_marked_text(
}
}
} else {
marked_text.insert(range.end, '»');
marked_text.insert(range.start, '«');
match range.start.cmp(&range.end) {
Ordering::Equal => {
marked_text.insert(range.start, 'ˇ');
}
_ => {
marked_text.insert(range.end, '»');
marked_text.insert(range.start, '«');
}
}
}
}
marked_text