diff options
Diffstat (limited to 'crates/ra_ide_db/src/line_index.rs')
-rw-r--r-- | crates/ra_ide_db/src/line_index.rs | 22 |
1 files changed, 11 insertions, 11 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. |
3 | use std::iter; | ||
4 | |||
3 | use ra_syntax::{TextRange, TextSize}; | 5 | use ra_syntax::{TextRange, TextSize}; |
4 | use rustc_hash::FxHashMap; | 6 | use rustc_hash::FxHashMap; |
5 | use std::iter; | ||
6 | use superslice::Ext; | 7 | use 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)] |
138 | mod test_line_index { | 138 | mod 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] |