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.rs24
-rw-r--r--crates/ra_ide_db/src/search.rs3
2 files changed, 12 insertions, 15 deletions
diff --git a/crates/ra_ide_db/src/line_index.rs b/crates/ra_ide_db/src/line_index.rs
index 7794dc9fd..81eebc711 100644
--- a/crates/ra_ide_db/src/line_index.rs
+++ b/crates/ra_ide_db/src/line_index.rs
@@ -1,9 +1,8 @@
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// TODO: un TextSize
5use ra_syntax::{TextRange, TextSize}; 3use ra_syntax::{TextRange, TextSize};
6use rustc_hash::FxHashMap; 4use rustc_hash::FxHashMap;
5use std::iter;
7use superslice::Ext; 6use superslice::Ext;
8 7
9#[derive(Clone, Debug, PartialEq, Eq)] 8#[derive(Clone, Debug, PartialEq, Eq)]
@@ -42,7 +41,8 @@ impl LineIndex {
42 let mut curr_col = 0.into(); 41 let mut curr_col = 0.into();
43 let mut line = 0; 42 let mut line = 0;
44 for c in text.chars() { 43 for c in text.chars() {
45 curr_row += TextSize::of(c); 44 let c_len = TextSize::of(c);
45 curr_row += c_len;
46 if c == '\n' { 46 if c == '\n' {
47 newlines.push(curr_row); 47 newlines.push(curr_row);
48 48
@@ -58,12 +58,11 @@ impl LineIndex {
58 continue; 58 continue;
59 } 59 }
60 60
61 let char_len = TextSize::of(c); 61 if !c.is_ascii() {
62 if char_len > TextSize::from_usize(1) { 62 utf16_chars.push(Utf16Char { start: curr_col, end: curr_col + c_len });
63 utf16_chars.push(Utf16Char { start: curr_col, end: curr_col + char_len });
64 } 63 }
65 64
66 curr_col += char_len; 65 curr_col += c_len;
67 } 66 }
68 67
69 // Save any utf-16 characters seen in the last line 68 // Save any utf-16 characters seen in the last line
@@ -102,22 +101,19 @@ impl LineIndex {
102 } 101 }
103 102
104 fn utf8_to_utf16_col(&self, line: u32, col: TextSize) -> usize { 103 fn utf8_to_utf16_col(&self, line: u32, col: TextSize) -> usize {
104 let mut res: usize = col.into();
105 if let Some(utf16_chars) = self.utf16_lines.get(&line) { 105 if let Some(utf16_chars) = self.utf16_lines.get(&line) {
106 let mut correction = 0;
107 for c in utf16_chars { 106 for c in utf16_chars {
108 if col >= c.end { 107 if c.end <= col {
109 correction += usize::from(c.len()) - 1; 108 res -= usize::from(c.len()) - 1;
110 } else { 109 } else {
111 // From here on, all utf16 characters come *after* the character we are mapping, 110 // From here on, all utf16 characters come *after* the character we are mapping,
112 // so we don't need to take them into account 111 // so we don't need to take them into account
113 break; 112 break;
114 } 113 }
115 } 114 }
116
117 usize::from(col) - correction
118 } else {
119 usize::from(col)
120 } 115 }
116 res
121 } 117 }
122 118
123 fn utf16_to_utf8_col(&self, line: u32, col: u32) -> TextSize { 119 fn utf16_to_utf8_col(&self, line: u32, col: u32) -> TextSize {
diff --git a/crates/ra_ide_db/src/search.rs b/crates/ra_ide_db/src/search.rs
index c66de4f42..599b8e562 100644
--- a/crates/ra_ide_db/src/search.rs
+++ b/crates/ra_ide_db/src/search.rs
@@ -200,7 +200,8 @@ impl Definition {
200 200
201 for (file_id, search_range) in search_scope { 201 for (file_id, search_range) in search_scope {
202 let text = db.file_text(file_id); 202 let text = db.file_text(file_id);
203 let search_range = search_range.unwrap_or(TextRange::up_to(TextSize::of(&text))); 203 let search_range =
204 search_range.unwrap_or(TextRange::up_to(TextSize::of(text.as_str())));
204 205
205 let sema = Semantics::new(db); 206 let sema = Semantics::new(db);
206 let tree = Lazy::new(|| sema.parse(file_id).syntax().clone()); 207 let tree = Lazy::new(|| sema.parse(file_id).syntax().clone());