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.
pull/400/head
Nathan Vegdahl 3 years ago
parent b571f28641
commit 220bc85821

@ -139,7 +139,7 @@ fn handle_close(doc: &Rope, selection: &Selection, _open: char, close: char) ->
} }
// handle cases where open and close is the same, or in triples ("""docstring""") // handle cases where open and close is the same, or in triples ("""docstring""")
fn handle_same(doc: &Rope, selection: &Selection, token: char) -> Option<Transaction> { fn handle_same(_doc: &Rope, _selection: &Selection, _token: char) -> Option<Transaction> {
// if not cursor but selection, wrap // if not cursor but selection, wrap
// let next = next char // let next = next char

@ -126,7 +126,6 @@ impl History {
let last_child = current_revision.last_child?; let last_child = current_revision.last_child?;
self.current = last_child.get(); self.current = last_child.get();
let last_child_revision = &self.revisions[last_child.get()];
Some(&self.revisions[last_child.get()].transaction) Some(&self.revisions[last_child.get()].transaction)
} }
@ -376,21 +375,21 @@ mod test {
if let Some(transaction) = history.undo() { if let Some(transaction) = history.undo() {
transaction.apply(&mut state.doc); transaction.apply(&mut state.doc);
} }
}; }
fn earlier(history: &mut History, state: &mut State, uk: UndoKind) { fn earlier(history: &mut History, state: &mut State, uk: UndoKind) {
let txns = history.earlier(uk); let txns = history.earlier(uk);
for txn in txns { for txn in txns {
txn.apply(&mut state.doc); txn.apply(&mut state.doc);
} }
}; }
fn later(history: &mut History, state: &mut State, uk: UndoKind) { fn later(history: &mut History, state: &mut State, uk: UndoKind) {
let txns = history.later(uk); let txns = history.later(uk);
for txn in txns { for txn in txns {
txn.apply(&mut state.doc); txn.apply(&mut state.doc);
} }
}; }
fn commit_change( fn commit_change(
history: &mut History, history: &mut History,
@ -401,7 +400,7 @@ mod test {
let txn = Transaction::change(&state.doc, vec![change.clone()].into_iter()); let txn = Transaction::change(&state.doc, vec![change.clone()].into_iter());
history.commit_revision_at_timestamp(&txn, &state, instant); history.commit_revision_at_timestamp(&txn, &state, instant);
txn.apply(&mut state.doc); txn.apply(&mut state.doc);
}; }
let t0 = Instant::now(); let t0 = Instant::now();
let t = |n| t0.checked_add(Duration::from_secs(n)).unwrap(); let t = |n| t0.checked_add(Duration::from_secs(n)).unwrap();

@ -7,7 +7,7 @@ use crate::{
/// To determine indentation of a newly inserted line, figure out the indentation at the last col /// To determine indentation of a newly inserted line, figure out the indentation at the last col
/// of the previous line. /// of the previous line.
#[allow(dead_code)]
fn indent_level_for_line(line: RopeSlice, tab_width: usize) -> usize { fn indent_level_for_line(line: RopeSlice, tab_width: usize) -> usize {
let mut len = 0; let mut len = 0;
for ch in line.chars() { for ch in line.chars() {
@ -98,12 +98,13 @@ fn calculate_indentation(query: &IndentQuery, node: Option<Node>, newline: bool)
increment as usize increment as usize
} }
#[allow(dead_code)]
fn suggested_indent_for_line( fn suggested_indent_for_line(
language_config: &LanguageConfiguration, language_config: &LanguageConfiguration,
syntax: Option<&Syntax>, syntax: Option<&Syntax>,
text: RopeSlice, text: RopeSlice,
line_num: usize, line_num: usize,
tab_width: usize, _tab_width: usize,
) -> usize { ) -> usize {
if let Some(start) = find_first_non_whitespace_char(text.line(line_num)) { if let Some(start) = find_first_non_whitespace_char(text.line(line_num)) {
return suggested_indent_for_pos( return suggested_indent_for_pos(

@ -12,7 +12,7 @@ pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
// most naive implementation: find the innermost syntax node, if we're at the edge of a node, // most naive implementation: find the innermost syntax node, if we're at the edge of a node,
// return the other edge. // return the other edge.
let mut node = match tree let node = match tree
.root_node() .root_node()
.named_descendant_for_byte_range(byte_pos, byte_pos) .named_descendant_for_byte_range(byte_pos, byte_pos)
{ {

@ -113,7 +113,7 @@ pub fn move_prev_long_word_start(slice: RopeSlice, range: Range, count: usize) -
word_move(slice, range, count, WordMotionTarget::PrevLongWordStart) word_move(slice, range, count, WordMotionTarget::PrevLongWordStart)
} }
fn word_move(slice: RopeSlice, mut range: Range, count: usize, target: WordMotionTarget) -> Range { fn word_move(slice: RopeSlice, range: Range, count: usize, target: WordMotionTarget) -> Range {
(0..count).fold(range, |range, _| { (0..count).fold(range, |range, _| {
slice.chars_at(range.head).range_to_target(target, range) slice.chars_at(range.head).range_to_target(target, range)
}) })
@ -179,7 +179,6 @@ enum WordMotionPhase {
impl CharHelpers for Chars<'_> { impl CharHelpers for Chars<'_> {
fn range_to_target(&mut self, target: WordMotionTarget, origin: Range) -> Range { fn range_to_target(&mut self, target: WordMotionTarget, origin: Range) -> Range {
let range = origin;
// Characters are iterated forward or backwards depending on the motion direction. // Characters are iterated forward or backwards depending on the motion direction.
let characters: Box<dyn Iterator<Item = char>> = match target { let characters: Box<dyn Iterator<Item = char>> = match target {
WordMotionTarget::PrevWordStart | WordMotionTarget::PrevLongWordStart => { WordMotionTarget::PrevWordStart | WordMotionTarget::PrevLongWordStart => {

@ -80,8 +80,8 @@ mod test {
#[test] #[test]
fn test_coords_at_pos() { fn test_coords_at_pos() {
let text = Rope::from("ḧëḷḷö\nẅöṛḷḋ"); // let text = Rope::from("ḧëḷḷö\nẅöṛḷḋ");
let slice = text.slice(..); // let slice = text.slice(..);
// assert_eq!(coords_at_pos(slice, 0), (0, 0).into()); // assert_eq!(coords_at_pos(slice, 0), (0, 0).into());
// assert_eq!(coords_at_pos(slice, 5), (0, 5).into()); // position on \n // assert_eq!(coords_at_pos(slice, 5), (0, 5).into()); // position on \n
// assert_eq!(coords_at_pos(slice, 6), (1, 0).into()); // position on w // assert_eq!(coords_at_pos(slice, 6), (1, 0).into()); // position on w

@ -345,10 +345,8 @@ pub fn select_on_matches(
// TODO: can't avoid occasional allocations since Regex can't operate on chunks yet // TODO: can't avoid occasional allocations since Regex can't operate on chunks yet
let fragment = sel.fragment(text); let fragment = sel.fragment(text);
let mut sel_start = sel.from(); let sel_start = sel.from();
let sel_end = sel.to(); let start_byte = text.char_to_byte(sel_start);
let mut start_byte = text.char_to_byte(sel_start);
for mat in regex.find_iter(&fragment) { for mat in regex.find_iter(&fragment) {
// TODO: retain range direction // TODO: retain range direction
@ -379,10 +377,10 @@ pub fn split_on_matches(
// TODO: can't avoid occasional allocations since Regex can't operate on chunks yet // TODO: can't avoid occasional allocations since Regex can't operate on chunks yet
let fragment = sel.fragment(text); let fragment = sel.fragment(text);
let mut sel_start = sel.from(); let sel_start = sel.from();
let sel_end = sel.to(); let sel_end = sel.to();
let mut start_byte = text.char_to_byte(sel_start); let start_byte = text.char_to_byte(sel_start);
let mut start = sel_start; let mut start = sel_start;
@ -411,7 +409,7 @@ mod test {
#[test] #[test]
#[should_panic] #[should_panic]
fn test_new_empty() { fn test_new_empty() {
let sel = Selection::new(smallvec![], 0); let _ = Selection::new(smallvec![], 0);
} }
#[test] #[test]

@ -166,7 +166,7 @@ impl LanguageConfiguration {
None None
} else { } else {
let language = get_language(self.language_id); let language = get_language(self.language_id);
let mut config = HighlightConfiguration::new( let config = HighlightConfiguration::new(
language, language,
&highlights_query, &highlights_query,
&injections_query, &injections_query,
@ -332,7 +332,8 @@ impl Syntax {
// update root layer // update root layer
PARSER.with(|ts_parser| { PARSER.with(|ts_parser| {
syntax.root_layer.parse( // TODO: handle the returned `Result` properly.
let _ = syntax.root_layer.parse(
&mut ts_parser.borrow_mut(), &mut ts_parser.borrow_mut(),
&syntax.config, &syntax.config,
source, source,
@ -387,7 +388,7 @@ impl Syntax {
source: RopeSlice<'a>, source: RopeSlice<'a>,
range: Option<std::ops::Range<usize>>, range: Option<std::ops::Range<usize>>,
cancellation_flag: Option<&'a AtomicUsize>, cancellation_flag: Option<&'a AtomicUsize>,
mut injection_callback: impl FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a, injection_callback: impl FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a,
) -> impl Iterator<Item = Result<HighlightEvent, Error>> + 'a { ) -> impl Iterator<Item = Result<HighlightEvent, Error>> + 'a {
// The `captures` iterator borrows the `Tree` and the `QueryCursor`, which // The `captures` iterator borrows the `Tree` and the `QueryCursor`, which
// prevents them from being moved. But both of these values are really just // prevents them from being moved. But both of these values are really just
@ -494,8 +495,8 @@ impl LanguageLayer {
ts_parser: &mut TsParser, ts_parser: &mut TsParser,
config: &HighlightConfiguration, config: &HighlightConfiguration,
source: &Rope, source: &Rope,
mut depth: usize, _depth: usize,
mut ranges: Vec<Range>, ranges: Vec<Range>,
) -> Result<(), Error> { ) -> Result<(), Error> {
if ts_parser.parser.set_included_ranges(&ranges).is_ok() { if ts_parser.parser.set_included_ranges(&ranges).is_ok() {
ts_parser ts_parser
@ -1644,13 +1645,13 @@ fn injection_for_match<'a>(
(language_name, content_node, include_children) (language_name, content_node, include_children)
} }
fn shrink_and_clear<T>(vec: &mut Vec<T>, capacity: usize) { // fn shrink_and_clear<T>(vec: &mut Vec<T>, capacity: usize) {
if vec.len() > capacity { // if vec.len() > capacity {
vec.truncate(capacity); // vec.truncate(capacity);
vec.shrink_to_fit(); // vec.shrink_to_fit();
} // }
vec.clear(); // vec.clear();
} // }
pub struct Merge<I> { pub struct Merge<I> {
iter: I, iter: I,
@ -1691,7 +1692,7 @@ impl<I: Iterator<Item = HighlightEvent>> Iterator for Merge<I> {
loop { loop {
match (self.next_event, &self.next_span) { match (self.next_event, &self.next_span) {
// this happens when range is partially or fully offscreen // this happens when range is partially or fully offscreen
(Some(Source { start, end }), Some((span, range))) if start > range.start => { (Some(Source { start, .. }), Some((span, range))) if start > range.start => {
if start > range.end { if start > range.end {
self.next_span = self.spans.next(); self.next_span = self.spans.next();
} else { } else {
@ -1711,7 +1712,7 @@ impl<I: Iterator<Item = HighlightEvent>> Iterator for Merge<I> {
self.next_event = self.iter.next(); self.next_event = self.iter.next();
Some(HighlightEnd) Some(HighlightEnd)
} }
(Some(Source { start, end }), Some((span, range))) if start < range.start => { (Some(Source { start, end }), Some((_, range))) if start < range.start => {
let intersect = range.start.min(end); let intersect = range.start.min(end);
let event = Source { let event = Source {
start, start,
@ -1766,7 +1767,7 @@ impl<I: Iterator<Item = HighlightEvent>> Iterator for Merge<I> {
Some(event) Some(event)
} }
// can happen if deleting and cursor at EOF, and diagnostic reaches past the end // can happen if deleting and cursor at EOF, and diagnostic reaches past the end
(None, Some((span, range))) => { (None, Some((_, _))) => {
self.next_span = None; self.next_span = None;
None None
} }
@ -1809,7 +1810,7 @@ mod test {
.collect(); .collect();
let language = get_language(Lang::Rust); let language = get_language(Lang::Rust);
let mut config = HighlightConfiguration::new( let config = HighlightConfiguration::new(
language, language,
&std::fs::read_to_string( &std::fs::read_to_string(
"../helix-syntax/languages/tree-sitter-rust/queries/highlights.scm", "../helix-syntax/languages/tree-sitter-rust/queries/highlights.scm",
@ -1853,7 +1854,7 @@ mod test {
use crate::State; use crate::State;
use tree_sitter::InputEdit; use tree_sitter::InputEdit;
let mut state = State::new("hello world!\ntest 123".into()); let state = State::new("hello world!\ntest 123".into());
let transaction = Transaction::change( let transaction = Transaction::change(
&state.doc, &state.doc,
vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(), vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),

@ -163,7 +163,7 @@ impl ChangeSet {
head_a = a; head_a = a;
head_b = changes_b.next(); head_b = changes_b.next();
} }
(None, val) | (val, None) => return unreachable!("({:?})", val), (None, val) | (val, None) => unreachable!("({:?})", val),
(Some(Retain(i)), Some(Retain(j))) => match i.cmp(&j) { (Some(Retain(i)), Some(Retain(j))) => match i.cmp(&j) {
Ordering::Less => { Ordering::Less => {
changes.retain(i); changes.retain(i);
@ -202,7 +202,7 @@ impl ChangeSet {
} }
} }
} }
(Some(Insert(mut s)), Some(Retain(j))) => { (Some(Insert(s)), Some(Retain(j))) => {
let len = s.chars().count(); let len = s.chars().count();
match len.cmp(&j) { match len.cmp(&j) {
Ordering::Less => { Ordering::Less => {
@ -274,7 +274,6 @@ impl ChangeSet {
let mut changes = Self::with_capacity(self.changes.len()); let mut changes = Self::with_capacity(self.changes.len());
let mut pos = 0; let mut pos = 0;
let mut len = 0;
for change in &self.changes { for change in &self.changes {
use Operation::*; use Operation::*;
@ -700,7 +699,7 @@ mod test {
#[test] #[test]
fn changes_iter() { fn changes_iter() {
let mut state = State::new("hello world!\ntest 123".into()); let state = State::new("hello world!\ntest 123".into());
let changes = vec![(6, 11, Some("void".into())), (12, 17, None)]; let changes = vec![(6, 11, Some("void".into())), (12, 17, None)];
let transaction = Transaction::change(&state.doc, changes.clone().into_iter()); let transaction = Transaction::change(&state.doc, changes.clone().into_iter());
assert_eq!(transaction.changes_iter().collect::<Vec<_>>(), changes); assert_eq!(transaction.changes_iter().collect::<Vec<_>>(), changes);
@ -732,7 +731,7 @@ mod test {
// retain 1, e // retain 1, e
// retain 2, l // retain 2, l
let mut changes = t1 let changes = t1
.changes .changes
.compose(t2.changes) .compose(t2.changes)
.compose(t3.changes) .compose(t3.changes)
@ -747,7 +746,7 @@ mod test {
#[test] #[test]
fn combine_with_empty() { fn combine_with_empty() {
let empty = Rope::from(""); let empty = Rope::from("");
let mut a = ChangeSet::new(&empty); let a = ChangeSet::new(&empty);
let mut b = ChangeSet::new(&empty); let mut b = ChangeSet::new(&empty);
b.insert("a".into()); b.insert("a".into());
@ -763,7 +762,7 @@ mod test {
const TEST_CASE: &'static str = "Hello, これはヘリックスエディターです!"; const TEST_CASE: &'static str = "Hello, これはヘリックスエディターです!";
let empty = Rope::from(""); let empty = Rope::from("");
let mut a = ChangeSet::new(&empty); let a = ChangeSet::new(&empty);
let mut b = ChangeSet::new(&empty); let mut b = ChangeSet::new(&empty);
b.insert(TEST_CASE.into()); b.insert(TEST_CASE.into());

Loading…
Cancel
Save