diff options
Diffstat (limited to 'crates/ra_ide_db')
-rw-r--r-- | crates/ra_ide_db/src/defs.rs | 10 | ||||
-rw-r--r-- | crates/ra_ide_db/src/line_index.rs | 12 | ||||
-rw-r--r-- | crates/ra_ide_db/src/marks.rs | 1 |
3 files changed, 20 insertions, 3 deletions
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index 7cd2384e9..40d0e77b5 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs | |||
@@ -119,6 +119,16 @@ fn classify_name_inner(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Opti | |||
119 | 119 | ||
120 | match_ast! { | 120 | match_ast! { |
121 | match parent { | 121 | match parent { |
122 | ast::Alias(it) => { | ||
123 | tested_by!(goto_def_for_use_alias; force); | ||
124 | let use_tree = it.syntax().parent().and_then(ast::UseTree::cast)?; | ||
125 | let path = use_tree.path()?; | ||
126 | let path_segment = path.segment()?; | ||
127 | let name_ref = path_segment.name_ref()?; | ||
128 | let name_ref_class = classify_name_ref(sema, &name_ref)?; | ||
129 | |||
130 | Some(name_ref_class.definition()) | ||
131 | }, | ||
122 | ast::BindPat(it) => { | 132 | ast::BindPat(it) => { |
123 | let local = sema.to_def(&it)?; | 133 | let local = sema.to_def(&it)?; |
124 | Some(Definition::Local(local)) | 134 | Some(Definition::Local(local)) |
diff --git a/crates/ra_ide_db/src/line_index.rs b/crates/ra_ide_db/src/line_index.rs index 00ba95913..212cb7b5b 100644 --- a/crates/ra_ide_db/src/line_index.rs +++ b/crates/ra_ide_db/src/line_index.rs | |||
@@ -8,7 +8,9 @@ use superslice::Ext; | |||
8 | 8 | ||
9 | #[derive(Clone, Debug, PartialEq, Eq)] | 9 | #[derive(Clone, Debug, PartialEq, Eq)] |
10 | pub struct LineIndex { | 10 | pub struct LineIndex { |
11 | /// Offset the the beginning of each line, zero-based | ||
11 | pub(crate) newlines: Vec<TextSize>, | 12 | pub(crate) newlines: Vec<TextSize>, |
13 | /// List of non-ASCII characters on each line | ||
12 | pub(crate) utf16_lines: FxHashMap<u32, Vec<Utf16Char>>, | 14 | pub(crate) utf16_lines: FxHashMap<u32, Vec<Utf16Char>>, |
13 | } | 15 | } |
14 | 16 | ||
@@ -22,7 +24,9 @@ pub struct LineCol { | |||
22 | 24 | ||
23 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] | 25 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] |
24 | pub(crate) struct Utf16Char { | 26 | pub(crate) struct Utf16Char { |
27 | /// Start offset of a character inside a line, zero-based | ||
25 | pub(crate) start: TextSize, | 28 | pub(crate) start: TextSize, |
29 | /// End offset of a character inside a line, zero-based | ||
26 | pub(crate) end: TextSize, | 30 | pub(crate) end: TextSize, |
27 | } | 31 | } |
28 | 32 | ||
@@ -120,7 +124,7 @@ impl LineIndex { | |||
120 | fn utf16_to_utf8_col(&self, line: u32, mut col: u32) -> TextSize { | 124 | fn utf16_to_utf8_col(&self, line: u32, mut col: u32) -> TextSize { |
121 | if let Some(utf16_chars) = self.utf16_lines.get(&line) { | 125 | if let Some(utf16_chars) = self.utf16_lines.get(&line) { |
122 | for c in utf16_chars { | 126 | for c in utf16_chars { |
123 | if col >= u32::from(c.start) { | 127 | if col > u32::from(c.start) { |
124 | col += u32::from(c.len()) - 1; | 128 | col += u32::from(c.len()) - 1; |
125 | } else { | 129 | } else { |
126 | // From here on, all utf16 characters come *after* the character we are mapping, | 130 | // From here on, all utf16 characters come *after* the character we are mapping, |
@@ -226,8 +230,10 @@ const C: char = \"メ メ\"; | |||
226 | // UTF-16 to UTF-8 | 230 | // UTF-16 to UTF-8 |
227 | assert_eq!(col_index.utf16_to_utf8_col(1, 15), TextSize::from(15)); | 231 | assert_eq!(col_index.utf16_to_utf8_col(1, 15), TextSize::from(15)); |
228 | 232 | ||
229 | assert_eq!(col_index.utf16_to_utf8_col(1, 18), TextSize::from(20)); | 233 | // メ UTF-8: 0xE3 0x83 0xA1, UTF-16: 0x30E1 |
230 | assert_eq!(col_index.utf16_to_utf8_col(1, 19), TextSize::from(23)); | 234 | assert_eq!(col_index.utf16_to_utf8_col(1, 17), TextSize::from(17)); // first メ at 17..20 |
235 | assert_eq!(col_index.utf16_to_utf8_col(1, 18), TextSize::from(20)); // space | ||
236 | assert_eq!(col_index.utf16_to_utf8_col(1, 19), TextSize::from(21)); // second メ at 21..24 | ||
231 | 237 | ||
232 | assert_eq!(col_index.utf16_to_utf8_col(2, 15), TextSize::from(15)); | 238 | assert_eq!(col_index.utf16_to_utf8_col(2, 15), TextSize::from(15)); |
233 | } | 239 | } |
diff --git a/crates/ra_ide_db/src/marks.rs b/crates/ra_ide_db/src/marks.rs index 03b4be21c..386fe605c 100644 --- a/crates/ra_ide_db/src/marks.rs +++ b/crates/ra_ide_db/src/marks.rs | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | test_utils::marks![ | 3 | test_utils::marks![ |
4 | goto_def_for_macros | 4 | goto_def_for_macros |
5 | goto_def_for_use_alias | ||
5 | goto_def_for_methods | 6 | goto_def_for_methods |
6 | goto_def_for_fields | 7 | goto_def_for_fields |
7 | goto_def_for_record_fields | 8 | goto_def_for_record_fields |