on master help sign in
Remove #[allow(unused)] from helix-core, and fix unused imports.
b571f28Nathan Vegdahl
helix-core/src/history.rs−1
@@ -1,7 +1,6 @@
1use crate::{ChangeSet, Rope, State, Transaction};
1use crate::{ChangeSet, Rope, State, Transaction};
2use once_cell::sync::Lazy;
2use once_cell::sync::Lazy;
3use regex::Regex;
3use regex::Regex;
4−use smallvec::{smallvec, SmallVec};
5use std::num::NonZeroUsize;
4use std::num::NonZeroUsize;
6use std::time::{Duration, Instant};
5use std::time::{Duration, Instant};
7
6
helix-core/src/indent.rs+3−2
@@ -1,8 +1,8 @@
1use crate::{
1use crate::{
2 find_first_non_whitespace_char,
2 find_first_non_whitespace_char,
3 syntax::{IndentQuery, LanguageConfiguration, Syntax},
3 syntax::{IndentQuery, LanguageConfiguration, Syntax},
4− tree_sitter::{Node, Tree},
4+ tree_sitter::Node,
5− Rope, RopeSlice,
5+ RopeSlice,
6};
6};
7
7
8/// To determine indentation of a newly inserted line, figure out the indentation at the last col
8/// 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(
150#[cfg(test)]
150#[cfg(test)]
151mod test {
151mod test {
152 use super::*;
152 use super::*;
153+ use crate::Rope;
153
154
154 #[test]
155 #[test]
155 fn test_indent_level() {
156 fn test_indent_level() {
helix-core/src/lib.rs−1
@@ -1,4 +1,3 @@
1−#![allow(unused)]
2pub mod auto_pairs;
1pub mod auto_pairs;
3pub mod chars;
2pub mod chars;
4pub mod comment;
3pub 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};
2
2
3#[cfg(target_os = "windows")]
3#[cfg(target_os = "windows")]
4pub const DEFAULT_LINE_ENDING: LineEnding = LineEnding::Crlf;
4pub 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};
2
2
3const PAIRS: &[(char, char)] = &[('(', ')'), ('{', '}'), ('[', ']'), ('<', '>')];
3const PAIRS: &[(char, char)] = &[('(', ')'), ('{', '}'), ('[', ']'), ('<', '>')];
4// limit matching pairs to only ( ) { } [ ] < >
4// 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};
2
2
3use ropey::iter::Chars;
3use ropey::iter::Chars;
4
4
5use crate::{
5use crate::{
6− chars::{
7− categorize_char, char_is_line_ending, char_is_punctuation, char_is_whitespace,
6+ chars::{categorize_char, char_is_line_ending, CharCategory},
8− char_is_word, CharCategory,
9− },
10 coords_at_pos,
7 coords_at_pos,
11 graphemes::{nth_next_grapheme_boundary, nth_prev_grapheme_boundary},
8 graphemes::{nth_next_grapheme_boundary, nth_prev_grapheme_boundary},
12 line_ending::{get_line_ending, line_end_char_index},
9 line_ending::{get_line_ending, line_end_char_index},
@@ -270,20 +267,20 @@ fn reached_target(target: WordMotionTarget, peek: char, next_peek: Option<&char>
270
267
271 match target {
268 match target {
272 WordMotionTarget::NextWordStart => {
269 WordMotionTarget::NextWordStart => {
273− (is_word_boundary(peek, *next_peek)
270+ is_word_boundary(peek, *next_peek)
274− && (char_is_line_ending(*next_peek) || !next_peek.is_whitespace()))
271+ && (char_is_line_ending(*next_peek) || !next_peek.is_whitespace())
275 }
272 }
276 WordMotionTarget::NextWordEnd | WordMotionTarget::PrevWordStart => {
273 WordMotionTarget::NextWordEnd | WordMotionTarget::PrevWordStart => {
277− (is_word_boundary(peek, *next_peek)
274+ is_word_boundary(peek, *next_peek)
278− && (!peek.is_whitespace() || char_is_line_ending(*next_peek)))
275+ && (!peek.is_whitespace() || char_is_line_ending(*next_peek))
279 }
276 }
280 WordMotionTarget::NextLongWordStart => {
277 WordMotionTarget::NextLongWordStart => {
281− (is_long_word_boundary(peek, *next_peek)
278+ is_long_word_boundary(peek, *next_peek)
282− && (char_is_line_ending(*next_peek) || !next_peek.is_whitespace()))
279+ && (char_is_line_ending(*next_peek) || !next_peek.is_whitespace())
283 }
280 }
284 WordMotionTarget::NextLongWordEnd | WordMotionTarget::PrevLongWordStart => {
281 WordMotionTarget::NextLongWordEnd | WordMotionTarget::PrevLongWordStart => {
285− (is_long_word_boundary(peek, *next_peek)
282+ is_long_word_boundary(peek, *next_peek)
286− && (!peek.is_whitespace() || char_is_line_ending(*next_peek)))
283+ && (!peek.is_whitespace() || char_is_line_ending(*next_peek))
287 }
284 }
288 }
285 }
289}
286}
helix-core/src/object.rs−1
@@ -1,5 +1,4 @@
1use crate::{Range, RopeSlice, Selection, Syntax};
1use crate::{Range, RopeSlice, Selection, Syntax};
2−use smallvec::smallvec;
3
2
4// TODO: to contract_selection we'd need to store the previous ranges before expand.
3// TODO: to contract_selection we'd need to store the previous ranges before expand.
5// Maybe just contract to the first child node?
4// Maybe just contract to the first child node?
helix-core/src/position.rs+2−1
@@ -1,7 +1,7 @@
1use crate::{
1use crate::{
2 chars::char_is_line_ending,
2 chars::char_is_line_ending,
3 graphemes::{nth_next_grapheme_boundary, RopeGraphemes},
3 graphemes::{nth_next_grapheme_boundary, RopeGraphemes},
4− Rope, RopeSlice,
4+ RopeSlice,
5};
5};
6
6
7/// Represents a single point in a text buffer. Zero indexed.
7/// Represents a single point in a text buffer. Zero indexed.
@@ -70,6 +70,7 @@ pub fn pos_at_coords(text: RopeSlice, coords: Position) -> usize {
70#[cfg(test)]
70#[cfg(test)]
71mod test {
71mod test {
72 use super::*;
72 use super::*;
73+ use crate::Rope;
73
74
74 #[test]
75 #[test]
75 fn test_ordering() {
76 fn test_ordering() {
helix-core/src/selection.rs+2−1
@@ -2,7 +2,7 @@
2//! single selection range.
2//! single selection range.
3//!
3//!
4//! All positioning is done via `char` offsets into the buffer.
4//! All positioning is done via `char` offsets into the buffer.
5−use crate::{Assoc, ChangeSet, Rope, RopeSlice};
5+use crate::{Assoc, ChangeSet, RopeSlice};
6use smallvec::{smallvec, SmallVec};
6use smallvec::{smallvec, SmallVec};
7use std::borrow::Cow;
7use std::borrow::Cow;
8
8
@@ -406,6 +406,7 @@ pub fn split_on_matches(
406#[cfg(test)]
406#[cfg(test)]
407mod test {
407mod test {
408 use super::*;
408 use super::*;
409+ use crate::Rope;
409
410
410 #[test]
411 #[test]
411 #[should_panic]
412 #[should_panic]
helix-core/src/syntax.rs+140−134
@@ -1,4 +1,10 @@
1+use crate::{
1−use crate::{chars::char_is_line_ending, regex::Regex, Change, Rope, RopeSlice, Transaction};
2+ chars::char_is_line_ending,
3+ regex::Regex,
4+ transaction::{ChangeSet, Operation},
5+ Rope, RopeSlice, Tendril,
6+};
7+
2pub use helix_syntax::{get_language, get_language_name, Lang};
8pub use helix_syntax::{get_language, get_language_name, Lang};
3
9
4use arc_swap::ArcSwap;
10use arc_swap::ArcSwap;
@@ -8,7 +14,7 @@ use std::{
8 cell::RefCell,
14 cell::RefCell,
9 collections::{HashMap, HashSet},
15 collections::{HashMap, HashSet},
10 fmt,
16 fmt,
11− path::{Path, PathBuf},
17+ path::Path,
12 sync::Arc,
18 sync::Arc,
13};
19};
14
20
@@ -473,12 +479,6 @@ pub struct LanguageLayer {
473 pub(crate) tree: Option<Tree>,
479 pub(crate) tree: Option<Tree>,
474}
480}
475
481
476−use crate::{
477− coords_at_pos,
478− transaction::{ChangeSet, Operation},
479− Tendril,
480−};
481−
482impl LanguageLayer {
482impl LanguageLayer {
483 // pub fn new() -> Self {
483 // pub fn new() -> Self {
484 // Self { tree: None }
484 // Self { tree: None }
@@ -1776,135 +1776,141 @@ impl<I: Iterator<Item = HighlightEvent>> Iterator for Merge<I> {
1776 }
1776 }
1777}
1777}
1778
1778
1779−#[test]
1779+#[cfg(test)]
1780+mod test {
1781+ use super::*;
1782+ use crate::{Rope, Transaction};
1783+
1784+ #[test]
1780−fn test_parser() {
1785+ fn test_parser() {
1781− let highlight_names: Vec<String> = [
1786+ let highlight_names: Vec<String> = [
1782− "attribute",
1787+ "attribute",
1783− "constant",
1788+ "constant",
1784− "function.builtin",
1789+ "function.builtin",
1785− "function",
1790+ "function",
1786− "keyword",
1791+ "keyword",
1787− "operator",
1792+ "operator",
1788− "property",
1793+ "property",
1789− "punctuation",
1794+ "punctuation",
1790− "punctuation.bracket",
1795+ "punctuation.bracket",
1791− "punctuation.delimiter",
1796+ "punctuation.delimiter",
1792− "string",
1797+ "string",
1793− "string.special",
1798+ "string.special",
1794− "tag",
1799+ "tag",
1795− "type",
1800+ "type",
1796− "type.builtin",
1801+ "type.builtin",
1797− "variable",
1802+ "variable",
1798− "variable.builtin",
1803+ "variable.builtin",
1799− "variable.parameter",
1804+ "variable.parameter",
1800− ]
1805+ ]
1801− .iter()
1806+ .iter()
1802− .cloned()
1807+ .cloned()
1803− .map(String::from)
1808+ .map(String::from)
1804− .collect();
1809+ .collect();
1805−
1810+
1806− let language = get_language(Lang::Rust);
1811+ let language = get_language(Lang::Rust);
1807− let mut config = HighlightConfiguration::new(
1812+ let mut config = HighlightConfiguration::new(
1808− language,
1813+ language,
1809− &std::fs::read_to_string(
1814+ &std::fs::read_to_string(
1810− "../helix-syntax/languages/tree-sitter-rust/queries/highlights.scm",
1815+ "../helix-syntax/languages/tree-sitter-rust/queries/highlights.scm",
1811− )
1816+ )
1812− .unwrap(),
1817+ .unwrap(),
1813− &std::fs::read_to_string(
1818+ &std::fs::read_to_string(
1814− "../helix-syntax/languages/tree-sitter-rust/queries/injections.scm",
1819+ "../helix-syntax/languages/tree-sitter-rust/queries/injections.scm",
1815− )
1820+ )
1816− .unwrap(),
1821+ .unwrap(),
1817− "", // locals.scm
1822+ "", // 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)))"
1839 )
1823 )
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+ )
1840− );
1845+ );
1841
1846
1842− let struct_node = root.child(0).unwrap();
1847+ let struct_node = root.child(0).unwrap();
1843− assert_eq!(struct_node.kind(), "struct_item");
1848+ assert_eq!(struct_node.kind(), "struct_item");
1844−}
1849+ }
1845
1850
1846−#[test]
1851+ #[test]
1847−fn test_input_edits() {
1852+ fn test_input_edits() {
1848− use crate::State;
1853+ use crate::State;
1849− use tree_sitter::InputEdit;
1854+ use tree_sitter::InputEdit;
1850−
1855+
1851− let mut state = State::new("hello world!\ntest 123".into());
1856+ let mut state = State::new("hello world!\ntest 123".into());
1852− let transaction = Transaction::change(
1857+ let transaction = Transaction::change(
1853− &state.doc,
1858+ &state.doc,
1854− vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),
1859+ vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),
1855− );
1860+ );
1856− let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes());
1861+ let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes());
1857− // transaction.apply(&mut state);
1862+ // transaction.apply(&mut state);
1858−
1863+
1859− assert_eq!(
1864+ assert_eq!(
1860− edits,
1865+ edits,
1861− &[
1866+ &[
1862− InputEdit {
1867+ InputEdit {
1863− start_byte: 6,
1868+ start_byte: 6,
1864− old_end_byte: 11,
1869+ old_end_byte: 11,
1865− new_end_byte: 10,
1870+ new_end_byte: 10,
1866− start_position: Point { row: 0, column: 6 },
1871+ start_position: Point { row: 0, column: 6 },
1867− old_end_position: Point { row: 0, column: 11 },
1872+ old_end_position: Point { row: 0, column: 11 },
1868− new_end_position: Point { row: 0, column: 10 }
1873+ new_end_position: Point { row: 0, column: 10 }
1869− },
1874+ },
1870− InputEdit {
1875+ InputEdit {
1871− start_byte: 12,
1876+ start_byte: 12,
1872− old_end_byte: 17,
1877+ old_end_byte: 17,
1873− new_end_byte: 12,
1878+ new_end_byte: 12,
1874− start_position: Point { row: 0, column: 12 },
1879+ start_position: Point { row: 0, column: 12 },
1875− old_end_position: Point { row: 1, column: 4 },
1880+ old_end_position: Point { row: 1, column: 4 },
1876− new_end_position: Point { row: 0, column: 12 }
1881+ new_end_position: Point { row: 0, column: 12 }
1877− }
1882+ }
1878− ]
1883+ ]
1879− );
1884+ );
1880−
1885+
1881− // Testing with the official example from tree-sitter
1886+ // Testing with the official example from tree-sitter
1882− let mut state = State::new("fn test() {}".into());
1887+ let mut state = State::new("fn test() {}".into());
1883− let transaction =
1888+ let transaction =
1884− Transaction::change(&state.doc, vec![(8, 8, Some("a: u32".into()))].into_iter());
1889+ Transaction::change(&state.doc, vec![(8, 8, Some("a: u32".into()))].into_iter());
1885− let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes());
1890+ let edits = LanguageLayer::generate_edits(state.doc.slice(..), transaction.changes());
1886− transaction.apply(&mut state.doc);
1891+ transaction.apply(&mut state.doc);
1887−
1892+
1888− assert_eq!(state.doc, "fn test(a: u32) {}");
1893+ assert_eq!(state.doc, "fn test(a: u32) {}");
1889− assert_eq!(
1894+ assert_eq!(
1890− edits,
1895+ edits,
1891− &[InputEdit {
1896+ &[InputEdit {
1892− start_byte: 8,
1897+ start_byte: 8,
1893− old_end_byte: 8,
1898+ old_end_byte: 8,
1894− new_end_byte: 14,
1899+ new_end_byte: 14,
1895− start_position: Point { row: 0, column: 8 },
1900+ start_position: Point { row: 0, column: 8 },
1896− old_end_position: Point { row: 0, column: 8 },
1901+ old_end_position: Point { row: 0, column: 8 },
1897− new_end_position: Point { row: 0, column: 14 }
1902+ new_end_position: Point { row: 0, column: 14 }
1898− }]
1903+ }]
1899− );
1904+ );
1900−}
1905+ }
1901
1906
1902−#[test]
1907+ #[test]
1903−fn test_load_runtime_file() {
1908+ fn test_load_runtime_file() {
1904− // Test to make sure we can load some data from the runtime directory.
1909+ // Test to make sure we can load some data from the runtime directory.
1905− let contents = load_runtime_file("rust", "indents.toml").unwrap();
1910+ let contents = load_runtime_file("rust", "indents.toml").unwrap();
1906− assert!(!contents.is_empty());
1911+ assert!(!contents.is_empty());
1907
1912
1908− let results = load_runtime_file("rust", "does-not-exist");
1913+ let results = load_runtime_file("rust", "does-not-exist");
1909− assert!(results.is_err());
1914+ assert!(results.is_err());
1915+ }
1910}
1916}
helix-core/src/transaction.rs+3−2
@@ -1,5 +1,5 @@
1−use crate::{Range, Rope, Selection, State, Tendril};
1+use crate::{Range, Rope, Selection, Tendril};
2−use std::{borrow::Cow, convert::TryFrom};
2+use std::borrow::Cow;
3
3
4/// (from, to, replacement)
4/// (from, to, replacement)
5pub type Change = (usize, usize, Option<Tendril>);
5pub type Change = (usize, usize, Option<Tendril>);
@@ -581,6 +581,7 @@ impl<'a> Iterator for ChangeIterator<'a> {
581#[cfg(test)]
581#[cfg(test)]
582mod test {
582mod test {
583 use super::*;
583 use super::*;
584+ use crate::State;
584
585
585 #[test]
586 #[test]
586 fn composition() {
587 fn composition() {