on master help sign in
ran cargo clippy and cargo fmt
17f69a0Jan Hrastnik
helix-core/src/lib.rs+1−1
@@ -100,11 +100,11 @@ pub use unicode_general_category::get_general_category;
100#[doc(inline)]
100#[doc(inline)]
101pub use {regex, tree_sitter};
101pub use {regex, tree_sitter};
102
102
103+pub use graphemes::RopeGraphemes;
103pub use position::{coords_at_pos, pos_at_coords, Position};
104pub use position::{coords_at_pos, pos_at_coords, Position};
104pub use selection::{Range, Selection};
105pub use selection::{Range, Selection};
105pub use smallvec::SmallVec;
106pub use smallvec::SmallVec;
106pub use syntax::Syntax;
107pub use syntax::Syntax;
107−pub use graphemes::RopeGraphemes;
108
108
109pub use diagnostic::Diagnostic;
109pub use diagnostic::Diagnostic;
110pub use state::State;
110pub use state::State;
helix-view/src/document.rs+25−26
@@ -8,7 +8,8 @@ use helix_core::{
8 chars::{char_is_linebreak, char_is_whitespace},
8 chars::{char_is_linebreak, char_is_whitespace},
9 history::History,
9 history::History,
10 syntax::{LanguageConfiguration, LOADER},
10 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,
12};
13};
13
14
14use crate::{DocumentId, ViewId};
15use crate::{DocumentId, ViewId};
@@ -34,12 +35,12 @@ pub enum IndentStyle {
34#[derive(PartialEq, Copy, Clone, Debug)]
35#[derive(PartialEq, Copy, Clone, Debug)]
35pub enum LineEnding {
36pub enum LineEnding {
36 None = 0, // No line ending
37 None = 0, // No line ending
37− CRLF = 1, // CarriageReturn followed by LineFeed
38+ Crlf = 1, // CarriageReturn followed by LineFeed
38 LF = 2, // U+000A -- LineFeed
39 LF = 2, // U+000A -- LineFeed
39 VT = 3, // U+000B -- VerticalTab
40 VT = 3, // U+000B -- VerticalTab
40 FF = 4, // U+000C -- FormFeed
41 FF = 4, // U+000C -- FormFeed
41 CR = 5, // U+000D -- CarriageReturn
42 CR = 5, // U+000D -- CarriageReturn
42− NEL = 6, // U+0085 -- NextLine
43+ Nel = 6, // U+0085 -- NextLine
43 LS = 7, // U+2028 -- Line Separator
44 LS = 7, // U+2028 -- Line Separator
44 PS = 8, // U+2029 -- ParagraphSeparator
45 PS = 8, // U+2029 -- ParagraphSeparator
45}
46}
@@ -77,7 +78,7 @@ pub struct Document {
77
78
78 diagnostics: Vec<Diagnostic>,
79 diagnostics: Vec<Diagnostic>,
79 language_server: Option<Arc<helix_lsp::Client>>,
80 language_server: Option<Arc<helix_lsp::Client>>,
80− line_ending: LineEnding
81+ _line_ending: LineEnding,
81}
82}
82
83
83use std::fmt;
84use std::fmt;
@@ -166,31 +167,29 @@ pub fn canonicalize_path(path: &Path) -> std::io::Result<PathBuf> {
166pub fn auto_detect_line_ending(doc: &Rope) -> LineEnding {
167pub fn auto_detect_line_ending(doc: &Rope) -> LineEnding {
167 // based on https://github.com/cessen/led/blob/27572c8838a1c664ee378a19358604063881cc1d/src/editor/mod.rs#L88-L162
168 // based on https://github.com/cessen/led/blob/27572c8838a1c664ee378a19358604063881cc1d/src/editor/mod.rs#L88-L162
168
169
169− let mut ending = LineEnding::None;
170+ let mut ending = LineEnding::None;
170− for line in doc.lines().take(1) { // check first line only - unsure how sound this is
171+ 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 {
172+ ending = match line.len_chars() {
173− let g = RopeGraphemes::new(line.slice((line.len_chars() - 1)..))
173+ 1 => { let g = RopeGraphemes::new(line.slice((line.len_chars() - 1)..))
174− .last()
174+ .last()
175− .unwrap();
175+ .unwrap();
176− rope_slice_to_line_ending(&g)
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)..))
177+ n if n > 1 => { let g = RopeGraphemes::new(line.slice((line.len_chars() - 2)..))
179− .last()
178+ .last()
180− .unwrap();
179+ .unwrap();
181− rope_slice_to_line_ending(&g)
180+ rope_slice_to_line_ending(&g) }
182− } else {
183− LineEnding::None
181+ _ => LineEnding::None
184− };
182+
185 }
183 }
184+ }
186− ending
185+ ending
187}
186}
188
187
189pub fn rope_slice_to_line_ending(g: &RopeSlice) -> LineEnding {
188pub fn rope_slice_to_line_ending(g: &RopeSlice) -> LineEnding {
190 if let Some(text) = g.as_str() {
189 if let Some(text) = g.as_str() {
191 str_to_line_ending(text)
190 str_to_line_ending(text)
192 } else if g == "\u{000D}\u{000A}" {
191 } else if g == "\u{000D}\u{000A}" {
193− LineEnding::CRLF
192+ LineEnding::Crlf
194 } else {
193 } else {
195 // Not a line ending
194 // Not a line ending
196 LineEnding::None
195 LineEnding::None
@@ -199,12 +198,12 @@ pub fn rope_slice_to_line_ending(g: &RopeSlice) -> LineEnding {
199
198
200pub fn str_to_line_ending(g: &str) -> LineEnding {
199pub fn str_to_line_ending(g: &str) -> LineEnding {
201 match g {
200 match g {
202− "\u{000D}\u{000A}" => LineEnding::CRLF,
201+ "\u{000D}\u{000A}" => LineEnding::Crlf,
203 "\u{000A}" => LineEnding::LF,
202 "\u{000A}" => LineEnding::LF,
204 "\u{000B}" => LineEnding::VT,
203 "\u{000B}" => LineEnding::VT,
205 "\u{000C}" => LineEnding::FF,
204 "\u{000C}" => LineEnding::FF,
206 "\u{000D}" => LineEnding::CR,
205 "\u{000D}" => LineEnding::CR,
207− "\u{0085}" => LineEnding::NEL,
206+ "\u{0085}" => LineEnding::Nel,
208 "\u{2028}" => LineEnding::LS,
207 "\u{2028}" => LineEnding::LS,
209 "\u{2029}" => LineEnding::PS,
208 "\u{2029}" => LineEnding::PS,
210
209
@@ -217,7 +216,7 @@ use helix_lsp::lsp;
217use url::Url;
216use url::Url;
218
217
219impl Document {
218impl Document {
220− pub fn new(text: Rope, line_ending: LineEnding) -> Self {
219+ pub fn new(text: Rope, _line_ending: LineEnding) -> Self {
221 let changes = ChangeSet::new(&text);
220 let changes = ChangeSet::new(&text);
222 let old_state = None;
221 let old_state = None;
223
222
@@ -238,7 +237,7 @@ impl Document {
238 history: Cell::new(History::default()),
237 history: Cell::new(History::default()),
239 last_saved_revision: 0,
238 last_saved_revision: 0,
240 language_server: None,
239 language_server: None,
241− line_ending: line_ending
240+ _line_ending
242 }
241 }
243 }
242 }
244
243
helix-view/src/editor.rs+3−1
@@ -1,4 +1,6 @@
1+use crate::{
1−use crate::{theme::Theme, tree::Tree, Document, DocumentId, RegisterSelection, View, ViewId, LineEnding};
2+ theme::Theme, tree::Tree, Document, DocumentId, LineEnding, RegisterSelection, View, ViewId,
3+};
2use tui::layout::Rect;
4use tui::layout::Rect;
3use tui::terminal::CursorKind;
5use tui::terminal::CursorKind;
4
6