aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_db/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_db/src')
-rw-r--r--crates/ra_ide_db/src/line_index.rs22
-rw-r--r--crates/ra_ide_db/src/line_index_utils.rs11
-rw-r--r--crates/ra_ide_db/src/search.rs4
3 files changed, 20 insertions, 17 deletions
diff --git a/crates/ra_ide_db/src/line_index.rs b/crates/ra_ide_db/src/line_index.rs
index 81eebc711..00ba95913 100644
--- a/crates/ra_ide_db/src/line_index.rs
+++ b/crates/ra_ide_db/src/line_index.rs
@@ -1,8 +1,9 @@
1//! `LineIndex` maps flat `TextSize` offsets into `(Line, Column)` 1//! `LineIndex` maps flat `TextSize` offsets into `(Line, Column)`
2//! representation. 2//! representation.
3use std::iter;
4
3use ra_syntax::{TextRange, TextSize}; 5use ra_syntax::{TextRange, TextSize};
4use rustc_hash::FxHashMap; 6use rustc_hash::FxHashMap;
5use std::iter;
6use superslice::Ext; 7use superslice::Ext;
7 8
8#[derive(Clone, Debug, PartialEq, Eq)] 9#[derive(Clone, Debug, PartialEq, Eq)]
@@ -116,12 +117,11 @@ impl LineIndex {
116 res 117 res
117 } 118 }
118 119
119 fn utf16_to_utf8_col(&self, line: u32, col: u32) -> TextSize { 120 fn utf16_to_utf8_col(&self, line: u32, mut col: u32) -> TextSize {
120 let mut col: TextSize = col.into();
121 if let Some(utf16_chars) = self.utf16_lines.get(&line) { 121 if let Some(utf16_chars) = self.utf16_lines.get(&line) {
122 for c in utf16_chars { 122 for c in utf16_chars {
123 if col >= c.start { 123 if col >= u32::from(c.start) {
124 col += c.len() - TextSize::from_usize(1); 124 col += u32::from(c.len()) - 1;
125 } else { 125 } else {
126 // From here on, all utf16 characters come *after* the character we are mapping, 126 // From here on, all utf16 characters come *after* the character we are mapping,
127 // so we don't need to take them into account 127 // so we don't need to take them into account
@@ -130,12 +130,12 @@ impl LineIndex {
130 } 130 }
131 } 131 }
132 132
133 col 133 col.into()
134 } 134 }
135} 135}
136 136
137#[cfg(test)] 137#[cfg(test)]
138mod test_line_index { 138mod tests {
139 use super::*; 139 use super::*;
140 140
141 #[test] 141 #[test]
@@ -224,12 +224,12 @@ const C: char = \"メ メ\";
224 assert!(col_index.utf8_to_utf16_col(2, 15.into()) == 15); 224 assert!(col_index.utf8_to_utf16_col(2, 15.into()) == 15);
225 225
226 // UTF-16 to UTF-8 226 // UTF-16 to UTF-8
227 assert_eq!(col_index.utf16_to_utf8_col(1, 15), TextSize::from_usize(15)); 227 assert_eq!(col_index.utf16_to_utf8_col(1, 15), TextSize::from(15));
228 228
229 assert_eq!(col_index.utf16_to_utf8_col(1, 18), TextSize::from_usize(20)); 229 assert_eq!(col_index.utf16_to_utf8_col(1, 18), TextSize::from(20));
230 assert_eq!(col_index.utf16_to_utf8_col(1, 19), TextSize::from_usize(23)); 230 assert_eq!(col_index.utf16_to_utf8_col(1, 19), TextSize::from(23));
231 231
232 assert_eq!(col_index.utf16_to_utf8_col(2, 15), TextSize::from_usize(15)); 232 assert_eq!(col_index.utf16_to_utf8_col(2, 15), TextSize::from(15));
233 } 233 }
234 234
235 #[test] 235 #[test]
diff --git a/crates/ra_ide_db/src/line_index_utils.rs b/crates/ra_ide_db/src/line_index_utils.rs
index f050fe77f..039a12c0d 100644
--- a/crates/ra_ide_db/src/line_index_utils.rs
+++ b/crates/ra_ide_db/src/line_index_utils.rs
@@ -7,6 +7,8 @@
7//! Code in this module applies this "to (Line, Column) after edit" 7//! Code in this module applies this "to (Line, Column) after edit"
8//! transformation. 8//! transformation.
9 9
10use std::convert::TryInto;
11
10use ra_syntax::{TextRange, TextSize}; 12use ra_syntax::{TextRange, TextSize};
11use ra_text_edit::{AtomTextEdit, TextEdit}; 13use ra_text_edit::{AtomTextEdit, TextEdit};
12 14
@@ -139,14 +141,15 @@ impl Iterator for OffsetStepIter<'_> {
139 .text 141 .text
140 .char_indices() 142 .char_indices()
141 .filter_map(|(i, c)| { 143 .filter_map(|(i, c)| {
144 let i: TextSize = i.try_into().unwrap();
145 let char_len = TextSize::of(c);
142 if c == '\n' { 146 if c == '\n' {
143 let next_offset = self.offset + TextSize::from_usize(i + 1); 147 let next_offset = self.offset + i + char_len;
144 let next = Step::Newline(next_offset); 148 let next = Step::Newline(next_offset);
145 Some((next, next_offset)) 149 Some((next, next_offset))
146 } else { 150 } else {
147 let char_len = TextSize::of(c); 151 if !c.is_ascii() {
148 if char_len > TextSize::from_usize(1) { 152 let start = self.offset + i;
149 let start = self.offset + TextSize::from_usize(i);
150 let end = start + char_len; 153 let end = start + char_len;
151 let next = Step::Utf16Char(TextRange::new(start, end)); 154 let next = Step::Utf16Char(TextRange::new(start, end));
152 let next_offset = end; 155 let next_offset = end;
diff --git a/crates/ra_ide_db/src/search.rs b/crates/ra_ide_db/src/search.rs
index 599b8e562..596f957b8 100644
--- a/crates/ra_ide_db/src/search.rs
+++ b/crates/ra_ide_db/src/search.rs
@@ -4,7 +4,7 @@
4//! get a super-set of matches. Then, we we confirm each match using precise 4//! get a super-set of matches. Then, we we confirm each match using precise
5//! name resolution. 5//! name resolution.
6 6
7use std::mem; 7use std::{convert::TryInto, mem};
8 8
9use hir::{DefWithBody, HasSource, Module, ModuleSource, Semantics, Visibility}; 9use hir::{DefWithBody, HasSource, Module, ModuleSource, Semantics, Visibility};
10use once_cell::unsync::Lazy; 10use once_cell::unsync::Lazy;
@@ -207,7 +207,7 @@ impl Definition {
207 let tree = Lazy::new(|| sema.parse(file_id).syntax().clone()); 207 let tree = Lazy::new(|| sema.parse(file_id).syntax().clone());
208 208
209 for (idx, _) in text.match_indices(pat) { 209 for (idx, _) in text.match_indices(pat) {
210 let offset = TextSize::from_usize(idx); 210 let offset: TextSize = idx.try_into().unwrap();
211 if !search_range.contains_inclusive(offset) { 211 if !search_range.contains_inclusive(offset) {
212 tested_by!(search_filters_by_range; force); 212 tested_by!(search_filters_by_range; force);
213 continue; 213 continue;