on master help sign in
added more changes from pr review for line_ending_detection
9c419feJan Hrastnik
helix-core/src/lib.rs+1−1
@@ -110,5 +110,5 @@ pub use syntax::Syntax;
110pub use diagnostic::Diagnostic;
110pub use diagnostic::Diagnostic;
111pub use state::State;
111pub use state::State;
112
112
113−pub use line_ending::{auto_detect_line_ending, default_line_ending, LineEnding};
113+pub use line_ending::{auto_detect_line_ending, DEFAULT_LINE_ENDING, LineEnding};
114pub use transaction::{Assoc, Change, ChangeSet, Operation, Transaction};
114pub use transaction::{Assoc, Change, ChangeSet, Operation, Transaction};
helix-core/src/line_ending.rs+5−14
@@ -1,16 +1,14 @@
1use crate::{Rope, RopeGraphemes, RopeSlice};
1use crate::{Rope, RopeGraphemes, RopeSlice};
2
2
3/// Represents one of the valid Unicode line endings.
3/// Represents one of the valid Unicode line endings.
4+/// VT, FF and PS are excluded here, as we don't expect them to show up as a default line break
4#[derive(PartialEq, Copy, Clone, Debug)]
5#[derive(PartialEq, Copy, Clone, Debug)]
5pub enum LineEnding {
6pub enum LineEnding {
6 Crlf, // CarriageReturn followed by LineFeed
7 Crlf, // CarriageReturn followed by LineFeed
7 LF, // U+000A -- LineFeed
8 LF, // U+000A -- LineFeed
8− VT, // U+000B -- VerticalTab
9− FF, // U+000C -- FormFeed
10 CR, // U+000D -- CarriageReturn
9 CR, // U+000D -- CarriageReturn
11 Nel, // U+0085 -- NextLine
10 Nel, // U+0085 -- NextLine
12 LS, // U+2028 -- Line Separator
11 LS, // U+2028 -- Line Separator
13− PS, // U+2029 -- ParagraphSeparator
14}
12}
15
13
16pub fn rope_slice_to_line_ending(g: &RopeSlice) -> Option<LineEnding> {
14pub fn rope_slice_to_line_ending(g: &RopeSlice) -> Option<LineEnding> {
@@ -28,13 +26,9 @@ pub fn str_to_line_ending(g: &str) -> Option<LineEnding> {
28 match g {
26 match g {
29 "\u{000D}\u{000A}" => Some(LineEnding::Crlf),
27 "\u{000D}\u{000A}" => Some(LineEnding::Crlf),
30 "\u{000A}" => Some(LineEnding::LF),
28 "\u{000A}" => Some(LineEnding::LF),
31− "\u{000B}" => Some(LineEnding::VT),
32− "\u{000C}" => Some(LineEnding::FF),
33 "\u{000D}" => Some(LineEnding::CR),
29 "\u{000D}" => Some(LineEnding::CR),
34 "\u{0085}" => Some(LineEnding::Nel),
30 "\u{0085}" => Some(LineEnding::Nel),
35 "\u{2028}" => Some(LineEnding::LS),
31 "\u{2028}" => Some(LineEnding::LS),
36− "\u{2029}" => Some(LineEnding::PS),
37−
38 // Not a line ending
32 // Not a line ending
39 _ => None,
33 _ => None,
40 }
34 }
@@ -65,10 +59,7 @@ pub fn auto_detect_line_ending(doc: &Rope) -> Option<LineEnding> {
65 ending
59 ending
66}
60}
67
61
68−pub fn default_line_ending() -> Option<LineEnding> {
62+#[cfg(target_os = "windows")]
69− if cfg!(windows) {
70− Some(LineEnding::Crlf)
63+pub const DEFAULT_LINE_ENDING: LineEnding = LineEnding::Crlf;
71− } else {
64+#[cfg(not(target_os = "windows"))]
72− Some(LineEnding::LF)
65+pub const DEFAULT_LINE_ENDING: LineEnding = LineEnding::Lf;
73− }
74−}
helix-view/src/document.rs+6−18
@@ -5,14 +5,10 @@ use std::path::{Component, Path, PathBuf};
5use std::sync::Arc;
5use std::sync::Arc;
6
6
7use helix_core::{
7use helix_core::{
8−<<<<<<< HEAD
9 chars::{char_is_linebreak, char_is_whitespace},
8 chars::{char_is_linebreak, char_is_whitespace},
10− history::History,
9+ auto_detect_line_ending, DEFAULT_LINE_ENDING, history::History,
11−=======
12− auto_detect_line_ending, default_line_ending,
13−>>>>>>> 491a8b3 (resolved conflict in rebase)
14 syntax::{LanguageConfiguration, LOADER},
10 syntax::{LanguageConfiguration, LOADER},
15− ChangeSet, Diagnostic, History, LineEnding, Rope, Selection, State, Syntax, Transaction,
11+ ChangeSet, Diagnostic, LineEnding, Rope, Selection, State, Syntax, Transaction,
16};
12};
17
13
18use crate::{DocumentId, ViewId};
14use crate::{DocumentId, ViewId};
@@ -26,8 +22,6 @@ pub enum Mode {
26 Insert,
22 Insert,
27}
23}
28
24
29−<<<<<<< HEAD
30−
31#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
25#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
32pub enum IndentStyle {
26pub enum IndentStyle {
33 Tabs,
27 Tabs,
@@ -49,8 +43,6 @@ pub enum LineEnding {
49 PS = 8, // U+2029 -- ParagraphSeparator
43 PS = 8, // U+2029 -- ParagraphSeparator
50}
44}
51
45
52−=======
53−>>>>>>> 491a8b3 (resolved conflict in rebase)
54pub struct Document {
46pub struct Document {
55 // rope + selection
47 // rope + selection
56 pub(crate) id: DocumentId,
48 pub(crate) id: DocumentId,
@@ -84,7 +76,7 @@ pub struct Document {
84
76
85 diagnostics: Vec<Diagnostic>,
77 diagnostics: Vec<Diagnostic>,
86 language_server: Option<Arc<helix_lsp::Client>>,
78 language_server: Option<Arc<helix_lsp::Client>>,
87− line_ending: Option<LineEnding>,
79+ line_ending: LineEnding,
88}
80}
89
81
90use std::fmt;
82use std::fmt;
@@ -177,7 +169,6 @@ impl Document {
177 pub fn new(text: Rope) -> Self {
169 pub fn new(text: Rope) -> Self {
178 let changes = ChangeSet::new(&text);
170 let changes = ChangeSet::new(&text);
179 let old_state = None;
171 let old_state = None;
180− let line_ending = default_line_ending();
181
172
182 Self {
173 Self {
183 id: DocumentId::default(),
174 id: DocumentId::default(),
@@ -196,7 +187,7 @@ impl Document {
196 history: Cell::new(History::default()),
187 history: Cell::new(History::default()),
197 last_saved_revision: 0,
188 last_saved_revision: 0,
198 language_server: None,
189 language_server: None,
199− line_ending,
190+ line_ending: DEFAULT_LINE_ENDING,
200 }
191 }
201 }
192 }
202
193
@@ -217,16 +208,13 @@ impl Document {
217 };
208 };
218
209
219 // search for line endings
210 // search for line endings
220− let line_ending = auto_detect_line_ending(&doc);
211+ let line_ending = auto_detect_line_ending(&doc).unwrap_or(DEFAULT_LINE_ENDING);
221
212
222 let mut doc = Self::new(doc);
213 let mut doc = Self::new(doc);
223 // set the path and try detecting the language
214 // set the path and try detecting the language
224 doc.set_path(&path)?;
215 doc.set_path(&path)?;
225−<<<<<<< HEAD
226 doc.detect_indent_style();
216 doc.detect_indent_style();
227−=======
228 doc.set_line_ending(line_ending);
217 doc.set_line_ending(line_ending);
229−>>>>>>> 491a8b3 (resolved conflict in rebase)
230
218
231 Ok(doc)
219 Ok(doc)
232 }
220 }
@@ -485,7 +473,7 @@ impl Document {
485 self.selections.insert(view_id, selection);
473 self.selections.insert(view_id, selection);
486 }
474 }
487
475
488− pub fn set_line_ending(&mut self, line_ending: Option<LineEnding>) {
476+ pub fn set_line_ending(&mut self, line_ending: LineEnding) {
489 self.line_ending = line_ending;
477 self.line_ending = line_ending;
490 }
478 }
491
479
helix-view/src/editor.rs−4
@@ -8,13 +8,9 @@ use slotmap::SlotMap;
8
8
9use anyhow::Error;
9use anyhow::Error;
10
10
11−<<<<<<< HEAD
12pub use helix_core::diagnostic::Severity;
11pub use helix_core::diagnostic::Severity;
13pub use helix_core::register::Registers;
12pub use helix_core::register::Registers;
14use helix_core::Position;
13use helix_core::Position;
15−=======
16−pub use helix_core::{diagnostic::Severity, LineEnding};
17−>>>>>>> 491a8b3 (resolved conflict in rebase)
18
14
19#[derive(Debug)]
15#[derive(Debug)]
20pub struct Editor {
16pub struct Editor {