Skip to content

Commit

Permalink
ran cargo clippy and cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
janhrastnik committed Jun 11, 2021
1 parent dd1b5ca commit 51be0a9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion helix-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ pub use tendril::StrTendril as Tendril;
#[doc(inline)]
pub use {regex, tree_sitter};

pub use graphemes::RopeGraphemes;
pub use position::{coords_at_pos, pos_at_coords, Position};
pub use selection::{Range, Selection};
pub use smallvec::SmallVec;
pub use syntax::Syntax;
pub use graphemes::RopeGraphemes;

pub use diagnostic::Diagnostic;
pub use history::History;
Expand Down
51 changes: 25 additions & 26 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use std::sync::Arc;

use helix_core::{
syntax::{LanguageConfiguration, LOADER},
ChangeSet, Diagnostic, History, Rope, RopeSlice, RopeGraphemes, Selection, State, Syntax, Transaction,
ChangeSet, Diagnostic, History, Rope, RopeGraphemes, RopeSlice, Selection, State, Syntax,
Transaction,
};

use crate::{DocumentId, ViewId};
Expand All @@ -25,12 +26,12 @@ pub enum Mode {
#[derive(PartialEq, Copy, Clone, Debug)]
pub enum LineEnding {
None = 0, // No line ending
CRLF = 1, // CarriageReturn followed by LineFeed
Crlf = 1, // CarriageReturn followed by LineFeed
LF = 2, // U+000A -- LineFeed
VT = 3, // U+000B -- VerticalTab
FF = 4, // U+000C -- FormFeed
CR = 5, // U+000D -- CarriageReturn
NEL = 6, // U+0085 -- NextLine
Nel = 6, // U+0085 -- NextLine
LS = 7, // U+2028 -- Line Separator
PS = 8, // U+2029 -- ParagraphSeparator
}
Expand Down Expand Up @@ -65,7 +66,7 @@ pub struct Document {

diagnostics: Vec<Diagnostic>,
language_server: Option<Arc<helix_lsp::Client>>,
line_ending: LineEnding
_line_ending: LineEnding,
}

/// Like std::mem::replace() except it allows the replacement value to be mapped from the
Expand Down Expand Up @@ -131,31 +132,29 @@ pub fn canonicalize_path(path: &Path) -> std::io::Result<PathBuf> {
pub fn auto_detect_line_ending(doc: &Rope) -> LineEnding {
// based on https://github.com/cessen/led/blob/27572c8838a1c664ee378a19358604063881cc1d/src/editor/mod.rs#L88-L162

let mut ending = LineEnding::None;
for line in doc.lines().take(1) { // check first line only - unsure how sound this is
// Get the line ending
ending = if line.len_chars() == 1 {
let g = RopeGraphemes::new(line.slice((line.len_chars() - 1)..))
.last()
.unwrap();
rope_slice_to_line_ending(&g)
} else if line.len_chars() > 1 {
let g = RopeGraphemes::new(line.slice((line.len_chars() - 2)..))
.last()
.unwrap();
rope_slice_to_line_ending(&g)
} else {
LineEnding::None
};
let mut ending = LineEnding::None;
for line in doc.lines().take(1) { // check first line only - unsure how sound this is
ending = match line.len_chars() {
1 => { let g = RopeGraphemes::new(line.slice((line.len_chars() - 1)..))
.last()
.unwrap();
rope_slice_to_line_ending(&g)}
n if n > 1 => { let g = RopeGraphemes::new(line.slice((line.len_chars() - 2)..))
.last()
.unwrap();
rope_slice_to_line_ending(&g) }
_ => LineEnding::None

}
ending
}
ending
}

pub fn rope_slice_to_line_ending(g: &RopeSlice) -> LineEnding {
if let Some(text) = g.as_str() {
str_to_line_ending(text)
} else if g == "\u{000D}\u{000A}" {
LineEnding::CRLF
LineEnding::Crlf
} else {
// Not a line ending
LineEnding::None
Expand All @@ -164,12 +163,12 @@ pub fn rope_slice_to_line_ending(g: &RopeSlice) -> LineEnding {

pub fn str_to_line_ending(g: &str) -> LineEnding {
match g {
"\u{000D}\u{000A}" => LineEnding::CRLF,
"\u{000D}\u{000A}" => LineEnding::Crlf,
"\u{000A}" => LineEnding::LF,
"\u{000B}" => LineEnding::VT,
"\u{000C}" => LineEnding::FF,
"\u{000D}" => LineEnding::CR,
"\u{0085}" => LineEnding::NEL,
"\u{0085}" => LineEnding::Nel,
"\u{2028}" => LineEnding::LS,
"\u{2029}" => LineEnding::PS,

Expand All @@ -182,7 +181,7 @@ use helix_lsp::lsp;
use url::Url;

impl Document {
pub fn new(text: Rope, line_ending: LineEnding) -> Self {
pub fn new(text: Rope, _line_ending: LineEnding) -> Self {
let changes = ChangeSet::new(&text);
let old_state = None;

Expand All @@ -202,7 +201,7 @@ impl Document {
history: Cell::new(History::default()),
last_saved_revision: 0,
language_server: None,
line_ending: line_ending
_line_ending
}
}

Expand Down
4 changes: 3 additions & 1 deletion helix-view/src/editor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{theme::Theme, tree::Tree, Document, DocumentId, RegisterSelection, View, ViewId, LineEnding};
use crate::{
theme::Theme, tree::Tree, Document, DocumentId, LineEnding, RegisterSelection, View, ViewId,
};
use tui::layout::Rect;

use std::path::PathBuf;
Expand Down

0 comments on commit 51be0a9

Please sign in to comment.