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""")
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
// let next = next char

@ -126,7 +126,6 @@ impl History {
let last_child = current_revision.last_child?;
self.current = last_child.get();
let last_child_revision = &self.revisions[last_child.get()];
Some(&self.revisions[last_child.get()].transaction)
}
@ -376,21 +375,21 @@ mod test {
if let Some(transaction) = history.undo() {
transaction.apply(&mut state.doc);
}
};
}
fn earlier(history: &mut History, state: &mut State, uk: UndoKind) {
let txns = history.earlier(uk);
for txn in txns {
txn.apply(&mut state.doc);
}
};
}
fn later(history: &mut History, state: &mut State, uk: UndoKind) {
let txns = history.later(uk);
for txn in txns {
txn.apply(&mut state.doc);
}
};
}
fn commit_change(
history: &mut History,
@ -401,7 +400,7 @@ mod test {
let txn = Transaction::change(&state.doc, vec![change.clone()].into_iter());
history.commit_revision_at_timestamp(&txn, &state, instant);
txn.apply(&mut state.doc);
};
}
let t0 = Instant::now();
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
/// of the previous line.
#[allow(dead_code)]
fn indent_level_for_line(line: RopeSlice, tab_width: usize) -> usize {
let mut len = 0;
for ch in line.chars() {
@ -98,12 +98,13 @@ fn calculate_indentation(query: &IndentQuery, node: Option<Node>, newline: bool)
increment as usize
}
#[allow(dead_code)]
fn suggested_indent_for_line(
language_config: &LanguageConfiguration,
syntax: Option<&Syntax>,
text: RopeSlice,
line_num: usize,
tab_width: usize,
_tab_width: usize,
) -> usize {
if let Some(start) = find_first_non_whitespace_char(text.line(line_num)) {
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,
// return the other edge.
let mut node = match tree
let node = match tree
.root_node()
.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)
}
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, _| {
slice.chars_at(range.head).range_to_target(target, range)
})
@ -179,7 +179,6 @@ enum WordMotionPhase {
impl CharHelpers for Chars<'_> {
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.
let characters: Box<dyn Iterator<Item = char>> = match target {
WordMotionTarget::PrevWordStart | WordMotionTarget::PrevLongWordStart => {

@ -80,8 +80,8 @@ mod test {
#[test]
fn test_coords_at_pos() {
let text = Rope::from("ḧëḷḷö\nẅöṛḷḋ");
let slice = text.slice(..);
// let text = Rope::from("ḧëḷḷö\nẅöṛḷḋ");
// let slice = text.slice(..);
// 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, 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
let fragment = sel.fragment(text);
let mut sel_start = sel.from();
let sel_end = sel.to();
let mut start_byte = text.char_to_byte(sel_start);
let sel_start = sel.from();
let start_byte = text.char_to_byte(sel_start);
for mat in regex.find_iter(&fragment) {
// 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
let fragment = sel.fragment(text);
let mut sel_start = sel.from();
let sel_start = sel.from();
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;
@ -411,7 +409,7 @@ mod test {
#[test]
#[should_panic]
fn test_new_empty() {
let sel = Selection::new(smallvec![], 0);
let _ = Selection::new(smallvec![], 0);
}
#[test]

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

@ -163,7 +163,7 @@ impl ChangeSet {
head_a = a;
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) {
Ordering::Less => {
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();
match len.cmp(&j) {
Ordering::Less => {
@ -274,7 +274,6 @@ impl ChangeSet {
let mut changes = Self::with_capacity(self.changes.len());
let mut pos = 0;
let mut len = 0;
for change in &self.changes {
use Operation::*;
@ -700,7 +699,7 @@ mod test {
#[test]
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 transaction = Transaction::change(&state.doc, changes.clone().into_iter());
assert_eq!(transaction.changes_iter().collect::<Vec<_>>(), changes);
@ -732,7 +731,7 @@ mod test {
// retain 1, e
// retain 2, l
let mut changes = t1
let changes = t1
.changes
.compose(t2.changes)
.compose(t3.changes)
@ -747,7 +746,7 @@ mod test {
#[test]
fn combine_with_empty() {
let empty = Rope::from("");
let mut a = ChangeSet::new(&empty);
let a = ChangeSet::new(&empty);
let mut b = ChangeSet::new(&empty);
b.insert("a".into());
@ -763,7 +762,7 @@ mod test {
const TEST_CASE: &'static str = "Hello, これはヘリックスエディターです!";
let empty = Rope::from("");
let mut a = ChangeSet::new(&empty);
let a = ChangeSet::new(&empty);
let mut b = ChangeSet::new(&empty);
b.insert(TEST_CASE.into());

Loading…
Cancel
Save