editor: Improve rewrapping when working with comments at different indentation levels (#18146)

This PR improves the `editor::Rewrap` command when working with comments
that were not all at the same indentation level.

We now use a heuristic of finding the most common indentation level for
each line, using the deepest indent in the event of a tie.

It also removes an `.unwrap()` that would previously lead to a panic in
this case. Instead of unwrapping we now log an error to the logs and
skip rewrapping for that selection.

Release Notes:

- Improved the behavior of `editor: rewrap` when working with a
selection that contained comments at different indentation levels.
This commit is contained in:
Marshall Bowers 2024-09-20 11:45:03 -04:00 committed by GitHub
parent ab1d466c5f
commit 759646e0a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 116 additions and 8 deletions

View file

@ -144,7 +144,7 @@ pub struct BufferSnapshot {
/// The kind and amount of indentation in a particular line. For now,
/// assumes that indentation is all the same character.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)]
pub struct IndentSize {
/// The number of bytes that comprise the indentation.
pub len: u32,
@ -153,7 +153,7 @@ pub struct IndentSize {
}
/// A whitespace character that's used for indentation.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)]
pub enum IndentKind {
/// An ASCII space character.
#[default]