fix `:indent-style` crash (#9087)

* removing unreachable statement in `:indent-style`

* update checks when setting indent line and update docs

* `cargo xtask docgen`
pull/9097/head
TornaxO7 7 months ago committed by GitHub
parent 33d85606cf
commit 914c83420b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,7 +17,7 @@
| `: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) | | `: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) |
| `:new`, `:n` | Create a new scratch buffer. | | `:new`, `:n` | Create a new scratch buffer. |
| `:format`, `:fmt` | Format the file using the LSP formatter. | | `:format`, `:fmt` | Format the file using the LSP formatter. |
| `:indent-style` | Set the indentation style for editing. ('t' for tabs or 1-8 for number of spaces.) | | `:indent-style` | Set the indentation style for editing. ('t' for tabs or 1-16 for number of spaces.) |
| `:line-ending` | Set the document's default line ending. Options: crlf, lf. | | `:line-ending` | Set the document's default line ending. Options: crlf, lf. |
| `:earlier`, `:ear` | Jump back to an earlier point in edit history. Accepts a number of steps or a time span. | | `:earlier`, `:ear` | Jump back to an earlier point in edit history. Accepts a number of steps or a time span. |
| `:later`, `:lat` | Jump to a later point in edit history. Accepts a number of steps or a time span. | | `:later`, `:lat` | Jump to a later point in edit history. Accepts a number of steps or a time span. |

@ -22,7 +22,7 @@ pub enum IndentStyle {
// 16 spaces // 16 spaces
const INDENTS: &str = " "; const INDENTS: &str = " ";
const MAX_INDENT: u8 = 16; pub const MAX_INDENT: u8 = 16;
impl IndentStyle { impl IndentStyle {
/// Creates an `IndentStyle` from an indentation string. /// Creates an `IndentStyle` from an indentation string.

@ -6,6 +6,7 @@ use crate::job::Job;
use super::*; use super::*;
use helix_core::fuzzy::fuzzy_match; use helix_core::fuzzy::fuzzy_match;
use helix_core::indent::MAX_INDENT;
use helix_core::{encoding, line_ending, path::get_canonicalized_path, shellwords::Shellwords}; use helix_core::{encoding, line_ending, path::get_canonicalized_path, shellwords::Shellwords};
use helix_lsp::{OffsetEncoding, Url}; use helix_lsp::{OffsetEncoding, Url};
use helix_view::document::DEFAULT_LANGUAGE_NAME; use helix_view::document::DEFAULT_LANGUAGE_NAME;
@ -476,8 +477,7 @@ fn set_indent_style(
cx.editor.set_status(match style { cx.editor.set_status(match style {
Tabs => "tabs".to_owned(), Tabs => "tabs".to_owned(),
Spaces(1) => "1 space".to_owned(), Spaces(1) => "1 space".to_owned(),
Spaces(n) if (2..=8).contains(&n) => format!("{} spaces", n), Spaces(n) => format!("{} spaces", n),
_ => unreachable!(), // Shouldn't happen.
}); });
return Ok(()); return Ok(());
} }
@ -489,7 +489,7 @@ fn set_indent_style(
Some(arg) => arg Some(arg) => arg
.parse::<u8>() .parse::<u8>()
.ok() .ok()
.filter(|n| (1..=8).contains(n)) .filter(|n| (1..=MAX_INDENT).contains(n))
.map(Spaces), .map(Spaces),
_ => None, _ => None,
}; };
@ -2606,7 +2606,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
TypableCommand { TypableCommand {
name: "indent-style", name: "indent-style",
aliases: &[], aliases: &[],
doc: "Set the indentation style for editing. ('t' for tabs or 1-8 for number of spaces.)", doc: "Set the indentation style for editing. ('t' for tabs or 1-16 for number of spaces.)",
fun: set_indent_style, fun: set_indent_style,
signature: CommandSignature::none(), signature: CommandSignature::none(),
}, },

Loading…
Cancel
Save