on master help sign in
clippy lint
06aca76Blaž Hrastnik
helix-core/src/auto_pairs.rs+1
@@ -24,6 +24,7 @@ const CLOSE_BEFORE: &str = ")]}'\":;> \n"; // includes space and newline
24
24
25// TODO: delete implementation where it erases the whole bracket (|) -> |
25// TODO: delete implementation where it erases the whole bracket (|) -> |
26
26
27+#[must_use]
27pub fn hook(doc: &Rope, selection: &Selection, ch: char) -> Option<Transaction> {
28pub fn hook(doc: &Rope, selection: &Selection, ch: char) -> Option<Transaction> {
28 for &(open, close) in PAIRS {
29 for &(open, close) in PAIRS {
29 if open == ch {
30 if open == ch {
helix-core/src/comment.rs+1
@@ -37,6 +37,7 @@ fn find_line_comment(
37 (commented, skipped, min)
37 (commented, skipped, min)
38}
38}
39
39
40+#[must_use]
40pub fn toggle_line_comments(doc: &Rope, selection: &Selection) -> Transaction {
41pub fn toggle_line_comments(doc: &Rope, selection: &Selection) -> Transaction {
41 let text = doc.slice(..);
42 let text = doc.slice(..);
42 let mut changes: Vec<Change> = Vec::new();
43 let mut changes: Vec<Change> = Vec::new();
helix-core/src/graphemes.rs+6−2
@@ -3,6 +3,7 @@ use ropey::{iter::Chunks, str_utils::byte_to_char_idx, RopeSlice};
3use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete};
3use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete};
4use unicode_width::UnicodeWidthStr;
4use unicode_width::UnicodeWidthStr;
5
5
6+#[must_use]
6pub fn grapheme_width(g: &str) -> usize {
7pub fn grapheme_width(g: &str) -> usize {
7 if g.as_bytes()[0] <= 127 {
8 if g.as_bytes()[0] <= 127 {
8 // Fast-path ascii.
9 // Fast-path ascii.
@@ -26,6 +27,7 @@ pub fn grapheme_width(g: &str) -> usize {
26 }
27 }
27}
28}
28
29
30+#[must_use]
29pub fn nth_prev_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) -> usize {
31pub fn nth_prev_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) -> usize {
30 // Bounds check
32 // Bounds check
31 debug_assert!(char_idx <= slice.len_chars());
33 debug_assert!(char_idx <= slice.len_chars());
@@ -71,6 +73,7 @@ pub fn prev_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> usize {
71 nth_prev_grapheme_boundary(slice, char_idx, 1)
73 nth_prev_grapheme_boundary(slice, char_idx, 1)
72}
74}
73
75
76+#[must_use]
74pub fn nth_next_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) -> usize {
77pub fn nth_next_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) -> usize {
75 // Bounds check
78 // Bounds check
76 debug_assert!(char_idx <= slice.len_chars());
79 debug_assert!(char_idx <= slice.len_chars());
@@ -138,12 +141,12 @@ pub fn is_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> bool {
138 let (ctx_chunk, ctx_byte_start, _, _) = slice.chunk_at_byte(n - 1);
141 let (ctx_chunk, ctx_byte_start, _, _) = slice.chunk_at_byte(n - 1);
139 gc.provide_context(ctx_chunk, ctx_byte_start);
142 gc.provide_context(ctx_chunk, ctx_byte_start);
140 }
143 }
141− _ => unreachable!(),
144+ Err(_) => unreachable!(),
142 }
145 }
143 }
146 }
144}
147}
145
148
146−/// An iterator over the graphemes of a RopeSlice.
149+/// An iterator over the graphemes of a `RopeSlice`.
147#[derive(Clone)]
150#[derive(Clone)]
148pub struct RopeGraphemes<'a> {
151pub struct RopeGraphemes<'a> {
149 text: RopeSlice<'a>,
152 text: RopeSlice<'a>,
@@ -154,6 +157,7 @@ pub struct RopeGraphemes<'a> {
154}
157}
155
158
156impl<'a> RopeGraphemes<'a> {
159impl<'a> RopeGraphemes<'a> {
160+ #[must_use]
157 pub fn new(slice: RopeSlice) -> RopeGraphemes {
161 pub fn new(slice: RopeSlice) -> RopeGraphemes {
158 let mut chunks = slice.chunks();
162 let mut chunks = slice.chunks();
159 let first_chunk = chunks.next().unwrap_or("");
163 let first_chunk = chunks.next().unwrap_or("");
helix-core/src/history.rs+1−1
@@ -53,7 +53,7 @@ impl History {
53 }
53 }
54
54
55 #[inline]
55 #[inline]
56− pub fn at_root(&self) -> bool {
56+ pub const fn at_root(&self) -> bool {
57 self.cursor == 0
57 self.cursor == 0
58 }
58 }
59
59
helix-core/src/match_brackets.rs+1
@@ -3,6 +3,7 @@ use crate::{Range, Rope, Selection, Syntax};
3// const PAIRS: &[(char, char)] = &[('(', ')'), ('{', '}'), ('[', ']')];
3// const PAIRS: &[(char, char)] = &[('(', ')'), ('{', '}'), ('[', ']')];
4// limit matching pairs to only ( ) { } [ ] < >
4// limit matching pairs to only ( ) { } [ ] < >
5
5
6+#[must_use]
6pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
7pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
7 let tree = syntax.root_layer.tree.as_ref().unwrap();
8 let tree = syntax.root_layer.tree.as_ref().unwrap();
8
9
helix-core/src/position.rs+1−1
@@ -37,7 +37,7 @@ impl Position {
37
37
38impl From<(usize, usize)> for Position {
38impl From<(usize, usize)> for Position {
39 fn from(tuple: (usize, usize)) -> Self {
39 fn from(tuple: (usize, usize)) -> Self {
40− Position {
40+ Self {
41 row: tuple.0,
41 row: tuple.0,
42 col: tuple.1,
42 col: tuple.1,
43 }
43 }
helix-core/src/selection.rs+3−3
@@ -99,14 +99,14 @@ impl Range {
99 #[must_use]
99 #[must_use]
100 pub fn extend(&self, from: usize, to: usize) -> Self {
100 pub fn extend(&self, from: usize, to: usize) -> Self {
101 if from <= self.anchor && to >= self.anchor {
101 if from <= self.anchor && to >= self.anchor {
102− return Range {
102+ return Self {
103 anchor: from,
103 anchor: from,
104 head: to,
104 head: to,
105 horiz: None,
105 horiz: None,
106 };
106 };
107 }
107 }
108
108
109− Range {
109+ Self {
110 anchor: self.anchor,
110 anchor: self.anchor,
111 head: if abs_difference(from, self.anchor) > abs_difference(to, self.anchor) {
111 head: if abs_difference(from, self.anchor) > abs_difference(to, self.anchor) {
112 from
112 from
@@ -253,7 +253,7 @@ impl Selection {
253
253
254 // fast path for a single selection (cursor)
254 // fast path for a single selection (cursor)
255 if ranges.len() == 1 {
255 if ranges.len() == 1 {
256− return Selection {
256+ return Self {
257 ranges,
257 ranges,
258 primary_index: 0,
258 primary_index: 0,
259 };
259 };
helix-core/src/syntax.rs+11−11
@@ -66,10 +66,10 @@ impl LanguageConfiguration {
66 language,
66 language,
67 &highlights_query,
67 &highlights_query,
68 &injections_query,
68 &injections_query,
69− &locals_query,
69+ locals_query,
70 )
70 )
71 .unwrap(); // TODO: no unwrap
71 .unwrap(); // TODO: no unwrap
72− config.configure(&scopes);
72+ config.configure(scopes);
73 Some(Arc::new(config))
73 Some(Arc::new(config))
74 }
74 }
75 })
75 })
@@ -90,8 +90,8 @@ pub struct Loader {
90}
90}
91
91
92impl Loader {
92impl Loader {
93− fn init() -> Loader {
93+ fn init() -> Self {
94− let mut loader = Loader {
94+ let mut loader = Self {
95 language_configs: Vec::new(),
95 language_configs: Vec::new(),
96 language_config_ids_by_file_type: HashMap::new(),
96 language_config_ids_by_file_type: HashMap::new(),
97 };
97 };
@@ -331,7 +331,7 @@ impl Syntax {
331
331
332 let mut result = HighlightIter {
332 let mut result = HighlightIter {
333 source,
333 source,
334− byte_offset: range.map(|r| r.start).unwrap_or(0), // TODO: simplify
334+ byte_offset: range.map_or(0, |r| r.start), // TODO: simplify
335 injection_callback,
335 injection_callback,
336 cancellation_flag,
336 cancellation_flag,
337 iter_count: 0,
337 iter_count: 0,
@@ -1019,12 +1019,12 @@ impl<'a> HighlightIterLayer<'a> {
1019
1019
1020 if queue.is_empty() {
1020 if queue.is_empty() {
1021 break;
1021 break;
1022− } else {
1023− let (next_config, next_depth, next_ranges) = queue.remove(0);
1024− config = next_config;
1025− depth = next_depth;
1026− ranges = next_ranges;
1027 }
1022 }
1023+
1024+ let (next_config, next_depth, next_ranges) = queue.remove(0);
1025+ config = next_config;
1026+ depth = next_depth;
1027+ ranges = next_ranges;
1028 }
1028 }
1029
1029
1030 Ok(result)
1030 Ok(result)
@@ -1292,7 +1292,7 @@ where
1292 // If this capture represents an injection, then process the injection.
1292 // If this capture represents an injection, then process the injection.
1293 if match_.pattern_index < layer.config.locals_pattern_index {
1293 if match_.pattern_index < layer.config.locals_pattern_index {
1294 let (language_name, content_node, include_children) =
1294 let (language_name, content_node, include_children) =
1295− injection_for_match(&layer.config, &layer.config.query, &match_, self.source);
1295+ injection_for_match(layer.config, &layer.config.query, &match_, self.source);
1296
1296
1297 // Explicitly remove this match so that none of its other captures will remain
1297 // Explicitly remove this match so that none of its other captures will remain
1298 // in the stream of captures.
1298 // in the stream of captures.
helix-core/src/transaction.rs+2−6
@@ -84,11 +84,7 @@ impl ChangeSet {
84 }
84 }
85
85
86 let new_last = match self.changes.as_mut_slice() {
86 let new_last = match self.changes.as_mut_slice() {
87− [.., Insert(prev)] => {
88− prev.push_tendril(&fragment);
89− return;
90− }
91− [.., Insert(prev), Delete(_)] => {
87+ [.., Insert(prev)] | [.., Insert(prev), Delete(_)] => {
92 prev.push_tendril(&fragment);
88 prev.push_tendril(&fragment);
93 return;
89 return;
94 }
90 }
@@ -115,7 +111,7 @@ impl ChangeSet {
115 /// Combine two changesets together.
111 /// Combine two changesets together.
116 /// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
112 /// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
117 /// returned value will represent the change `docA` → `docC`.
113 /// returned value will represent the change `docA` → `docC`.
118− pub fn compose(self, other: ChangeSet) -> Self {
114+ pub fn compose(self, other: Self) -> Self {
119 debug_assert!(self.len_after() == other.len);
115 debug_assert!(self.len_after() == other.len);
120
116
121 let len = self.changes.len();
117 let len = self.changes.len();
helix-syntax/build.rs+6−6
@@ -11,7 +11,7 @@ fn get_debug() -> bool {
11 env::var("DEBUG").unwrap() == "true"
11 env::var("DEBUG").unwrap() == "true"
12}
12}
13
13
14−fn collect_tree_sitter_dirs(ignore: Vec<String>) -> Vec<String> {
14+fn collect_tree_sitter_dirs(ignore: &[String]) -> Vec<String> {
15 let mut dirs = Vec::new();
15 let mut dirs = Vec::new();
16 for entry in fs::read_dir("languages").unwrap().flatten() {
16 for entry in fs::read_dir("languages").unwrap().flatten() {
17 let path = entry.path();
17 let path = entry.path();
@@ -97,12 +97,12 @@ fn build_dir(dir: &str, language: &str) {
97 eprintln!("You can fix in using 'git submodule init && git submodule update --recursive'.");
97 eprintln!("You can fix in using 'git submodule init && git submodule update --recursive'.");
98 std::process::exit(1);
98 std::process::exit(1);
99 }
99 }
100− let (c, cpp) = collect_src_files(&dir);
100+ let (c, cpp) = collect_src_files(dir);
101 if !c.is_empty() {
101 if !c.is_empty() {
102− build_c(c, &language);
102+ build_c(c, language);
103 }
103 }
104 if !cpp.is_empty() {
104 if !cpp.is_empty() {
105− build_cpp(cpp, &language);
105+ build_cpp(cpp, language);
106 }
106 }
107}
107}
108
108
@@ -111,7 +111,7 @@ fn main() {
111 "tree-sitter-typescript".to_string(),
111 "tree-sitter-typescript".to_string(),
112 "tree-sitter-cpp".to_string(),
112 "tree-sitter-cpp".to_string(),
113 ];
113 ];
114− let dirs = collect_tree_sitter_dirs(ignore);
114+ let dirs = collect_tree_sitter_dirs(&ignore);
115
115
116 let mut n_jobs = 0;
116 let mut n_jobs = 0;
117 let pool = threadpool::Builder::new().build(); // by going through the builder, it'll use num_cpus
117 let pool = threadpool::Builder::new().build(); // by going through the builder, it'll use num_cpus
@@ -123,7 +123,7 @@ fn main() {
123
123
124 pool.execute(move || {
124 pool.execute(move || {
125 let language = &dir[12..]; // skip tree-sitter- prefix
125 let language = &dir[12..]; // skip tree-sitter- prefix
126− build_dir(&dir, &language);
126+ build_dir(&dir, language);
127
127
128 // report progress
128 // report progress
129 tx.send(1).unwrap();
129 tx.send(1).unwrap();