on master help sign in
treewide: &RopeSlice -> RopeSlice. It's Copy so no reason to pass by ref
commitc9dd1c930edee68a32ef19ee407820c247937b05 authorBlaž Hrastnik <blaz@mxxn.io> dateThu 18 Feb 2021, 18:34 (6 years ago) parentbd85460
12 files changed+118−101
helix-core/src/graphemes.rs+7−7 helix-core/src/indent.rs+8−23 helix-core/src/lib.rs+30 helix-core/src/selection.rs+8−8 helix-core/src/state.rs+26−24 helix-core/src/syntax.rs+9−9 helix-lsp/src/client.rs+2−2 helix-lsp/src/lib.rs+4−4 helix-term/src/application.rs+2−2 helix-term/src/commands.rs+15−15 helix-term/src/ui/editor.rs+4−4 helix-view/src/view.rs+3−3
helix-core/src/graphemes.rs+7−7
@@ -26,7 +26,7 @@ pub fn grapheme_width(g: &str) -> usize {
2626 }
2727}
2828
29−pub fn nth_prev_grapheme_boundary(slice: &RopeSlice, char_idx: usize, n: usize) -> usize {
29+pub fn nth_prev_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) -> usize {
3030 // TODO: implement this more efficiently. This has to do a lot of
3131 // re-scanning of rope chunks. Probably move the main implementation here,
3232 // and have prev_grapheme_boundary call this instead.
@@ -38,7 +38,7 @@ pub fn nth_prev_grapheme_boundary(slice: &RopeSlice, char_idx: usize, n: usize)
3838}
3939
4040/// Finds the previous grapheme boundary before the given char position.
41−pub fn prev_grapheme_boundary(slice: &RopeSlice, char_idx: usize) -> usize {
41+pub fn prev_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> usize {
4242 // Bounds check
4343 debug_assert!(char_idx <= slice.len_chars());
4444
@@ -74,7 +74,7 @@ pub fn prev_grapheme_boundary(slice: &RopeSlice, char_idx: usize) -> usize {
7474 }
7575}
7676
77−pub fn nth_next_grapheme_boundary(slice: &RopeSlice, char_idx: usize, n: usize) -> usize {
77+pub fn nth_next_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) -> usize {
7878 // TODO: implement this more efficiently. This has to do a lot of
7979 // re-scanning of rope chunks. Probably move the main implementation here,
8080 // and have next_grapheme_boundary call this instead.
@@ -86,7 +86,7 @@ pub fn nth_next_grapheme_boundary(slice: &RopeSlice, char_idx: usize, n: usize)
8686}
8787
8888/// Finds the next grapheme boundary after the given char position.
89−pub fn next_grapheme_boundary(slice: &RopeSlice, char_idx: usize) -> usize {
89+pub fn next_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> usize {
9090 // Bounds check
9191 debug_assert!(char_idx <= slice.len_chars());
9292
@@ -123,7 +123,7 @@ pub fn next_grapheme_boundary(slice: &RopeSlice, char_idx: usize) -> usize {
123123}
124124
125125/// Returns whether the given char position is a grapheme boundary.
126−pub fn is_grapheme_boundary(slice: &RopeSlice, char_idx: usize) -> bool {
126+pub fn is_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> bool {
127127 // Bounds check
128128 debug_assert!(char_idx <= slice.len_chars());
129129
@@ -160,11 +160,11 @@ pub struct RopeGraphemes<'a> {
160160}
161161
162162impl<'a> RopeGraphemes<'a> {
163− pub fn new<'b>(slice: &RopeSlice<'b>) -> RopeGraphemes<'b> {
163+ pub fn new<'b>(slice: RopeSlice<'b>) -> RopeGraphemes<'b> {
164164 let mut chunks = slice.chunks();
165165 let first_chunk = chunks.next().unwrap_or("");
166166 RopeGraphemes {
167− text: *slice,
167+ text: slice,
168168 chunks,
169169 cur_chunk: first_chunk,
170170 cur_chunk_start: 0,
helix-core/src/indent.rs+8−23
@@ -1,4 +1,5 @@
11use crate::{
2+ find_first_non_whitespace_char,
23 syntax::Syntax,
34 tree_sitter::{Node, Tree},
45 Rope, RopeSlice, State,
@@ -9,7 +10,7 @@ use crate::{
910
1011pub const TAB_WIDTH: usize = 4;
1112
12−fn indent_level_for_line(line: &RopeSlice) -> usize {
13+fn indent_level_for_line(line: RopeSlice) -> usize {
1314 let mut len = 0;
1415 for ch in line.chars() {
1516 match ch {
@@ -159,27 +160,11 @@ fn calculate_indentation(node: Option<Node>, newline: bool) -> usize {
159160 increment as usize
160161}
161162
162−fn find_first_non_whitespace_char(state: &State, line_num: usize) -> Option<usize> {
163− let line = state.doc.line(line_num);
164− let mut start = state.doc.line_to_char(line_num);
165−
166− // find first non-whitespace char
167− for ch in line.chars() {
168− // TODO: could use memchr with chunks?
169− if ch != ' ' && ch != '\t' && ch != '\n' {
170− return Some(start);
171− }
172− start += 1;
173− }
174−
175− None
176−}
177−
178163fn suggested_indent_for_line(syntax: Option<&Syntax>, state: &State, line_num: usize) -> usize {
179164 let line = state.doc.line(line_num);
180− let current = indent_level_for_line(&line);
165+ let current = indent_level_for_line(line);
181166
182− if let Some(start) = find_first_non_whitespace_char(state, line_num) {
167+ if let Some(start) = find_first_non_whitespace_char(state.doc.slice(..), line_num) {
183168 return suggested_indent_for_pos(syntax, state, start, false);
184169 };
185170
@@ -216,12 +201,12 @@ mod test {
216201 #[test]
217202 fn test_indent_level() {
218203 let line = Rope::from(" fn new"); // 8 spaces
219− assert_eq!(indent_level_for_line(&line.slice(..)), 2);
204+ assert_eq!(indent_level_for_line(line.slice(..)), 2);
220205 let line = Rope::from("\t\t\tfn new"); // 3 tabs
221− assert_eq!(indent_level_for_line(&line.slice(..)), 3);
206+ assert_eq!(indent_level_for_line(line.slice(..)), 3);
222207 // mixed indentation
223208 let line = Rope::from("\t \tfn new"); // 1 tab, 4 spaces, tab
224− assert_eq!(indent_level_for_line(&line.slice(..)), 3);
209+ assert_eq!(indent_level_for_line(line.slice(..)), 3);
225210 }
226211
227212 #[test]
@@ -306,7 +291,7 @@ where
306291
307292 for i in 0..state.doc.len_lines() {
308293 let line = text.line(i);
309− let indent = indent_level_for_line(&line);
294+ let indent = indent_level_for_line(line);
310295 assert_eq!(
311296 suggested_indent_for_line(Some(&syntax), &state, i),
312297 indent,
helix-core/src/lib.rs+30
@@ -11,6 +11,36 @@ pub mod state;
1111pub mod syntax;
1212mod transaction;
1313
14+pub(crate) fn find_first_non_whitespace_char2(line: RopeSlice) -> Option<usize> {
15+ let mut start = 0;
16+
17+ // find first non-whitespace char
18+ for ch in line.chars() {
19+ // TODO: could use memchr with chunks?
20+ if ch != ' ' && ch != '\t' && ch != '\n' {
21+ return Some(start);
22+ }
23+ start += 1;
24+ }
25+
26+ None
27+}
28+pub(crate) fn find_first_non_whitespace_char(text: RopeSlice, line_num: usize) -> Option<usize> {
29+ let line = text.line(line_num);
30+ let mut start = text.line_to_char(line_num);
31+
32+ // find first non-whitespace char
33+ for ch in line.chars() {
34+ // TODO: could use memchr with chunks?
35+ if ch != ' ' && ch != '\t' && ch != '\n' {
36+ return Some(start);
37+ }
38+ start += 1;
39+ }
40+
41+ None
42+}
43+
1444pub use ropey::{Rope, RopeSlice};
1545
1646pub use tendril::StrTendril as Tendril;
helix-core/src/selection.rs+8−8
@@ -120,7 +120,7 @@ impl Range {
120120 // groupAt
121121
122122 #[inline]
123− pub fn fragment<'a>(&'a self, text: &'a RopeSlice) -> Cow<'a, str> {
123+ pub fn fragment<'a>(&'a self, text: RopeSlice<'a>) -> Cow<'a, str> {
124124 Cow::from(text.slice(self.from()..self.to() + 1))
125125 }
126126}
@@ -267,7 +267,7 @@ impl Selection {
267267 )
268268 }
269269
270− pub fn fragments<'a>(&'a self, text: &'a RopeSlice) -> impl Iterator<Item = Cow<str>> + 'a {
270+ pub fn fragments<'a>(&'a self, text: RopeSlice<'a>) -> impl Iterator<Item = Cow<str>> + 'a {
271271 self.ranges.iter().map(move |range| range.fragment(text))
272272 }
273273}
@@ -275,7 +275,7 @@ impl Selection {
275275// TODO: checkSelection -> check if valid for doc length
276276
277277pub fn select_on_matches(
278− text: &RopeSlice,
278+ text: RopeSlice,
279279 selections: &Selection,
280280 regex: &crate::regex::Regex,
281281) -> Option<Selection> {
@@ -283,7 +283,7 @@ pub fn select_on_matches(
283283
284284 for sel in selections.ranges() {
285285 // TODO: can't avoid occasional allocations since Regex can't operate on chunks yet
286− let fragment = sel.fragment(&text);
286+ let fragment = sel.fragment(text);
287287
288288 let mut sel_start = sel.from();
289289 let sel_end = sel.to();
@@ -309,7 +309,7 @@ pub fn select_on_matches(
309309
310310// TODO: support to split on capture #N instead of whole match
311311pub fn split_on_matches(
312− text: &RopeSlice,
312+ text: RopeSlice,
313313 selections: &Selection,
314314 regex: &crate::regex::Regex,
315315) -> Selection {
@@ -317,7 +317,7 @@ pub fn split_on_matches(
317317
318318 for sel in selections.ranges() {
319319 // TODO: can't avoid occasional allocations since Regex can't operate on chunks yet
320− let fragment = sel.fragment(&text);
320+ let fragment = sel.fragment(text);
321321
322322 let mut sel_start = sel.from();
323323 let sel_end = sel.to();
@@ -420,7 +420,7 @@ mod test {
420420
421421 let selections = Selection::new(smallvec![Range::new(0, 8), Range::new(10, 19),], 0);
422422
423− let result = split_on_matches(&text.slice(..), &selections, &Regex::new(r"\s+").unwrap());
423+ let result = split_on_matches(text.slice(..), &selections, &Regex::new(r"\s+").unwrap());
424424
425425 assert_eq!(
426426 result.ranges(),
@@ -434,7 +434,7 @@ mod test {
434434 );
435435
436436 assert_eq!(
437− result.fragments(&text.slice(..)).collect::<Vec<_>>(),
437+ result.fragments(text.slice(..)).collect::<Vec<_>>(),
438438 &["abcd", "efg", "rs", "xyz", "1"]
439439 );
440440 }
helix-core/src/state.rs+26−24
@@ -101,7 +101,7 @@ impl State {
101101 let line = text.char_to_line(pos);
102102 let start = text.line_to_char(line);
103103 let pos = std::cmp::max(
104− nth_prev_grapheme_boundary(&text.slice(..), pos, count),
104+ nth_prev_grapheme_boundary(text.slice(..), pos, count),
105105 start,
106106 );
107107 Range::new(if extend { range.anchor } else { pos }, pos)
@@ -113,14 +113,14 @@ impl State {
113113 // subtract another 1 because the line ends with \n
114114 let end = text.line_to_char(line + 1).saturating_sub(2);
115115 let pos =
116− std::cmp::min(nth_next_grapheme_boundary(&text.slice(..), pos, count), end);
116+ std::cmp::min(nth_next_grapheme_boundary(text.slice(..), pos, count), end);
117117 Range::new(if extend { range.anchor } else { pos }, pos)
118118 }
119− (_, Granularity::Line) => move_vertically(&text.slice(..), dir, range, count, extend),
119+ (_, Granularity::Line) => move_vertically(text.slice(..), dir, range, count, extend),
120120 }
121121 }
122122
123− pub fn move_next_word_start(slice: &RopeSlice, mut pos: usize) -> usize {
123+ pub fn move_next_word_start(slice: RopeSlice, mut pos: usize) -> usize {
124124 // TODO: confirm it's fine without using graphemes, I think it should be
125125 let ch = slice.char(pos);
126126 let next = slice.char(pos.saturating_add(1));
@@ -143,7 +143,7 @@ impl State {
143143 pos
144144 }
145145
146− pub fn move_prev_word_start(slice: &RopeSlice, mut pos: usize) -> usize {
146+ pub fn move_prev_word_start(slice: RopeSlice, mut pos: usize) -> usize {
147147 // TODO: confirm it's fine without using graphemes, I think it should be
148148 let ch = slice.char(pos);
149149 let prev = slice.char(pos.saturating_sub(1)); // TODO: just return original pos if at start
@@ -169,7 +169,7 @@ impl State {
169169 pos.saturating_add(1)
170170 }
171171
172− pub fn move_next_word_end(slice: &RopeSlice, mut pos: usize, _count: usize) -> usize {
172+ pub fn move_next_word_end(slice: RopeSlice, mut pos: usize, _count: usize) -> usize {
173173 // TODO: confirm it's fine without using graphemes, I think it should be
174174 let ch = slice.char(pos);
175175 let next = slice.char(pos.saturating_add(1));
@@ -217,7 +217,7 @@ impl State {
217217}
218218
219219/// Convert a character index to (line, column) coordinates.
220−pub fn coords_at_pos(text: &RopeSlice, pos: usize) -> Position {
220+pub fn coords_at_pos(text: RopeSlice, pos: usize) -> Position {
221221 let line = text.char_to_line(pos);
222222 let line_start = text.line_to_char(line);
223223 let col = text.slice(line_start..pos).len_chars();
@@ -225,14 +225,14 @@ pub fn coords_at_pos(text: &RopeSlice, pos: usize) -> Position {
225225}
226226
227227/// Convert (line, column) coordinates to a character index.
228−pub fn pos_at_coords(text: &RopeSlice, coords: Position) -> usize {
228+pub fn pos_at_coords(text: RopeSlice, coords: Position) -> usize {
229229 let Position { row, col } = coords;
230230 let line_start = text.line_to_char(row);
231231 nth_next_grapheme_boundary(text, line_start, col)
232232}
233233
234234fn move_vertically(
235− text: &RopeSlice,
235+ text: RopeSlice,
236236 dir: Direction,
237237 range: Range,
238238 count: usize,
@@ -287,7 +287,7 @@ fn categorize(ch: char) -> Category {
287287 }
288288}
289289
290−fn skip_over_next<F>(slice: &RopeSlice, pos: &mut usize, fun: F)
290+fn skip_over_next<F>(slice: RopeSlice, pos: &mut usize, fun: F)
291291where
292292 F: Fn(char) -> bool,
293293{
@@ -301,7 +301,7 @@ where
301301 }
302302}
303303
304−fn skip_over_prev<F>(slice: &RopeSlice, pos: &mut usize, fun: F)
304+fn skip_over_prev<F>(slice: RopeSlice, pos: &mut usize, fun: F)
305305where
306306 F: Fn(char) -> bool,
307307{
@@ -323,34 +323,36 @@ mod test {
323323 #[test]
324324 fn test_coords_at_pos() {
325325 let text = Rope::from("ḧëḷḷö\nẅöṛḷḋ");
326− assert_eq!(coords_at_pos(&text.slice(..), 0), (0, 0).into());
327− assert_eq!(coords_at_pos(&text.slice(..), 5), (0, 5).into()); // position on \n
328− assert_eq!(coords_at_pos(&text.slice(..), 6), (1, 0).into()); // position on w
329− assert_eq!(coords_at_pos(&text.slice(..), 7), (1, 1).into()); // position on o
330− assert_eq!(coords_at_pos(&text.slice(..), 10), (1, 4).into()); // position on d
326+ let slice = text.slice(..);
327+ assert_eq!(coords_at_pos(slice, 0), (0, 0).into());
328+ assert_eq!(coords_at_pos(slice, 5), (0, 5).into()); // position on \n
329+ assert_eq!(coords_at_pos(slice, 6), (1, 0).into()); // position on w
330+ assert_eq!(coords_at_pos(slice, 7), (1, 1).into()); // position on o
331+ assert_eq!(coords_at_pos(slice, 10), (1, 4).into()); // position on d
331332 }
332333
333334 #[test]
334335 fn test_pos_at_coords() {
335336 let text = Rope::from("ḧëḷḷö\nẅöṛḷḋ");
336− assert_eq!(pos_at_coords(&text.slice(..), (0, 0).into()), 0);
337− assert_eq!(pos_at_coords(&text.slice(..), (0, 5).into()), 5); // position on \n
338− assert_eq!(pos_at_coords(&text.slice(..), (1, 0).into()), 6); // position on w
339− assert_eq!(pos_at_coords(&text.slice(..), (1, 1).into()), 7); // position on o
340− assert_eq!(pos_at_coords(&text.slice(..), (1, 4).into()), 10); // position on d
337+ let slice = text.slice(..);
338+ assert_eq!(pos_at_coords(slice, (0, 0).into()), 0);
339+ assert_eq!(pos_at_coords(slice, (0, 5).into()), 5); // position on \n
340+ assert_eq!(pos_at_coords(slice, (1, 0).into()), 6); // position on w
341+ assert_eq!(pos_at_coords(slice, (1, 1).into()), 7); // position on o
342+ assert_eq!(pos_at_coords(slice, (1, 4).into()), 10); // position on d
341343 }
342344
343345 #[test]
344346 fn test_vertical_move() {
345347 let text = Rope::from("abcd\nefg\nwrs");
346− let pos = pos_at_coords(&text.slice(..), (0, 4).into());
347348 let slice = text.slice(..);
349+ let pos = pos_at_coords(slice, (0, 4).into());
348350
349351 let range = Range::new(pos, pos);
350352 assert_eq!(
351353 coords_at_pos(
352− &slice,
353− move_vertically(&slice, Direction::Forward, range, 1, false).head
354+ slice,
355+ move_vertically(slice, Direction::Forward, range, 1, false).head
354356 ),
355357 (1, 2).into()
356358 );
helix-core/src/syntax.rs+9−9
@@ -406,7 +406,7 @@ impl LanguageLayer {
406406 }
407407
408408 pub(crate) fn generate_edits(
409− old_text: &RopeSlice,
409+ old_text: RopeSlice,
410410 changeset: &ChangeSet,
411411 ) -> Vec<tree_sitter::InputEdit> {
412412 use Operation::*;
@@ -419,7 +419,7 @@ impl LanguageLayer {
419419
420420 // TODO; this is a lot easier with Change instead of Operation.
421421
422− fn point_at_pos(text: &RopeSlice, pos: usize) -> (usize, Point) {
422+ fn point_at_pos(text: RopeSlice, pos: usize) -> (usize, Point) {
423423 let byte = text.char_to_byte(pos); // <- attempted to index past end
424424 let line = text.char_to_line(pos);
425425 let line_start_byte = text.line_to_byte(line);
@@ -458,8 +458,8 @@ impl LanguageLayer {
458458 new_pos += len;
459459 }
460460 Delete(_) => {
461− let (start_byte, start_position) = point_at_pos(&old_text, old_pos);
462− let (old_end_byte, old_end_position) = point_at_pos(&old_text, old_end);
461+ let (start_byte, start_position) = point_at_pos(old_text, old_pos);
462+ let (old_end_byte, old_end_position) = point_at_pos(old_text, old_end);
463463
464464 // TODO: Position also needs to be byte based...
465465 // let byte = char_to_byte(old_pos)
@@ -478,14 +478,14 @@ impl LanguageLayer {
478478 });
479479 }
480480 Insert(s) => {
481− let (start_byte, start_position) = point_at_pos(&old_text, old_pos);
481+ let (start_byte, start_position) = point_at_pos(old_text, old_pos);
482482
483483 let ins = s.chars().count();
484484
485485 // a subsequent delete means a replace, consume it
486486 if let Some(Delete(len)) = iter.peek() {
487487 old_end = old_pos + len;
488− let (old_end_byte, old_end_position) = point_at_pos(&old_text, old_end);
488+ let (old_end_byte, old_end_position) = point_at_pos(old_text, old_end);
489489
490490 iter.next();
491491
@@ -530,7 +530,7 @@ impl LanguageLayer {
530530 return Ok(());
531531 }
532532
533− let edits = Self::generate_edits(&old_source.slice(..), changeset);
533+ let edits = Self::generate_edits(old_source.slice(..), changeset);
534534
535535 // Notify the tree about all the changes
536536 for edit in edits {
@@ -1528,7 +1528,7 @@ fn test_input_edits() {
15281528 &state,
15291529 vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),
15301530 );
1531− let edits = LanguageLayer::generate_edits(&state.doc.slice(..), &transaction.changes);
1531+ let edits = LanguageLayer::generate_edits(state.doc.slice(..), &transaction.changes);
15321532 // transaction.apply(&mut state);
15331533
15341534 assert_eq!(
@@ -1556,7 +1556,7 @@ fn test_input_edits() {
15561556 // Testing with the official example from tree-sitter
15571557 let mut state = State::new("fn test() {}".into());
15581558 let transaction = Transaction::change(&state, vec![(8, 8, Some("a: u32".into()))].into_iter());
1559− let edits = LanguageLayer::generate_edits(&state.doc.slice(..), &transaction.changes);
1559+ let edits = LanguageLayer::generate_edits(state.doc.slice(..), &transaction.changes);
15601560 transaction.apply(&mut state);
15611561
15621562 assert_eq!(state.doc(), "fn test(a: u32) {}");
helix-lsp/src/client.rs+2−2
@@ -303,7 +303,7 @@ impl Client {
303303 new_pos += i;
304304 }
305305 Delete(_) => {
306− let start = pos_to_lsp_pos(&new_text, new_pos);
306+ let start = pos_to_lsp_pos(new_text, new_pos);
307307 let end = traverse(start, old_text.slice(old_pos..old_end));
308308
309309 // deletion
@@ -314,7 +314,7 @@ impl Client {
314314 });
315315 }
316316 Insert(s) => {
317− let start = pos_to_lsp_pos(&new_text, new_pos);
317+ let start = pos_to_lsp_pos(new_text, new_pos);
318318
319319 new_pos += s.chars().count();
320320
helix-lsp/src/lib.rs+4−4
@@ -30,12 +30,12 @@ pub mod util {
3030 use super::*;
3131 use helix_core::{RopeSlice, State, Transaction};
3232
33− pub fn lsp_pos_to_pos(doc: &RopeSlice, pos: lsp::Position) -> usize {
33+ pub fn lsp_pos_to_pos(doc: RopeSlice, pos: lsp::Position) -> usize {
3434 let line = doc.line_to_char(pos.line as usize);
3535 let line_start = doc.char_to_utf16_cu(line);
3636 doc.utf16_cu_to_char(pos.character as usize + line_start)
3737 }
38− pub fn pos_to_lsp_pos(doc: &RopeSlice, pos: usize) -> lsp::Position {
38+ pub fn pos_to_lsp_pos(doc: RopeSlice, pos: usize) -> lsp::Position {
3939 let line = doc.char_to_line(pos);
4040 let line_start = doc.char_to_utf16_cu(doc.line_to_char(line));
4141 let col = doc.char_to_utf16_cu(pos) - line_start;
@@ -58,8 +58,8 @@ pub mod util {
5858 None
5959 };
6060
61− let start = lsp_pos_to_pos(&doc, edit.range.start);
62− let end = lsp_pos_to_pos(&doc, edit.range.end);
61+ let start = lsp_pos_to_pos(doc, edit.range.start);
62+ let end = lsp_pos_to_pos(doc, edit.range.end);
6363 (start, end, replacement)
6464 }),
6565 )
helix-term/src/application.rs+2−2
@@ -147,8 +147,8 @@ impl Application {
147147 .into_iter()
148148 .map(|diagnostic| {
149149 use helix_lsp::util::lsp_pos_to_pos;
150− let start = lsp_pos_to_pos(&doc, diagnostic.range.start);
151− let end = lsp_pos_to_pos(&doc, diagnostic.range.end);
150+ let start = lsp_pos_to_pos(doc, diagnostic.range.start);
151+ let end = lsp_pos_to_pos(doc, diagnostic.range.end);
152152
153153 helix_core::Diagnostic {
154154 range: (start, end),
helix-term/src/commands.rs+15−15
@@ -117,7 +117,7 @@ pub fn move_next_word_start(cx: &mut Context) {
117117 let count = cx.count;
118118 let doc = cx.doc();
119119 // TODO: count
120− let pos = State::move_next_word_start(&doc.text().slice(..), doc.selection().cursor());
120+ let pos = State::move_next_word_start(doc.text().slice(..), doc.selection().cursor());
121121
122122 doc.set_selection(Selection::point(pos));
123123}
@@ -125,7 +125,7 @@ pub fn move_next_word_start(cx: &mut Context) {
125125pub fn move_prev_word_start(cx: &mut Context) {
126126 let count = cx.count;
127127 let doc = cx.doc();
128− let pos = State::move_prev_word_start(&doc.text().slice(..), doc.selection().cursor());
128+ let pos = State::move_prev_word_start(doc.text().slice(..), doc.selection().cursor());
129129
130130 doc.set_selection(Selection::point(pos));
131131}
@@ -133,7 +133,7 @@ pub fn move_prev_word_start(cx: &mut Context) {
133133pub fn move_next_word_end(cx: &mut Context) {
134134 let count = cx.count;
135135 let doc = cx.doc();
136− let pos = State::move_next_word_end(&doc.text().slice(..), doc.selection().cursor(), count);
136+ let pos = State::move_next_word_end(doc.text().slice(..), doc.selection().cursor(), count);
137137
138138 doc.set_selection(Selection::point(pos));
139139}
@@ -156,7 +156,7 @@ pub fn extend_next_word_start(cx: &mut Context) {
156156 let count = cx.count;
157157 let doc = cx.doc();
158158 let mut selection = doc.selection().transform(|mut range| {
159− let pos = State::move_next_word_start(&doc.text().slice(..), doc.selection().cursor());
159+ let pos = State::move_next_word_start(doc.text().slice(..), doc.selection().cursor());
160160 range.head = pos;
161161 range
162162 }); // TODO: count
@@ -168,7 +168,7 @@ pub fn extend_prev_word_start(cx: &mut Context) {
168168 let count = cx.count;
169169 let doc = cx.doc();
170170 let mut selection = doc.selection().transform(|mut range| {
171− let pos = State::move_prev_word_start(&doc.text().slice(..), doc.selection().cursor());
171+ let pos = State::move_prev_word_start(doc.text().slice(..), doc.selection().cursor());
172172 range.head = pos;
173173 range
174174 }); // TODO: count
@@ -179,7 +179,7 @@ pub fn extend_next_word_end(cx: &mut Context) {
179179 let count = cx.count;
180180 let doc = cx.doc();
181181 let mut selection = doc.selection().transform(|mut range| {
182− let pos = State::move_next_word_end(&doc.text().slice(..), doc.selection().cursor(), count);
182+ let pos = State::move_next_word_end(doc.text().slice(..), doc.selection().cursor(), count);
183183 range.head = pos;
184184 range
185185 }); // TODO: count
@@ -303,7 +303,7 @@ pub fn select_all(cx: &mut Context) {
303303
304304pub fn select_regex(cx: &mut Context) {
305305 let prompt = ui::regex_prompt(cx, "select:".to_string(), |doc, regex| {
306− let text = &doc.text().slice(..);
306+ let text = doc.text().slice(..);
307307 // TODO: if select on matches returns empty range, we need to abort
308308 let selection =
309309 selection::select_on_matches(text, doc.selection(), &regex).expect("no matches");
@@ -331,7 +331,7 @@ pub fn split_selection(cx: &mut Context) {
331331 // }
332332
333333 let prompt = ui::regex_prompt(cx, "split:".to_string(), |doc, regex| {
334− let text = &doc.text().slice(..);
334+ let text = doc.text().slice(..);
335335 let selection = selection::split_on_matches(text, doc.selection(), &regex);
336336 doc.set_selection(selection);
337337 });
@@ -345,7 +345,7 @@ pub fn split_selection(cx: &mut Context) {
345345
346346pub fn split_selection_on_newline(cx: &mut Context) {
347347 let doc = cx.doc();
348− let text = &doc.text().slice(..);
348+ let text = doc.text().slice(..);
349349 // only compile the regex once
350350 #[allow(clippy::trivial_regex)]
351351 static REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\n").unwrap());
@@ -489,7 +489,7 @@ pub fn append_mode(cx: &mut Context) {
489489 doc.restore_cursor = true;
490490
491491 // TODO: as transaction
492− let text = &doc.text().slice(..);
492+ let text = doc.text().slice(..);
493493 let selection = doc.selection().transform(|range| {
494494 // TODO: to() + next char
495495 Range::new(
@@ -721,7 +721,7 @@ pub fn normal_mode(cx: &mut Context) {
721721
722722 // if leaving append mode, move cursor back by 1
723723 if doc.restore_cursor {
724− let text = &doc.text().slice(..);
724+ let text = doc.text().slice(..);
725725 let selection = doc.selection().transform(|range| {
726726 Range::new(
727727 range.from(),
@@ -775,7 +775,7 @@ pub mod insert {
775775 pub fn delete_char_backward(cx: &mut Context) {
776776 let count = cx.count;
777777 let doc = cx.doc();
778− let text = &doc.text().slice(..);
778+ let text = doc.text().slice(..);
779779 let transaction = Transaction::change_by_selection(&doc.state, |range| {
780780 (
781781 graphemes::nth_prev_grapheme_boundary(text, range.head, count),
@@ -789,7 +789,7 @@ pub mod insert {
789789 pub fn delete_char_forward(cx: &mut Context) {
790790 let count = cx.count;
791791 let doc = cx.doc();
792− let text = &doc.text().slice(..);
792+ let text = doc.text().slice(..);
793793 let transaction = Transaction::change_by_selection(&doc.state, |range| {
794794 (
795795 range.head,
@@ -826,7 +826,7 @@ pub fn yank(cx: &mut Context) {
826826 let values = doc
827827 .state
828828 .selection()
829− .fragments(&doc.text().slice(..))
829+ .fragments(doc.text().slice(..))
830830 .map(|cow| cow.into_owned())
831831 .collect();
832832
@@ -978,7 +978,7 @@ pub fn completion(cx: &mut Context) {
978978 let doc = cx.doc();
979979
980980 // TODO: blocking here is not ideal
981− let pos = helix_lsp::util::pos_to_lsp_pos(&doc.text().slice(..), doc.selection().cursor());
981+ let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor());
982982
983983 // TODO: handle fails
984984 let res =
helix-term/src/ui/editor.rs+4−4
@@ -134,7 +134,7 @@ impl EditorView {
134134 let mut char_index = start;
135135
136136 // iterate over range char by char
137− for grapheme in RopeGraphemes::new(&text) {
137+ for grapheme in RopeGraphemes::new(text) {
138138 // TODO: track current char_index
139139
140140 if grapheme == "\n" {
@@ -211,8 +211,8 @@ impl EditorView {
211211 .filter(|range| range.overlaps(&screen))
212212 {
213213 // TODO: render also if only one of the ranges is in viewport
214− let mut start = view.screen_coords_at_pos(&text, selection.anchor);
215− let mut end = view.screen_coords_at_pos(&text, selection.head);
214+ let mut start = view.screen_coords_at_pos(text, selection.anchor);
215+ let mut end = view.screen_coords_at_pos(text, selection.head);
216216
217217 // cursor
218218 if let Some(end) = end {
@@ -439,7 +439,7 @@ impl Component for EditorView {
439439 let cursor = view.doc.state.selection().cursor();
440440
441441 let mut pos = view
442− .screen_coords_at_pos(&view.doc.text().slice(..), cursor)
442+ .screen_coords_at_pos(view.doc.text().slice(..), cursor)
443443 .expect("Cursor is out of bounds.");
444444 pos.col += view.area.x as usize + area.x as usize + OFFSET as usize;
445445 pos.row += view.area.y as usize + area.y as usize;
helix-view/src/view.rs+3−3
@@ -61,7 +61,7 @@ impl View {
6161 /// Translates a document position to an absolute position in the terminal.
6262 /// Returns a (line, col) position if the position is visible on screen.
6363 // TODO: Could return width as well for the character width at cursor.
64− pub fn screen_coords_at_pos(&self, text: &RopeSlice, pos: usize) -> Option<Position> {
64+ pub fn screen_coords_at_pos(&self, text: RopeSlice, pos: usize) -> Option<Position> {
6565 let line = text.char_to_line(pos);
6666
6767 if line < self.first_line as usize || line > self.last_line() {
@@ -73,7 +73,7 @@ impl View {
7373 let line_slice = text.slice(line_start..pos);
7474 let mut col = 0;
7575
76− for grapheme in RopeGraphemes::new(&line_slice) {
76+ for grapheme in RopeGraphemes::new(line_slice) {
7777 if grapheme == "\t" {
7878 col += TAB_WIDTH;
7979 } else {
@@ -87,7 +87,7 @@ impl View {
8787 Some(Position::new(row, col))
8888 }
8989
90− // pub fn traverse<F>(&self, text: &RopeSlice, start: usize, end: usize, fun: F)
90+ // pub fn traverse<F>(&self, text: RopeSlice, start: usize, end: usize, fun: F)
9191 // where
9292 // F: Fn(usize, usize),
9393 // {