From b571f28641787ae4c5750e91899afdccc6d89ed6 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Thu, 1 Jul 2021 12:24:22 -0700 Subject: [PATCH] Remove #[allow(unused)] from helix-core, and fix unused imports. Still a bunch more warnings to fix in core, but it's a start. --- helix-core/src/history.rs | 1 - helix-core/src/indent.rs | 5 +- helix-core/src/lib.rs | 1 - helix-core/src/line_ending.rs | 2 +- helix-core/src/match_brackets.rs | 2 +- helix-core/src/movement.rs | 23 ++- helix-core/src/object.rs | 1 - helix-core/src/position.rs | 3 +- helix-core/src/selection.rs | 3 +- helix-core/src/syntax.rs | 274 ++++++++++++++++--------------- helix-core/src/transaction.rs | 5 +- 11 files changed, 162 insertions(+), 158 deletions(-) diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs index 236802758..b361b3f40 100644 --- a/helix-core/src/history.rs +++ b/helix-core/src/history.rs @@ -1,7 +1,6 @@ use crate::{ChangeSet, Rope, State, Transaction}; use once_cell::sync::Lazy; use regex::Regex; -use smallvec::{smallvec, SmallVec}; use std::num::NonZeroUsize; use std::time::{Duration, Instant}; diff --git a/helix-core/src/indent.rs b/helix-core/src/indent.rs index 8e0379e2d..373229a01 100644 --- a/helix-core/src/indent.rs +++ b/helix-core/src/indent.rs @@ -1,8 +1,8 @@ use crate::{ find_first_non_whitespace_char, syntax::{IndentQuery, LanguageConfiguration, Syntax}, - tree_sitter::{Node, Tree}, - Rope, RopeSlice, + tree_sitter::Node, + RopeSlice, }; /// To determine indentation of a newly inserted line, figure out the indentation at the last col @@ -150,6 +150,7 @@ pub fn suggested_indent_for_pos( #[cfg(test)] mod test { use super::*; + use crate::Rope; #[test] fn test_indent_level() { diff --git a/helix-core/src/lib.rs b/helix-core/src/lib.rs index ae135b00f..dfbbd7489 100644 --- a/helix-core/src/lib.rs +++ b/helix-core/src/lib.rs @@ -1,4 +1,3 @@ -#![allow(unused)] pub mod auto_pairs; pub mod chars; pub mod comment; diff --git a/helix-core/src/line_ending.rs b/helix-core/src/line_ending.rs index 7ea3f14af..e3ff6478d 100644 --- a/helix-core/src/line_ending.rs +++ b/helix-core/src/line_ending.rs @@ -1,4 +1,4 @@ -use crate::{Rope, RopeGraphemes, RopeSlice}; +use crate::{Rope, RopeSlice}; #[cfg(target_os = "windows")] pub const DEFAULT_LINE_ENDING: LineEnding = LineEnding::Crlf; diff --git a/helix-core/src/match_brackets.rs b/helix-core/src/match_brackets.rs index 288b45861..dcf481c20 100644 --- a/helix-core/src/match_brackets.rs +++ b/helix-core/src/match_brackets.rs @@ -1,4 +1,4 @@ -use crate::{Range, Rope, Selection, Syntax}; +use crate::{Rope, Syntax}; const PAIRS: &[(char, char)] = &[('(', ')'), ('{', '}'), ('[', ']'), ('<', '>')]; // limit matching pairs to only ( ) { } [ ] < > diff --git a/helix-core/src/movement.rs b/helix-core/src/movement.rs index a4c7f9c93..85c0e749a 100644 --- a/helix-core/src/movement.rs +++ b/helix-core/src/movement.rs @@ -1,12 +1,9 @@ -use std::iter::{self, from_fn, Peekable, SkipWhile}; +use std::iter::{self, from_fn}; use ropey::iter::Chars; use crate::{ - chars::{ - categorize_char, char_is_line_ending, char_is_punctuation, char_is_whitespace, - char_is_word, CharCategory, - }, + chars::{categorize_char, char_is_line_ending, CharCategory}, coords_at_pos, graphemes::{nth_next_grapheme_boundary, nth_prev_grapheme_boundary}, line_ending::{get_line_ending, line_end_char_index}, @@ -270,20 +267,20 @@ fn reached_target(target: WordMotionTarget, peek: char, next_peek: Option<&char> match target { WordMotionTarget::NextWordStart => { - (is_word_boundary(peek, *next_peek) - && (char_is_line_ending(*next_peek) || !next_peek.is_whitespace())) + is_word_boundary(peek, *next_peek) + && (char_is_line_ending(*next_peek) || !next_peek.is_whitespace()) } WordMotionTarget::NextWordEnd | WordMotionTarget::PrevWordStart => { - (is_word_boundary(peek, *next_peek) - && (!peek.is_whitespace() || char_is_line_ending(*next_peek))) + is_word_boundary(peek, *next_peek) + && (!peek.is_whitespace() || char_is_line_ending(*next_peek)) } WordMotionTarget::NextLongWordStart => { - (is_long_word_boundary(peek, *next_peek) - && (char_is_line_ending(*next_peek) || !next_peek.is_whitespace())) + is_long_word_boundary(peek, *next_peek) + && (char_is_line_ending(*next_peek) || !next_peek.is_whitespace()) } WordMotionTarget::NextLongWordEnd | WordMotionTarget::PrevLongWordStart => { - (is_long_word_boundary(peek, *next_peek) - && (!peek.is_whitespace() || char_is_line_ending(*next_peek))) + is_long_word_boundary(peek, *next_peek) + && (!peek.is_whitespace() || char_is_line_ending(*next_peek)) } } } diff --git a/helix-core/src/object.rs b/helix-core/src/object.rs index 1c644fb29..33d909715 100644 --- a/helix-core/src/object.rs +++ b/helix-core/src/object.rs @@ -1,5 +1,4 @@ use crate::{Range, RopeSlice, Selection, Syntax}; -use smallvec::smallvec; // TODO: to contract_selection we'd need to store the previous ranges before expand. // Maybe just contract to the first child node? diff --git a/helix-core/src/position.rs b/helix-core/src/position.rs index 392eee9cc..6e84707a5 100644 --- a/helix-core/src/position.rs +++ b/helix-core/src/position.rs @@ -1,7 +1,7 @@ use crate::{ chars::char_is_line_ending, graphemes::{nth_next_grapheme_boundary, RopeGraphemes}, - Rope, RopeSlice, + RopeSlice, }; /// Represents a single point in a text buffer. Zero indexed. @@ -70,6 +70,7 @@ pub fn pos_at_coords(text: RopeSlice, coords: Position) -> usize { #[cfg(test)] mod test { use super::*; + use crate::Rope; #[test] fn test_ordering() { diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs index 370a1f6e1..ff5dc23dd 100644 --- a/helix-core/src/selection.rs +++ b/helix-core/src/selection.rs @@ -2,7 +2,7 @@ //! single selection range. //! //! All positioning is done via `char` offsets into the buffer. -use crate::{Assoc, ChangeSet, Rope, RopeSlice}; +use crate::{Assoc, ChangeSet, RopeSlice}; use smallvec::{smallvec, SmallVec}; use std::borrow::Cow; @@ -406,6 +406,7 @@ pub fn split_on_matches( #[cfg(test)] mod test { use super::*; + use crate::Rope; #[test] #[should_panic] diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index c556a3477..1772b5af5 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -1,4 +1,10 @@ -use crate::{chars::char_is_line_ending, regex::Regex, Change, Rope, RopeSlice, Transaction}; +use crate::{ + chars::char_is_line_ending, + regex::Regex, + transaction::{ChangeSet, Operation}, + Rope, RopeSlice, Tendril, +}; + pub use helix_syntax::{get_language, get_language_name, Lang}; use arc_swap::ArcSwap; @@ -8,7 +14,7 @@ use std::{ cell::RefCell, collections::{HashMap, HashSet}, fmt, - path::{Path, PathBuf}, + path::Path, sync::Arc, }; @@ -473,12 +479,6 @@ pub struct LanguageLayer { pub(crate) tree: Option, } -use crate::{ - coords_at_pos, - transaction::{ChangeSet, Operation}, - Tendril, -}; - impl LanguageLayer { // pub fn new() -> Self { // Self { tree: None } @@ -1776,135 +1776,141 @@ impl> Iterator for Merge { } } -#[test] -fn test_parser() { - let highlight_names: Vec = [ - "attribute", - "constant", - "function.builtin", - "function", - "keyword", - "operator", - "property", - "punctuation", - "punctuation.bracket", - "punctuation.delimiter", - "string", - "string.special", - "tag", - "type", - "type.builtin", - "variable", - "variable.builtin", - "variable.parameter", - ] - .iter() - .cloned() - .map(String::from) - .collect(); - - let language = get_language(Lang::Rust); - let mut config = HighlightConfiguration::new( - language, - &std::fs::read_to_string( - "../helix-syntax/languages/tree-sitter-rust/queries/highlights.scm", - ) - .unwrap(), - &std::fs::read_to_string( - "../helix-syntax/languages/tree-sitter-rust/queries/injections.scm", - ) - .unwrap(), - "", // locals.scm - ) - .unwrap(); - config.configure(&highlight_names); - - let source = Rope::from_str( - " - struct Stuff {} - fn main() {} - ", - ); - let syntax = Syntax::new(&source, Arc::new(config)); - let tree = syntax.tree(); - let root = tree.root_node(); - assert_eq!(root.kind(), "source_file"); - - assert_eq!( - root.to_sexp(), - concat!( - "(source_file ", - "(struct_item name: (type_identifier) body: (field_declaration_list)) ", - "(function_item name: (identifier) parameters: (parameters) body: (block)))" +#[cfg(test)] +mod test { + use super::*; + use crate::{Rope, Transaction}; + + #[test] + fn test_parser() { + let highlight_names: Vec = [ + "attribute", + "constant", + "function.builtin", + "function", + "keyword", + "operator", + "property", + "punctuation", + "punctuation.bracket", + "punctuation.delimiter", + "string", + "string.special", + "tag", + "type", + "type.builtin", + "variable", + "variable.builtin", + "variable.parameter", + ] + .iter() + .cloned() + .map(String::from) + .collect(); + + let language = get_language(Lang::Rust); + let mut config = HighlightConfiguration::new( + language, + &std::fs::read_to_string( + "../helix-syntax/languages/tree-sitter-rust/queries/highlights.scm", + ) + .unwrap(), + &std::fs::read_to_string( + "../helix-syntax/languages/tree-sitter-rust/queries/injections.scm", + ) + .unwrap(), + "", // locals.scm ) - ); + .unwrap(); + config.configure(&highlight_names); + + let source = Rope::from_str( + " + struct Stuff {} + fn main() {} + ", + ); + let syntax = Syntax::new(&source, Arc::new(config)); + let tree = syntax.tree(); + let root = tree.root_node(); + assert_eq!(root.kind(), "source_file"); + + assert_eq!( + root.to_sexp(), + concat!( + "(source_file ", + "(struct_item name: (type_identifier) body: (field_declaration_list)) ", + "(function_item name: (identifier) parameters: (parameters) body: (block)))" + ) + ); - let struct_node = root.child(0).unwrap(); - assert_eq!(struct_node.kind(), "struct_item"); -} + let struct_node = root.child(0).unwrap(); + assert_eq!(struct_node.kind(), "struct_item"); + } -#[test] -fn test_input_edits() { - use crate::State; - use tree_sitter::InputEdit; - - let mut state = State::new("hello world!\ntest 123".into()); - let transaction = Transaction::change( - &state.doc, - vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(), - ); - let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes()); - // transaction.apply(&mut state); - - assert_eq!( - edits, - &[ - InputEdit { - start_byte: 6, - old_end_byte: 11, - new_end_byte: 10, - start_position: Point { row: 0, column: 6 }, - old_end_position: Point { row: 0, column: 11 }, - new_end_position: Point { row: 0, column: 10 } - }, - InputEdit { - start_byte: 12, - old_end_byte: 17, - new_end_byte: 12, - start_position: Point { row: 0, column: 12 }, - old_end_position: Point { row: 1, column: 4 }, - new_end_position: Point { row: 0, column: 12 } - } - ] - ); - - // Testing with the official example from tree-sitter - let mut state = State::new("fn test() {}".into()); - let transaction = - Transaction::change(&state.doc, vec![(8, 8, Some("a: u32".into()))].into_iter()); - let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes()); - transaction.apply(&mut state.doc); - - assert_eq!(state.doc, "fn test(a: u32) {}"); - assert_eq!( - edits, - &[InputEdit { - start_byte: 8, - old_end_byte: 8, - new_end_byte: 14, - start_position: Point { row: 0, column: 8 }, - old_end_position: Point { row: 0, column: 8 }, - new_end_position: Point { row: 0, column: 14 } - }] - ); -} + #[test] + fn test_input_edits() { + use crate::State; + use tree_sitter::InputEdit; + + let mut state = State::new("hello world!\ntest 123".into()); + let transaction = Transaction::change( + &state.doc, + vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(), + ); + let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes()); + // transaction.apply(&mut state); + + assert_eq!( + edits, + &[ + InputEdit { + start_byte: 6, + old_end_byte: 11, + new_end_byte: 10, + start_position: Point { row: 0, column: 6 }, + old_end_position: Point { row: 0, column: 11 }, + new_end_position: Point { row: 0, column: 10 } + }, + InputEdit { + start_byte: 12, + old_end_byte: 17, + new_end_byte: 12, + start_position: Point { row: 0, column: 12 }, + old_end_position: Point { row: 1, column: 4 }, + new_end_position: Point { row: 0, column: 12 } + } + ] + ); + + // Testing with the official example from tree-sitter + let mut state = State::new("fn test() {}".into()); + let transaction = + Transaction::change(&state.doc, vec![(8, 8, Some("a: u32".into()))].into_iter()); + let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes()); + transaction.apply(&mut state.doc); + + assert_eq!(state.doc, "fn test(a: u32) {}"); + assert_eq!( + edits, + &[InputEdit { + start_byte: 8, + old_end_byte: 8, + new_end_byte: 14, + start_position: Point { row: 0, column: 8 }, + old_end_position: Point { row: 0, column: 8 }, + new_end_position: Point { row: 0, column: 14 } + }] + ); + } -#[test] -fn test_load_runtime_file() { - // Test to make sure we can load some data from the runtime directory. - let contents = load_runtime_file("rust", "indents.toml").unwrap(); - assert!(!contents.is_empty()); + #[test] + fn test_load_runtime_file() { + // Test to make sure we can load some data from the runtime directory. + let contents = load_runtime_file("rust", "indents.toml").unwrap(); + assert!(!contents.is_empty()); - let results = load_runtime_file("rust", "does-not-exist"); - assert!(results.is_err()); + let results = load_runtime_file("rust", "does-not-exist"); + assert!(results.is_err()); + } } diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs index 10219142a..e907ecf7e 100644 --- a/helix-core/src/transaction.rs +++ b/helix-core/src/transaction.rs @@ -1,5 +1,5 @@ -use crate::{Range, Rope, Selection, State, Tendril}; -use std::{borrow::Cow, convert::TryFrom}; +use crate::{Range, Rope, Selection, Tendril}; +use std::borrow::Cow; /// (from, to, replacement) pub type Change = (usize, usize, Option); @@ -581,6 +581,7 @@ impl<'a> Iterator for ChangeIterator<'a> { #[cfg(test)] mod test { use super::*; + use crate::State; #[test] fn composition() {