on master help sign in
ran cargo clippy and cargo fmt
commit17f69a03e0bd6c7bee7e26237dc47dfa0e0dd7c9 authorJan Hrastnik <jan.hrastnik2@gmail.com> dateFri 11 Jun 2021, 23:57 (5 years ago) parent3756c21
3 files changed+29−28
helix-core/src/lib.rs+1−1 helix-view/src/document.rs+25−26 helix-view/src/editor.rs+3−1
helix-core/src/lib.rs+1−1
@@ -100,11 +100,11 @@ pub use unicode_general_category::get_general_category;
100100#[doc(inline)]
101101pub use {regex, tree_sitter};
102102
103+pub use graphemes::RopeGraphemes;
103104pub use position::{coords_at_pos, pos_at_coords, Position};
104105pub use selection::{Range, Selection};
105106pub use smallvec::SmallVec;
106107pub use syntax::Syntax;
107−pub use graphemes::RopeGraphemes;
108108
109109pub use diagnostic::Diagnostic;
110110pub use state::State;
helix-view/src/document.rs+25−26
@@ -8,7 +8,8 @@ use helix_core::{
88 chars::{char_is_linebreak, char_is_whitespace},
99 history::History,
1010 syntax::{LanguageConfiguration, LOADER},
11− ChangeSet, Diagnostic, History, Rope, RopeSlice, RopeGraphemes, Selection, State, Syntax, Transaction,
11+ ChangeSet, Diagnostic, History, Rope, RopeGraphemes, RopeSlice, Selection, State, Syntax,
12+ Transaction,
1213};
1314
1415use crate::{DocumentId, ViewId};
@@ -34,12 +35,12 @@ pub enum IndentStyle {
3435#[derive(PartialEq, Copy, Clone, Debug)]
3536pub enum LineEnding {
3637 None = 0, // No line ending
37− CRLF = 1, // CarriageReturn followed by LineFeed
38+ Crlf = 1, // CarriageReturn followed by LineFeed
3839 LF = 2, // U+000A -- LineFeed
3940 VT = 3, // U+000B -- VerticalTab
4041 FF = 4, // U+000C -- FormFeed
4142 CR = 5, // U+000D -- CarriageReturn
42− NEL = 6, // U+0085 -- NextLine
43+ Nel = 6, // U+0085 -- NextLine
4344 LS = 7, // U+2028 -- Line Separator
4445 PS = 8, // U+2029 -- ParagraphSeparator
4546}
@@ -77,7 +78,7 @@ pub struct Document {
7778
7879 diagnostics: Vec<Diagnostic>,
7980 language_server: Option<Arc<helix_lsp::Client>>,
80− line_ending: LineEnding
81+ _line_ending: LineEnding,
8182}
8283
8384use std::fmt;
@@ -166,31 +167,29 @@ pub fn canonicalize_path(path: &Path) -> std::io::Result<PathBuf> {
166167pub fn auto_detect_line_ending(doc: &Rope) -> LineEnding {
167168 // based on https://github.com/cessen/led/blob/27572c8838a1c664ee378a19358604063881cc1d/src/editor/mod.rs#L88-L162
168169
169− let mut ending = LineEnding::None;
170− for line in doc.lines().take(1) { // check first line only - unsure how sound this is
171− // Get the line ending
172− ending = if line.len_chars() == 1 {
173− let g = RopeGraphemes::new(line.slice((line.len_chars() - 1)..))
174− .last()
175− .unwrap();
176− rope_slice_to_line_ending(&g)
177− } else if line.len_chars() > 1 {
178− let g = RopeGraphemes::new(line.slice((line.len_chars() - 2)..))
179− .last()
180− .unwrap();
181− rope_slice_to_line_ending(&g)
182− } else {
183− LineEnding::None
184− };
170+ let mut ending = LineEnding::None;
171+ for line in doc.lines().take(1) { // check first line only - unsure how sound this is
172+ ending = match line.len_chars() {
173+ 1 => { let g = RopeGraphemes::new(line.slice((line.len_chars() - 1)..))
174+ .last()
175+ .unwrap();
176+ rope_slice_to_line_ending(&g)}
177+ n if n > 1 => { let g = RopeGraphemes::new(line.slice((line.len_chars() - 2)..))
178+ .last()
179+ .unwrap();
180+ rope_slice_to_line_ending(&g) }
181+ _ => LineEnding::None
182+
185183 }
186− ending
184+ }
185+ ending
187186}
188187
189188pub fn rope_slice_to_line_ending(g: &RopeSlice) -> LineEnding {
190189 if let Some(text) = g.as_str() {
191190 str_to_line_ending(text)
192191 } else if g == "\u{000D}\u{000A}" {
193− LineEnding::CRLF
192+ LineEnding::Crlf
194193 } else {
195194 // Not a line ending
196195 LineEnding::None
@@ -199,12 +198,12 @@ pub fn rope_slice_to_line_ending(g: &RopeSlice) -> LineEnding {
199198
200199pub fn str_to_line_ending(g: &str) -> LineEnding {
201200 match g {
202− "\u{000D}\u{000A}" => LineEnding::CRLF,
201+ "\u{000D}\u{000A}" => LineEnding::Crlf,
203202 "\u{000A}" => LineEnding::LF,
204203 "\u{000B}" => LineEnding::VT,
205204 "\u{000C}" => LineEnding::FF,
206205 "\u{000D}" => LineEnding::CR,
207− "\u{0085}" => LineEnding::NEL,
206+ "\u{0085}" => LineEnding::Nel,
208207 "\u{2028}" => LineEnding::LS,
209208 "\u{2029}" => LineEnding::PS,
210209
@@ -217,7 +216,7 @@ use helix_lsp::lsp;
217216use url::Url;
218217
219218impl Document {
220− pub fn new(text: Rope, line_ending: LineEnding) -> Self {
219+ pub fn new(text: Rope, _line_ending: LineEnding) -> Self {
221220 let changes = ChangeSet::new(&text);
222221 let old_state = None;
223222
@@ -238,7 +237,7 @@ impl Document {
238237 history: Cell::new(History::default()),
239238 last_saved_revision: 0,
240239 language_server: None,
241− line_ending: line_ending
240+ _line_ending
242241 }
243242 }
244243
helix-view/src/editor.rs+3−1
@@ -1,4 +1,6 @@
1−use crate::{theme::Theme, tree::Tree, Document, DocumentId, RegisterSelection, View, ViewId, LineEnding};
1+use crate::{
2+ theme::Theme, tree::Tree, Document, DocumentId, LineEnding, RegisterSelection, View, ViewId,
3+};
24use tui::layout::Rect;
35use tui::terminal::CursorKind;
46