on master help sign in
added more changes from pr review for line_ending_detection
commit9c419fe05cd51c96df29ac02e3dc5c73cae4ef97 authorJan Hrastnik <jan.hrastnik2@gmail.com> dateWed 16 Jun 2021, 17:08 (5 years ago) parent5eb6918
4 files changed+12−37
helix-core/src/lib.rs+1−1 helix-core/src/line_ending.rs+5−14 helix-view/src/document.rs+6−18 helix-view/src/editor.rs−4
helix-core/src/lib.rs+1−1
@@ -110,5 +110,5 @@ pub use syntax::Syntax;
110110pub use diagnostic::Diagnostic;
111111pub use state::State;
112112
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};
114114pub use transaction::{Assoc, Change, ChangeSet, Operation, Transaction};
helix-core/src/line_ending.rs+5−14
@@ -1,16 +1,14 @@
11use crate::{Rope, RopeGraphemes, RopeSlice};
22
33/// 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
45#[derive(PartialEq, Copy, Clone, Debug)]
56pub enum LineEnding {
67 Crlf, // CarriageReturn followed by LineFeed
78 LF, // U+000A -- LineFeed
8− VT, // U+000B -- VerticalTab
9− FF, // U+000C -- FormFeed
109 CR, // U+000D -- CarriageReturn
1110 Nel, // U+0085 -- NextLine
1211 LS, // U+2028 -- Line Separator
13− PS, // U+2029 -- ParagraphSeparator
1412}
1513
1614pub fn rope_slice_to_line_ending(g: &RopeSlice) -> Option<LineEnding> {
@@ -28,13 +26,9 @@ pub fn str_to_line_ending(g: &str) -> Option<LineEnding> {
2826 match g {
2927 "\u{000D}\u{000A}" => Some(LineEnding::Crlf),
3028 "\u{000A}" => Some(LineEnding::LF),
31− "\u{000B}" => Some(LineEnding::VT),
32− "\u{000C}" => Some(LineEnding::FF),
3329 "\u{000D}" => Some(LineEnding::CR),
3430 "\u{0085}" => Some(LineEnding::Nel),
3531 "\u{2028}" => Some(LineEnding::LS),
36− "\u{2029}" => Some(LineEnding::PS),
37−
3832 // Not a line ending
3933 _ => None,
4034 }
@@ -65,10 +59,7 @@ pub fn auto_detect_line_ending(doc: &Rope) -> Option<LineEnding> {
6559 ending
6660}
6761
68−pub fn default_line_ending() -> Option<LineEnding> {
69− if cfg!(windows) {
70− Some(LineEnding::Crlf)
71− } else {
72− Some(LineEnding::LF)
73− }
74−}
62+#[cfg(target_os = "windows")]
63+pub const DEFAULT_LINE_ENDING: LineEnding = LineEnding::Crlf;
64+#[cfg(not(target_os = "windows"))]
65+pub const DEFAULT_LINE_ENDING: LineEnding = LineEnding::Lf;
helix-view/src/document.rs+6−18
@@ -5,14 +5,10 @@ use std::path::{Component, Path, PathBuf};
55use std::sync::Arc;
66
77use helix_core::{
8−<<<<<<< HEAD
98 chars::{char_is_linebreak, char_is_whitespace},
10− history::History,
11−=======
12− auto_detect_line_ending, default_line_ending,
13−>>>>>>> 491a8b3 (resolved conflict in rebase)
9+ auto_detect_line_ending, DEFAULT_LINE_ENDING, history::History,
1410 syntax::{LanguageConfiguration, LOADER},
15− ChangeSet, Diagnostic, History, LineEnding, Rope, Selection, State, Syntax, Transaction,
11+ ChangeSet, Diagnostic, LineEnding, Rope, Selection, State, Syntax, Transaction,
1612};
1713
1814use crate::{DocumentId, ViewId};
@@ -26,8 +22,6 @@ pub enum Mode {
2622 Insert,
2723}
2824
29−<<<<<<< HEAD
30−
3125#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
3226pub enum IndentStyle {
3327 Tabs,
@@ -49,8 +43,6 @@ pub enum LineEnding {
4943 PS = 8, // U+2029 -- ParagraphSeparator
5044}
5145
52−=======
53−>>>>>>> 491a8b3 (resolved conflict in rebase)
5446pub struct Document {
5547 // rope + selection
5648 pub(crate) id: DocumentId,
@@ -84,7 +76,7 @@ pub struct Document {
8476
8577 diagnostics: Vec<Diagnostic>,
8678 language_server: Option<Arc<helix_lsp::Client>>,
87− line_ending: Option<LineEnding>,
79+ line_ending: LineEnding,
8880}
8981
9082use std::fmt;
@@ -177,7 +169,6 @@ impl Document {
177169 pub fn new(text: Rope) -> Self {
178170 let changes = ChangeSet::new(&text);
179171 let old_state = None;
180− let line_ending = default_line_ending();
181172
182173 Self {
183174 id: DocumentId::default(),
@@ -196,7 +187,7 @@ impl Document {
196187 history: Cell::new(History::default()),
197188 last_saved_revision: 0,
198189 language_server: None,
199− line_ending,
190+ line_ending: DEFAULT_LINE_ENDING,
200191 }
201192 }
202193
@@ -217,16 +208,13 @@ impl Document {
217208 };
218209
219210 // 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);
221212
222213 let mut doc = Self::new(doc);
223214 // set the path and try detecting the language
224215 doc.set_path(&path)?;
225−<<<<<<< HEAD
226216 doc.detect_indent_style();
227−=======
228217 doc.set_line_ending(line_ending);
229−>>>>>>> 491a8b3 (resolved conflict in rebase)
230218
231219 Ok(doc)
232220 }
@@ -485,7 +473,7 @@ impl Document {
485473 self.selections.insert(view_id, selection);
486474 }
487475
488− pub fn set_line_ending(&mut self, line_ending: Option<LineEnding>) {
476+ pub fn set_line_ending(&mut self, line_ending: LineEnding) {
489477 self.line_ending = line_ending;
490478 }
491479
helix-view/src/editor.rs−4
@@ -8,13 +8,9 @@ use slotmap::SlotMap;
88
99use anyhow::Error;
1010
11−<<<<<<< HEAD
1211pub use helix_core::diagnostic::Severity;
1312pub use helix_core::register::Registers;
1413use helix_core::Position;
15−=======
16−pub use helix_core::{diagnostic::Severity, LineEnding};
17−>>>>>>> 491a8b3 (resolved conflict in rebase)
1814
1915#[derive(Debug)]
2016pub struct Editor {