on master help sign in
Fix all remaining warnings in helix-core except for two.

I'm not sure how to address them, because they look like they might be bugs, and code is involved. Will poke the relevant people.

commit220bc85821d87f65630601dedd219fd2fa41c0ea authorNathan Vegdahl <cessen@cessen.com> dateThu 1 Jul 2021, 12:55 (5 years ago) parentb571f28
9 files changed+41−44
helix-core/src/auto_pairs.rs+1−1 helix-core/src/history.rs+4−5 helix-core/src/indent.rs+3−2 helix-core/src/match_brackets.rs+1−1 helix-core/src/movement.rs+1−2 helix-core/src/position.rs+2−2 helix-core/src/selection.rs+5−7 helix-core/src/syntax.rs+18−17 helix-core/src/transaction.rs+6−7
helix-core/src/auto_pairs.rs+1−1
@@ -139,7 +139,7 @@ fn handle_close(doc: &Rope, selection: &Selection, _open: char, close: char) ->
139139}
140140
141141// handle cases where open and close is the same, or in triples ("""docstring""")
142−fn handle_same(doc: &Rope, selection: &Selection, token: char) -> Option<Transaction> {
142+fn handle_same(_doc: &Rope, _selection: &Selection, _token: char) -> Option<Transaction> {
143143 // if not cursor but selection, wrap
144144 // let next = next char
145145
helix-core/src/history.rs+4−5
@@ -126,7 +126,6 @@ impl History {
126126 let last_child = current_revision.last_child?;
127127 self.current = last_child.get();
128128
129− let last_child_revision = &self.revisions[last_child.get()];
130129 Some(&self.revisions[last_child.get()].transaction)
131130 }
132131
@@ -376,21 +375,21 @@ mod test {
376375 if let Some(transaction) = history.undo() {
377376 transaction.apply(&mut state.doc);
378377 }
379− };
378+ }
380379
381380 fn earlier(history: &mut History, state: &mut State, uk: UndoKind) {
382381 let txns = history.earlier(uk);
383382 for txn in txns {
384383 txn.apply(&mut state.doc);
385384 }
386− };
385+ }
387386
388387 fn later(history: &mut History, state: &mut State, uk: UndoKind) {
389388 let txns = history.later(uk);
390389 for txn in txns {
391390 txn.apply(&mut state.doc);
392391 }
393− };
392+ }
394393
395394 fn commit_change(
396395 history: &mut History,
@@ -401,7 +400,7 @@ mod test {
401400 let txn = Transaction::change(&state.doc, vec![change.clone()].into_iter());
402401 history.commit_revision_at_timestamp(&txn, &state, instant);
403402 txn.apply(&mut state.doc);
404− };
403+ }
405404
406405 let t0 = Instant::now();
407406 let t = |n| t0.checked_add(Duration::from_secs(n)).unwrap();
helix-core/src/indent.rs+3−2
@@ -7,7 +7,7 @@ use crate::{
77
88/// To determine indentation of a newly inserted line, figure out the indentation at the last col
99/// of the previous line.
10−
10+#[allow(dead_code)]
1111fn indent_level_for_line(line: RopeSlice, tab_width: usize) -> usize {
1212 let mut len = 0;
1313 for ch in line.chars() {
@@ -98,12 +98,13 @@ fn calculate_indentation(query: &IndentQuery, node: Option<Node>, newline: bool)
9898 increment as usize
9999}
100100
101+#[allow(dead_code)]
101102fn suggested_indent_for_line(
102103 language_config: &LanguageConfiguration,
103104 syntax: Option<&Syntax>,
104105 text: RopeSlice,
105106 line_num: usize,
106− tab_width: usize,
107+ _tab_width: usize,
107108) -> usize {
108109 if let Some(start) = find_first_non_whitespace_char(text.line(line_num)) {
109110 return suggested_indent_for_pos(
helix-core/src/match_brackets.rs+1−1
@@ -12,7 +12,7 @@ pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
1212 // most naive implementation: find the innermost syntax node, if we're at the edge of a node,
1313 // return the other edge.
1414
15− let mut node = match tree
15+ let node = match tree
1616 .root_node()
1717 .named_descendant_for_byte_range(byte_pos, byte_pos)
1818 {
helix-core/src/movement.rs+1−2
@@ -113,7 +113,7 @@ pub fn move_prev_long_word_start(slice: RopeSlice, range: Range, count: usize) -
113113 word_move(slice, range, count, WordMotionTarget::PrevLongWordStart)
114114}
115115
116−fn word_move(slice: RopeSlice, mut range: Range, count: usize, target: WordMotionTarget) -> Range {
116+fn word_move(slice: RopeSlice, range: Range, count: usize, target: WordMotionTarget) -> Range {
117117 (0..count).fold(range, |range, _| {
118118 slice.chars_at(range.head).range_to_target(target, range)
119119 })
@@ -179,7 +179,6 @@ enum WordMotionPhase {
179179
180180impl CharHelpers for Chars<'_> {
181181 fn range_to_target(&mut self, target: WordMotionTarget, origin: Range) -> Range {
182− let range = origin;
183182 // Characters are iterated forward or backwards depending on the motion direction.
184183 let characters: Box<dyn Iterator<Item = char>> = match target {
185184 WordMotionTarget::PrevWordStart | WordMotionTarget::PrevLongWordStart => {
helix-core/src/position.rs+2−2
@@ -80,8 +80,8 @@ mod test {
8080
8181 #[test]
8282 fn test_coords_at_pos() {
83− let text = Rope::from("ḧëḷḷö\nẅöṛḷḋ");
84− let slice = text.slice(..);
83+ // let text = Rope::from("ḧëḷḷö\nẅöṛḷḋ");
84+ // let slice = text.slice(..);
8585 // assert_eq!(coords_at_pos(slice, 0), (0, 0).into());
8686 // assert_eq!(coords_at_pos(slice, 5), (0, 5).into()); // position on \n
8787 // assert_eq!(coords_at_pos(slice, 6), (1, 0).into()); // position on w
helix-core/src/selection.rs+5−7
@@ -345,10 +345,8 @@ pub fn select_on_matches(
345345 // TODO: can't avoid occasional allocations since Regex can't operate on chunks yet
346346 let fragment = sel.fragment(text);
347347
348− let mut sel_start = sel.from();
349− let sel_end = sel.to();
350−
351− let mut start_byte = text.char_to_byte(sel_start);
348+ let sel_start = sel.from();
349+ let start_byte = text.char_to_byte(sel_start);
352350
353351 for mat in regex.find_iter(&fragment) {
354352 // TODO: retain range direction
@@ -379,10 +377,10 @@ pub fn split_on_matches(
379377 // TODO: can't avoid occasional allocations since Regex can't operate on chunks yet
380378 let fragment = sel.fragment(text);
381379
382− let mut sel_start = sel.from();
380+ let sel_start = sel.from();
383381 let sel_end = sel.to();
384382
385− let mut start_byte = text.char_to_byte(sel_start);
383+ let start_byte = text.char_to_byte(sel_start);
386384
387385 let mut start = sel_start;
388386
@@ -411,7 +409,7 @@ mod test {
411409 #[test]
412410 #[should_panic]
413411 fn test_new_empty() {
414− let sel = Selection::new(smallvec![], 0);
412+ let _ = Selection::new(smallvec![], 0);
415413 }
416414
417415 #[test]
helix-core/src/syntax.rs+18−17
@@ -166,7 +166,7 @@ impl LanguageConfiguration {
166166 None
167167 } else {
168168 let language = get_language(self.language_id);
169− let mut config = HighlightConfiguration::new(
169+ let config = HighlightConfiguration::new(
170170 language,
171171 &highlights_query,
172172 &injections_query,
@@ -332,7 +332,8 @@ impl Syntax {
332332
333333 // update root layer
334334 PARSER.with(|ts_parser| {
335− syntax.root_layer.parse(
335+ // TODO: handle the returned `Result` properly.
336+ let _ = syntax.root_layer.parse(
336337 &mut ts_parser.borrow_mut(),
337338 &syntax.config,
338339 source,
@@ -387,7 +388,7 @@ impl Syntax {
387388 source: RopeSlice<'a>,
388389 range: Option<std::ops::Range<usize>>,
389390 cancellation_flag: Option<&'a AtomicUsize>,
390− mut injection_callback: impl FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a,
391+ injection_callback: impl FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a,
391392 ) -> impl Iterator<Item = Result<HighlightEvent, Error>> + 'a {
392393 // The `captures` iterator borrows the `Tree` and the `QueryCursor`, which
393394 // prevents them from being moved. But both of these values are really just
@@ -494,8 +495,8 @@ impl LanguageLayer {
494495 ts_parser: &mut TsParser,
495496 config: &HighlightConfiguration,
496497 source: &Rope,
497− mut depth: usize,
498− mut ranges: Vec<Range>,
498+ _depth: usize,
499+ ranges: Vec<Range>,
499500 ) -> Result<(), Error> {
500501 if ts_parser.parser.set_included_ranges(&ranges).is_ok() {
501502 ts_parser
@@ -1644,13 +1645,13 @@ fn injection_for_match<'a>(
16441645 (language_name, content_node, include_children)
16451646}
16461647
1647−fn shrink_and_clear<T>(vec: &mut Vec<T>, capacity: usize) {
1648− if vec.len() > capacity {
1649− vec.truncate(capacity);
1650− vec.shrink_to_fit();
1651− }
1652− vec.clear();
1653−}
1648+// fn shrink_and_clear<T>(vec: &mut Vec<T>, capacity: usize) {
1649+// if vec.len() > capacity {
1650+// vec.truncate(capacity);
1651+// vec.shrink_to_fit();
1652+// }
1653+// vec.clear();
1654+// }
16541655
16551656pub struct Merge<I> {
16561657 iter: I,
@@ -1691,7 +1692,7 @@ impl<I: Iterator<Item = HighlightEvent>> Iterator for Merge<I> {
16911692 loop {
16921693 match (self.next_event, &self.next_span) {
16931694 // this happens when range is partially or fully offscreen
1694− (Some(Source { start, end }), Some((span, range))) if start > range.start => {
1695+ (Some(Source { start, .. }), Some((span, range))) if start > range.start => {
16951696 if start > range.end {
16961697 self.next_span = self.spans.next();
16971698 } else {
@@ -1711,7 +1712,7 @@ impl<I: Iterator<Item = HighlightEvent>> Iterator for Merge<I> {
17111712 self.next_event = self.iter.next();
17121713 Some(HighlightEnd)
17131714 }
1714− (Some(Source { start, end }), Some((span, range))) if start < range.start => {
1715+ (Some(Source { start, end }), Some((_, range))) if start < range.start => {
17151716 let intersect = range.start.min(end);
17161717 let event = Source {
17171718 start,
@@ -1766,7 +1767,7 @@ impl<I: Iterator<Item = HighlightEvent>> Iterator for Merge<I> {
17661767 Some(event)
17671768 }
17681769 // can happen if deleting and cursor at EOF, and diagnostic reaches past the end
1769− (None, Some((span, range))) => {
1770+ (None, Some((_, _))) => {
17701771 self.next_span = None;
17711772 None
17721773 }
@@ -1809,7 +1810,7 @@ mod test {
18091810 .collect();
18101811
18111812 let language = get_language(Lang::Rust);
1812− let mut config = HighlightConfiguration::new(
1813+ let config = HighlightConfiguration::new(
18131814 language,
18141815 &std::fs::read_to_string(
18151816 "../helix-syntax/languages/tree-sitter-rust/queries/highlights.scm",
@@ -1853,7 +1854,7 @@ mod test {
18531854 use crate::State;
18541855 use tree_sitter::InputEdit;
18551856
1856− let mut state = State::new("hello world!\ntest 123".into());
1857+ let state = State::new("hello world!\ntest 123".into());
18571858 let transaction = Transaction::change(
18581859 &state.doc,
18591860 vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),
helix-core/src/transaction.rs+6−7
@@ -163,7 +163,7 @@ impl ChangeSet {
163163 head_a = a;
164164 head_b = changes_b.next();
165165 }
166− (None, val) | (val, None) => return unreachable!("({:?})", val),
166+ (None, val) | (val, None) => unreachable!("({:?})", val),
167167 (Some(Retain(i)), Some(Retain(j))) => match i.cmp(&j) {
168168 Ordering::Less => {
169169 changes.retain(i);
@@ -202,7 +202,7 @@ impl ChangeSet {
202202 }
203203 }
204204 }
205− (Some(Insert(mut s)), Some(Retain(j))) => {
205+ (Some(Insert(s)), Some(Retain(j))) => {
206206 let len = s.chars().count();
207207 match len.cmp(&j) {
208208 Ordering::Less => {
@@ -274,7 +274,6 @@ impl ChangeSet {
274274 let mut changes = Self::with_capacity(self.changes.len());
275275
276276 let mut pos = 0;
277− let mut len = 0;
278277
279278 for change in &self.changes {
280279 use Operation::*;
@@ -700,7 +699,7 @@ mod test {
700699
701700 #[test]
702701 fn changes_iter() {
703− let mut state = State::new("hello world!\ntest 123".into());
702+ let state = State::new("hello world!\ntest 123".into());
704703 let changes = vec![(6, 11, Some("void".into())), (12, 17, None)];
705704 let transaction = Transaction::change(&state.doc, changes.clone().into_iter());
706705 assert_eq!(transaction.changes_iter().collect::<Vec<_>>(), changes);
@@ -732,7 +731,7 @@ mod test {
732731 // retain 1, e
733732 // retain 2, l
734733
735− let mut changes = t1
734+ let changes = t1
736735 .changes
737736 .compose(t2.changes)
738737 .compose(t3.changes)
@@ -747,7 +746,7 @@ mod test {
747746 #[test]
748747 fn combine_with_empty() {
749748 let empty = Rope::from("");
750− let mut a = ChangeSet::new(&empty);
749+ let a = ChangeSet::new(&empty);
751750
752751 let mut b = ChangeSet::new(&empty);
753752 b.insert("a".into());
@@ -763,7 +762,7 @@ mod test {
763762 const TEST_CASE: &'static str = "Hello, これはヘリックスエディターです!";
764763
765764 let empty = Rope::from("");
766− let mut a = ChangeSet::new(&empty);
765+ let a = ChangeSet::new(&empty);
767766
768767 let mut b = ChangeSet::new(&empty);
769768 b.insert(TEST_CASE.into());