on master help sign in
fix `:indent-style` crash (#9087)

* removing unreachable statement in `:indent-style` * update checks when setting indent line and update docs * `cargo xtask docgen`

commit914c83420b9901f596bf771ad5f20495de9a070c authorTornaxO7 <tornax@proton.me> dateFri 15 Dec 2023, 19:05 (3 years ago) parent33d8560
3 files changed+6−6
book/src/generated/typable-cmd.md+1−1 helix-core/src/indent.rs+1−1 helix-term/src/commands/typed.rs+4−4
book/src/generated/typable-cmd.md+1−1
@@ -17,7 +17,7 @@
1717| `:write-buffer-close!`, `:wbc!` | Force write changes to disk creating necessary subdirectories and closes the buffer. Accepts an optional path (:write-buffer-close! some/path.txt) |
1818| `:new`, `:n` | Create a new scratch buffer. |
1919| `:format`, `:fmt` | Format the file using the LSP formatter. |
20−| `:indent-style` | Set the indentation style for editing. ('t' for tabs or 1-8 for number of spaces.) |
20+| `:indent-style` | Set the indentation style for editing. ('t' for tabs or 1-16 for number of spaces.) |
2121| `:line-ending` | Set the document's default line ending. Options: crlf, lf. |
2222| `:earlier`, `:ear` | Jump back to an earlier point in edit history. Accepts a number of steps or a time span. |
2323| `:later`, `:lat` | Jump to a later point in edit history. Accepts a number of steps or a time span. |
helix-core/src/indent.rs+1−1
@@ -22,7 +22,7 @@ pub enum IndentStyle {
2222
2323// 16 spaces
2424const INDENTS: &str = " ";
25−const MAX_INDENT: u8 = 16;
25+pub const MAX_INDENT: u8 = 16;
2626
2727impl IndentStyle {
2828 /// Creates an `IndentStyle` from an indentation string.
helix-term/src/commands/typed.rs+4−4
@@ -6,6 +6,7 @@ use crate::job::Job;
66use super::*;
77
88use helix_core::fuzzy::fuzzy_match;
9+use helix_core::indent::MAX_INDENT;
910use helix_core::{encoding, line_ending, path::get_canonicalized_path, shellwords::Shellwords};
1011use helix_lsp::{OffsetEncoding, Url};
1112use helix_view::document::DEFAULT_LANGUAGE_NAME;
@@ -476,8 +477,7 @@ fn set_indent_style(
476477 cx.editor.set_status(match style {
477478 Tabs => "tabs".to_owned(),
478479 Spaces(1) => "1 space".to_owned(),
479− Spaces(n) if (2..=8).contains(&n) => format!("{} spaces", n),
480− _ => unreachable!(), // Shouldn't happen.
480+ Spaces(n) => format!("{} spaces", n),
481481 });
482482 return Ok(());
483483 }
@@ -489,7 +489,7 @@ fn set_indent_style(
489489 Some(arg) => arg
490490 .parse::<u8>()
491491 .ok()
492− .filter(|n| (1..=8).contains(n))
492+ .filter(|n| (1..=MAX_INDENT).contains(n))
493493 .map(Spaces),
494494 _ => None,
495495 };
@@ -2606,7 +2606,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
26062606 TypableCommand {
26072607 name: "indent-style",
26082608 aliases: &[],
2609− doc: "Set the indentation style for editing. ('t' for tabs or 1-8 for number of spaces.)",
2609+ doc: "Set the indentation style for editing. ('t' for tabs or 1-16 for number of spaces.)",
26102610 fun: set_indent_style,
26112611 signature: CommandSignature::none(),
26122612 },