@@ -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,
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
@@ -77,7 +78,7 @@ pub struct Document {
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,
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
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)..))
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)..))
180− .unwrap();
179+ .unwrap();
181− rope_slice_to_line_ending(&g)
180+ rope_slice_to_line_ending(&g) }
183− LineEnding::None
181+ _ => LineEnding::None
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
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 {
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,
@@ -217,7 +216,7 @@ use helix_lsp::lsp;
217use url::Url;
216use url::Url;
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;
@@ -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