on master help sign in
Remove #[allow(unused)] from helix-core, and fix unused imports.

Still a bunch more warnings to fix in core, but it's a start.

commitb571f28641787ae4c5750e91899afdccc6d89ed6 authorNathan Vegdahl <cessen@cessen.com> dateThu 1 Jul 2021, 12:24 (5 years ago) parent0b2d51c
11 files changed+162−158
helix-core/src/history.rs−1 helix-core/src/indent.rs+3−2 helix-core/src/lib.rs−1 helix-core/src/line_ending.rs+1−1 helix-core/src/match_brackets.rs+1−1 helix-core/src/movement.rs+10−13 helix-core/src/object.rs−1 helix-core/src/position.rs+2−1 helix-core/src/selection.rs+2−1 helix-core/src/syntax.rs+140−134 helix-core/src/transaction.rs+3−2
helix-core/src/history.rs−1
@@ -1,7 +1,6 @@
11use crate::{ChangeSet, Rope, State, Transaction};
22use once_cell::sync::Lazy;
33use regex::Regex;
4−use smallvec::{smallvec, SmallVec};
54use std::num::NonZeroUsize;
65use std::time::{Duration, Instant};
76
helix-core/src/indent.rs+3−2
@@ -1,8 +1,8 @@
11use crate::{
22 find_first_non_whitespace_char,
33 syntax::{IndentQuery, LanguageConfiguration, Syntax},
4− tree_sitter::{Node, Tree},
5− Rope, RopeSlice,
4+ tree_sitter::Node,
5+ RopeSlice,
66};
77
88/// 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(
150150#[cfg(test)]
151151mod test {
152152 use super::*;
153+ use crate::Rope;
153154
154155 #[test]
155156 fn test_indent_level() {
helix-core/src/lib.rs−1
@@ -1,4 +1,3 @@
1−#![allow(unused)]
21pub mod auto_pairs;
32pub mod chars;
43pub mod comment;
helix-core/src/line_ending.rs+1−1
@@ -1,4 +1,4 @@
1−use crate::{Rope, RopeGraphemes, RopeSlice};
1+use crate::{Rope, RopeSlice};
22
33#[cfg(target_os = "windows")]
44pub const DEFAULT_LINE_ENDING: LineEnding = LineEnding::Crlf;
helix-core/src/match_brackets.rs+1−1
@@ -1,4 +1,4 @@
1−use crate::{Range, Rope, Selection, Syntax};
1+use crate::{Rope, Syntax};
22
33const PAIRS: &[(char, char)] = &[('(', ')'), ('{', '}'), ('[', ']'), ('<', '>')];
44// limit matching pairs to only ( ) { } [ ] < >
helix-core/src/movement.rs+10−13
@@ -1,12 +1,9 @@
1−use std::iter::{self, from_fn, Peekable, SkipWhile};
1+use std::iter::{self, from_fn};
22
33use ropey::iter::Chars;
44
55use crate::{
6− chars::{
7− categorize_char, char_is_line_ending, char_is_punctuation, char_is_whitespace,
8− char_is_word, CharCategory,
9− },
6+ chars::{categorize_char, char_is_line_ending, CharCategory},
107 coords_at_pos,
118 graphemes::{nth_next_grapheme_boundary, nth_prev_grapheme_boundary},
129 line_ending::{get_line_ending, line_end_char_index},
@@ -270,20 +267,20 @@ fn reached_target(target: WordMotionTarget, peek: char, next_peek: Option<&char>
270267
271268 match target {
272269 WordMotionTarget::NextWordStart => {
273− (is_word_boundary(peek, *next_peek)
274− && (char_is_line_ending(*next_peek) || !next_peek.is_whitespace()))
270+ is_word_boundary(peek, *next_peek)
271+ && (char_is_line_ending(*next_peek) || !next_peek.is_whitespace())
275272 }
276273 WordMotionTarget::NextWordEnd | WordMotionTarget::PrevWordStart => {
277− (is_word_boundary(peek, *next_peek)
278− && (!peek.is_whitespace() || char_is_line_ending(*next_peek)))
274+ is_word_boundary(peek, *next_peek)
275+ && (!peek.is_whitespace() || char_is_line_ending(*next_peek))
279276 }
280277 WordMotionTarget::NextLongWordStart => {
281− (is_long_word_boundary(peek, *next_peek)
282− && (char_is_line_ending(*next_peek) || !next_peek.is_whitespace()))
278+ is_long_word_boundary(peek, *next_peek)
279+ && (char_is_line_ending(*next_peek) || !next_peek.is_whitespace())
283280 }
284281 WordMotionTarget::NextLongWordEnd | WordMotionTarget::PrevLongWordStart => {
285− (is_long_word_boundary(peek, *next_peek)
286− && (!peek.is_whitespace() || char_is_line_ending(*next_peek)))
282+ is_long_word_boundary(peek, *next_peek)
283+ && (!peek.is_whitespace() || char_is_line_ending(*next_peek))
287284 }
288285 }
289286}
helix-core/src/object.rs−1
@@ -1,5 +1,4 @@
11use crate::{Range, RopeSlice, Selection, Syntax};
2−use smallvec::smallvec;
32
43// TODO: to contract_selection we'd need to store the previous ranges before expand.
54// Maybe just contract to the first child node?
helix-core/src/position.rs+2−1
@@ -1,7 +1,7 @@
11use crate::{
22 chars::char_is_line_ending,
33 graphemes::{nth_next_grapheme_boundary, RopeGraphemes},
4− Rope, RopeSlice,
4+ RopeSlice,
55};
66
77/// Represents a single point in a text buffer. Zero indexed.
@@ -70,6 +70,7 @@ pub fn pos_at_coords(text: RopeSlice, coords: Position) -> usize {
7070#[cfg(test)]
7171mod test {
7272 use super::*;
73+ use crate::Rope;
7374
7475 #[test]
7576 fn test_ordering() {
helix-core/src/selection.rs+2−1
@@ -2,7 +2,7 @@
22//! single selection range.
33//!
44//! All positioning is done via `char` offsets into the buffer.
5−use crate::{Assoc, ChangeSet, Rope, RopeSlice};
5+use crate::{Assoc, ChangeSet, RopeSlice};
66use smallvec::{smallvec, SmallVec};
77use std::borrow::Cow;
88
@@ -406,6 +406,7 @@ pub fn split_on_matches(
406406#[cfg(test)]
407407mod test {
408408 use super::*;
409+ use crate::Rope;
409410
410411 #[test]
411412 #[should_panic]
helix-core/src/syntax.rs+140−134
@@ -1,4 +1,10 @@
1−use crate::{chars::char_is_line_ending, regex::Regex, Change, Rope, RopeSlice, Transaction};
1+use crate::{
2+ chars::char_is_line_ending,
3+ regex::Regex,
4+ transaction::{ChangeSet, Operation},
5+ Rope, RopeSlice, Tendril,
6+};
7+
28pub use helix_syntax::{get_language, get_language_name, Lang};
39
410use arc_swap::ArcSwap;
@@ -8,7 +14,7 @@ use std::{
814 cell::RefCell,
915 collections::{HashMap, HashSet},
1016 fmt,
11− path::{Path, PathBuf},
17+ path::Path,
1218 sync::Arc,
1319};
1420
@@ -473,12 +479,6 @@ pub struct LanguageLayer {
473479 pub(crate) tree: Option<Tree>,
474480}
475481
476−use crate::{
477− coords_at_pos,
478− transaction::{ChangeSet, Operation},
479− Tendril,
480−};
481−
482482impl LanguageLayer {
483483 // pub fn new() -> Self {
484484 // Self { tree: None }
@@ -1776,135 +1776,141 @@ impl<I: Iterator<Item = HighlightEvent>> Iterator for Merge<I> {
17761776 }
17771777}
17781778
1779−#[test]
1780−fn test_parser() {
1781− let highlight_names: Vec<String> = [
1782− "attribute",
1783− "constant",
1784− "function.builtin",
1785− "function",
1786− "keyword",
1787− "operator",
1788− "property",
1789− "punctuation",
1790− "punctuation.bracket",
1791− "punctuation.delimiter",
1792− "string",
1793− "string.special",
1794− "tag",
1795− "type",
1796− "type.builtin",
1797− "variable",
1798− "variable.builtin",
1799− "variable.parameter",
1800− ]
1801− .iter()
1802− .cloned()
1803− .map(String::from)
1804− .collect();
1805−
1806− let language = get_language(Lang::Rust);
1807− let mut config = HighlightConfiguration::new(
1808− language,
1809− &std::fs::read_to_string(
1810− "../helix-syntax/languages/tree-sitter-rust/queries/highlights.scm",
1811− )
1812− .unwrap(),
1813− &std::fs::read_to_string(
1814− "../helix-syntax/languages/tree-sitter-rust/queries/injections.scm",
1815− )
1816− .unwrap(),
1817− "", // locals.scm
1818− )
1819− .unwrap();
1820− config.configure(&highlight_names);
1821−
1822− let source = Rope::from_str(
1823− "
1824− struct Stuff {}
1825− fn main() {}
1826− ",
1827− );
1828− let syntax = Syntax::new(&source, Arc::new(config));
1829− let tree = syntax.tree();
1830− let root = tree.root_node();
1831− assert_eq!(root.kind(), "source_file");
1832−
1833− assert_eq!(
1834− root.to_sexp(),
1835− concat!(
1836− "(source_file ",
1837− "(struct_item name: (type_identifier) body: (field_declaration_list)) ",
1838− "(function_item name: (identifier) parameters: (parameters) body: (block)))"
1779+#[cfg(test)]
1780+mod test {
1781+ use super::*;
1782+ use crate::{Rope, Transaction};
1783+
1784+ #[test]
1785+ fn test_parser() {
1786+ let highlight_names: Vec<String> = [
1787+ "attribute",
1788+ "constant",
1789+ "function.builtin",
1790+ "function",
1791+ "keyword",
1792+ "operator",
1793+ "property",
1794+ "punctuation",
1795+ "punctuation.bracket",
1796+ "punctuation.delimiter",
1797+ "string",
1798+ "string.special",
1799+ "tag",
1800+ "type",
1801+ "type.builtin",
1802+ "variable",
1803+ "variable.builtin",
1804+ "variable.parameter",
1805+ ]
1806+ .iter()
1807+ .cloned()
1808+ .map(String::from)
1809+ .collect();
1810+
1811+ let language = get_language(Lang::Rust);
1812+ let mut config = HighlightConfiguration::new(
1813+ language,
1814+ &std::fs::read_to_string(
1815+ "../helix-syntax/languages/tree-sitter-rust/queries/highlights.scm",
1816+ )
1817+ .unwrap(),
1818+ &std::fs::read_to_string(
1819+ "../helix-syntax/languages/tree-sitter-rust/queries/injections.scm",
1820+ )
1821+ .unwrap(),
1822+ "", // locals.scm
18391823 )
1840− );
1824+ .unwrap();
1825+ config.configure(&highlight_names);
1826+
1827+ let source = Rope::from_str(
1828+ "
1829+ struct Stuff {}
1830+ fn main() {}
1831+ ",
1832+ );
1833+ let syntax = Syntax::new(&source, Arc::new(config));
1834+ let tree = syntax.tree();
1835+ let root = tree.root_node();
1836+ assert_eq!(root.kind(), "source_file");
1837+
1838+ assert_eq!(
1839+ root.to_sexp(),
1840+ concat!(
1841+ "(source_file ",
1842+ "(struct_item name: (type_identifier) body: (field_declaration_list)) ",
1843+ "(function_item name: (identifier) parameters: (parameters) body: (block)))"
1844+ )
1845+ );
18411846
1842− let struct_node = root.child(0).unwrap();
1843− assert_eq!(struct_node.kind(), "struct_item");
1844−}
1847+ let struct_node = root.child(0).unwrap();
1848+ assert_eq!(struct_node.kind(), "struct_item");
1849+ }
18451850
1846−#[test]
1847−fn test_input_edits() {
1848− use crate::State;
1849− use tree_sitter::InputEdit;
1850−
1851− let mut state = State::new("hello world!\ntest 123".into());
1852− let transaction = Transaction::change(
1853− &state.doc,
1854− vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),
1855− );
1856− let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes());
1857− // transaction.apply(&mut state);
1858−
1859− assert_eq!(
1860− edits,
1861− &[
1862− InputEdit {
1863− start_byte: 6,
1864− old_end_byte: 11,
1865− new_end_byte: 10,
1866− start_position: Point { row: 0, column: 6 },
1867− old_end_position: Point { row: 0, column: 11 },
1868− new_end_position: Point { row: 0, column: 10 }
1869− },
1870− InputEdit {
1871− start_byte: 12,
1872− old_end_byte: 17,
1873− new_end_byte: 12,
1874− start_position: Point { row: 0, column: 12 },
1875− old_end_position: Point { row: 1, column: 4 },
1876− new_end_position: Point { row: 0, column: 12 }
1877− }
1878− ]
1879− );
1880−
1881− // Testing with the official example from tree-sitter
1882− let mut state = State::new("fn test() {}".into());
1883− let transaction =
1884− Transaction::change(&state.doc, vec![(8, 8, Some("a: u32".into()))].into_iter());
1885− let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes());
1886− transaction.apply(&mut state.doc);
1887−
1888− assert_eq!(state.doc, "fn test(a: u32) {}");
1889− assert_eq!(
1890− edits,
1891− &[InputEdit {
1892− start_byte: 8,
1893− old_end_byte: 8,
1894− new_end_byte: 14,
1895− start_position: Point { row: 0, column: 8 },
1896− old_end_position: Point { row: 0, column: 8 },
1897− new_end_position: Point { row: 0, column: 14 }
1898− }]
1899− );
1900−}
1851+ #[test]
1852+ fn test_input_edits() {
1853+ use crate::State;
1854+ use tree_sitter::InputEdit;
1855+
1856+ let mut state = State::new("hello world!\ntest 123".into());
1857+ let transaction = Transaction::change(
1858+ &state.doc,
1859+ vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),
1860+ );
1861+ let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes());
1862+ // transaction.apply(&mut state);
1863+
1864+ assert_eq!(
1865+ edits,
1866+ &[
1867+ InputEdit {
1868+ start_byte: 6,
1869+ old_end_byte: 11,
1870+ new_end_byte: 10,
1871+ start_position: Point { row: 0, column: 6 },
1872+ old_end_position: Point { row: 0, column: 11 },
1873+ new_end_position: Point { row: 0, column: 10 }
1874+ },
1875+ InputEdit {
1876+ start_byte: 12,
1877+ old_end_byte: 17,
1878+ new_end_byte: 12,
1879+ start_position: Point { row: 0, column: 12 },
1880+ old_end_position: Point { row: 1, column: 4 },
1881+ new_end_position: Point { row: 0, column: 12 }
1882+ }
1883+ ]
1884+ );
1885+
1886+ // Testing with the official example from tree-sitter
1887+ let mut state = State::new("fn test() {}".into());
1888+ let transaction =
1889+ Transaction::change(&state.doc, vec![(8, 8, Some("a: u32".into()))].into_iter());
1890+ let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes());
1891+ transaction.apply(&mut state.doc);
1892+
1893+ assert_eq!(state.doc, "fn test(a: u32) {}");
1894+ assert_eq!(
1895+ edits,
1896+ &[InputEdit {
1897+ start_byte: 8,
1898+ old_end_byte: 8,
1899+ new_end_byte: 14,
1900+ start_position: Point { row: 0, column: 8 },
1901+ old_end_position: Point { row: 0, column: 8 },
1902+ new_end_position: Point { row: 0, column: 14 }
1903+ }]
1904+ );
1905+ }
19011906
1902−#[test]
1903−fn test_load_runtime_file() {
1904− // Test to make sure we can load some data from the runtime directory.
1905− let contents = load_runtime_file("rust", "indents.toml").unwrap();
1906− assert!(!contents.is_empty());
1907+ #[test]
1908+ fn test_load_runtime_file() {
1909+ // Test to make sure we can load some data from the runtime directory.
1910+ let contents = load_runtime_file("rust", "indents.toml").unwrap();
1911+ assert!(!contents.is_empty());
19071912
1908− let results = load_runtime_file("rust", "does-not-exist");
1909− assert!(results.is_err());
1913+ let results = load_runtime_file("rust", "does-not-exist");
1914+ assert!(results.is_err());
1915+ }
19101916}
helix-core/src/transaction.rs+3−2
@@ -1,5 +1,5 @@
1−use crate::{Range, Rope, Selection, State, Tendril};
2−use std::{borrow::Cow, convert::TryFrom};
1+use crate::{Range, Rope, Selection, Tendril};
2+use std::borrow::Cow;
33
44/// (from, to, replacement)
55pub type Change = (usize, usize, Option<Tendril>);
@@ -581,6 +581,7 @@ impl<'a> Iterator for ChangeIterator<'a> {
581581#[cfg(test)]
582582mod test {
583583 use super::*;
584+ use crate::State;
584585
585586 #[test]
586587 fn composition() {