clippy lint

pull/11/head
Blaž Hrastnik 3 years ago
parent 8a0ab447ec
commit 06aca7691c

@ -24,6 +24,7 @@ const CLOSE_BEFORE: &str = ")]}'\":;> \n"; // includes space and newline
// TODO: delete implementation where it erases the whole bracket (|) -> | // TODO: delete implementation where it erases the whole bracket (|) -> |
#[must_use]
pub fn hook(doc: &Rope, selection: &Selection, ch: char) -> Option<Transaction> { pub fn hook(doc: &Rope, selection: &Selection, ch: char) -> Option<Transaction> {
for &(open, close) in PAIRS { for &(open, close) in PAIRS {
if open == ch { if open == ch {

@ -37,6 +37,7 @@ fn find_line_comment(
(commented, skipped, min) (commented, skipped, min)
} }
#[must_use]
pub fn toggle_line_comments(doc: &Rope, selection: &Selection) -> Transaction { pub fn toggle_line_comments(doc: &Rope, selection: &Selection) -> Transaction {
let text = doc.slice(..); let text = doc.slice(..);
let mut changes: Vec<Change> = Vec::new(); let mut changes: Vec<Change> = Vec::new();

@ -3,6 +3,7 @@ use ropey::{iter::Chunks, str_utils::byte_to_char_idx, RopeSlice};
use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete}; use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete};
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
#[must_use]
pub fn grapheme_width(g: &str) -> usize { pub fn grapheme_width(g: &str) -> usize {
if g.as_bytes()[0] <= 127 { if g.as_bytes()[0] <= 127 {
// Fast-path ascii. // Fast-path ascii.
@ -26,6 +27,7 @@ pub fn grapheme_width(g: &str) -> usize {
} }
} }
#[must_use]
pub fn nth_prev_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) -> usize { pub fn nth_prev_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) -> usize {
// Bounds check // Bounds check
debug_assert!(char_idx <= slice.len_chars()); debug_assert!(char_idx <= slice.len_chars());
@ -71,6 +73,7 @@ pub fn prev_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> usize {
nth_prev_grapheme_boundary(slice, char_idx, 1) nth_prev_grapheme_boundary(slice, char_idx, 1)
} }
#[must_use]
pub fn nth_next_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) -> usize { pub fn nth_next_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) -> usize {
// Bounds check // Bounds check
debug_assert!(char_idx <= slice.len_chars()); debug_assert!(char_idx <= slice.len_chars());
@ -138,12 +141,12 @@ pub fn is_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> bool {
let (ctx_chunk, ctx_byte_start, _, _) = slice.chunk_at_byte(n - 1); let (ctx_chunk, ctx_byte_start, _, _) = slice.chunk_at_byte(n - 1);
gc.provide_context(ctx_chunk, ctx_byte_start); gc.provide_context(ctx_chunk, ctx_byte_start);
} }
_ => unreachable!(), Err(_) => unreachable!(),
} }
} }
} }
/// An iterator over the graphemes of a RopeSlice. /// An iterator over the graphemes of a `RopeSlice`.
#[derive(Clone)] #[derive(Clone)]
pub struct RopeGraphemes<'a> { pub struct RopeGraphemes<'a> {
text: RopeSlice<'a>, text: RopeSlice<'a>,
@ -154,6 +157,7 @@ pub struct RopeGraphemes<'a> {
} }
impl<'a> RopeGraphemes<'a> { impl<'a> RopeGraphemes<'a> {
#[must_use]
pub fn new(slice: RopeSlice) -> RopeGraphemes { pub fn new(slice: RopeSlice) -> RopeGraphemes {
let mut chunks = slice.chunks(); let mut chunks = slice.chunks();
let first_chunk = chunks.next().unwrap_or(""); let first_chunk = chunks.next().unwrap_or("");

@ -53,7 +53,7 @@ impl History {
} }
#[inline] #[inline]
pub fn at_root(&self) -> bool { pub const fn at_root(&self) -> bool {
self.cursor == 0 self.cursor == 0
} }

@ -3,6 +3,7 @@ use crate::{Range, Rope, Selection, Syntax};
// const PAIRS: &[(char, char)] = &[('(', ')'), ('{', '}'), ('[', ']')]; // const PAIRS: &[(char, char)] = &[('(', ')'), ('{', '}'), ('[', ']')];
// limit matching pairs to only ( ) { } [ ] < > // limit matching pairs to only ( ) { } [ ] < >
#[must_use]
pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> { pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
let tree = syntax.root_layer.tree.as_ref().unwrap(); let tree = syntax.root_layer.tree.as_ref().unwrap();

@ -37,7 +37,7 @@ impl Position {
impl From<(usize, usize)> for Position { impl From<(usize, usize)> for Position {
fn from(tuple: (usize, usize)) -> Self { fn from(tuple: (usize, usize)) -> Self {
Position { Self {
row: tuple.0, row: tuple.0,
col: tuple.1, col: tuple.1,
} }

@ -99,14 +99,14 @@ impl Range {
#[must_use] #[must_use]
pub fn extend(&self, from: usize, to: usize) -> Self { pub fn extend(&self, from: usize, to: usize) -> Self {
if from <= self.anchor && to >= self.anchor { if from <= self.anchor && to >= self.anchor {
return Range { return Self {
anchor: from, anchor: from,
head: to, head: to,
horiz: None, horiz: None,
}; };
} }
Range { Self {
anchor: self.anchor, anchor: self.anchor,
head: if abs_difference(from, self.anchor) > abs_difference(to, self.anchor) { head: if abs_difference(from, self.anchor) > abs_difference(to, self.anchor) {
from from
@ -253,7 +253,7 @@ impl Selection {
// fast path for a single selection (cursor) // fast path for a single selection (cursor)
if ranges.len() == 1 { if ranges.len() == 1 {
return Selection { return Self {
ranges, ranges,
primary_index: 0, primary_index: 0,
}; };

@ -66,10 +66,10 @@ impl LanguageConfiguration {
language, language,
&highlights_query, &highlights_query,
&injections_query, &injections_query,
&locals_query, locals_query,
) )
.unwrap(); // TODO: no unwrap .unwrap(); // TODO: no unwrap
config.configure(&scopes); config.configure(scopes);
Some(Arc::new(config)) Some(Arc::new(config))
} }
}) })
@ -90,8 +90,8 @@ pub struct Loader {
} }
impl Loader { impl Loader {
fn init() -> Loader { fn init() -> Self {
let mut loader = Loader { let mut loader = Self {
language_configs: Vec::new(), language_configs: Vec::new(),
language_config_ids_by_file_type: HashMap::new(), language_config_ids_by_file_type: HashMap::new(),
}; };
@ -331,7 +331,7 @@ impl Syntax {
let mut result = HighlightIter { let mut result = HighlightIter {
source, source,
byte_offset: range.map(|r| r.start).unwrap_or(0), // TODO: simplify byte_offset: range.map_or(0, |r| r.start), // TODO: simplify
injection_callback, injection_callback,
cancellation_flag, cancellation_flag,
iter_count: 0, iter_count: 0,
@ -1019,12 +1019,12 @@ impl<'a> HighlightIterLayer<'a> {
if queue.is_empty() { if queue.is_empty() {
break; break;
} else {
let (next_config, next_depth, next_ranges) = queue.remove(0);
config = next_config;
depth = next_depth;
ranges = next_ranges;
} }
let (next_config, next_depth, next_ranges) = queue.remove(0);
config = next_config;
depth = next_depth;
ranges = next_ranges;
} }
Ok(result) Ok(result)
@ -1292,7 +1292,7 @@ where
// If this capture represents an injection, then process the injection. // If this capture represents an injection, then process the injection.
if match_.pattern_index < layer.config.locals_pattern_index { if match_.pattern_index < layer.config.locals_pattern_index {
let (language_name, content_node, include_children) = let (language_name, content_node, include_children) =
injection_for_match(&layer.config, &layer.config.query, &match_, self.source); injection_for_match(layer.config, &layer.config.query, &match_, self.source);
// Explicitly remove this match so that none of its other captures will remain // Explicitly remove this match so that none of its other captures will remain
// in the stream of captures. // in the stream of captures.

@ -84,11 +84,7 @@ impl ChangeSet {
} }
let new_last = match self.changes.as_mut_slice() { let new_last = match self.changes.as_mut_slice() {
[.., Insert(prev)] => { [.., Insert(prev)] | [.., Insert(prev), Delete(_)] => {
prev.push_tendril(&fragment);
return;
}
[.., Insert(prev), Delete(_)] => {
prev.push_tendril(&fragment); prev.push_tendril(&fragment);
return; return;
} }
@ -115,7 +111,7 @@ impl ChangeSet {
/// Combine two changesets together. /// Combine two changesets together.
/// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the /// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
/// returned value will represent the change `docA` → `docC`. /// returned value will represent the change `docA` → `docC`.
pub fn compose(self, other: ChangeSet) -> Self { pub fn compose(self, other: Self) -> Self {
debug_assert!(self.len_after() == other.len); debug_assert!(self.len_after() == other.len);
let len = self.changes.len(); let len = self.changes.len();

@ -11,7 +11,7 @@ fn get_debug() -> bool {
env::var("DEBUG").unwrap() == "true" env::var("DEBUG").unwrap() == "true"
} }
fn collect_tree_sitter_dirs(ignore: Vec<String>) -> Vec<String> { fn collect_tree_sitter_dirs(ignore: &[String]) -> Vec<String> {
let mut dirs = Vec::new(); let mut dirs = Vec::new();
for entry in fs::read_dir("languages").unwrap().flatten() { for entry in fs::read_dir("languages").unwrap().flatten() {
let path = entry.path(); let path = entry.path();
@ -97,12 +97,12 @@ fn build_dir(dir: &str, language: &str) {
eprintln!("You can fix in using 'git submodule init && git submodule update --recursive'."); eprintln!("You can fix in using 'git submodule init && git submodule update --recursive'.");
std::process::exit(1); std::process::exit(1);
} }
let (c, cpp) = collect_src_files(&dir); let (c, cpp) = collect_src_files(dir);
if !c.is_empty() { if !c.is_empty() {
build_c(c, &language); build_c(c, language);
} }
if !cpp.is_empty() { if !cpp.is_empty() {
build_cpp(cpp, &language); build_cpp(cpp, language);
} }
} }
@ -111,7 +111,7 @@ fn main() {
"tree-sitter-typescript".to_string(), "tree-sitter-typescript".to_string(),
"tree-sitter-cpp".to_string(), "tree-sitter-cpp".to_string(),
]; ];
let dirs = collect_tree_sitter_dirs(ignore); let dirs = collect_tree_sitter_dirs(&ignore);
let mut n_jobs = 0; let mut n_jobs = 0;
let pool = threadpool::Builder::new().build(); // by going through the builder, it'll use num_cpus let pool = threadpool::Builder::new().build(); // by going through the builder, it'll use num_cpus
@ -123,7 +123,7 @@ fn main() {
pool.execute(move || { pool.execute(move || {
let language = &dir[12..]; // skip tree-sitter- prefix let language = &dir[12..]; // skip tree-sitter- prefix
build_dir(&dir, &language); build_dir(&dir, language);
// report progress // report progress
tx.send(1).unwrap(); tx.send(1).unwrap();

Loading…
Cancel
Save