diff options
Diffstat (limited to 'crates/ra_ide_api/src/goto_definition.rs')
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 6c8387f6c..821796e5f 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -1,6 +1,7 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use ra_db::{FileId, SourceDatabase}; | 3 | use hir::Source; |
4 | use ra_db::SourceDatabase; | ||
4 | use ra_syntax::{ | 5 | use ra_syntax::{ |
5 | algo::find_node_at_offset, | 6 | algo::find_node_at_offset, |
6 | ast::{self, DocCommentsOwner}, | 7 | ast::{self, DocCommentsOwner}, |
@@ -21,11 +22,12 @@ pub(crate) fn goto_definition( | |||
21 | let parse = db.parse(position.file_id); | 22 | let parse = db.parse(position.file_id); |
22 | let syntax = parse.tree().syntax().clone(); | 23 | let syntax = parse.tree().syntax().clone(); |
23 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(&syntax, position.offset) { | 24 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(&syntax, position.offset) { |
24 | let navs = reference_definition(db, position.file_id, &name_ref).to_vec(); | 25 | let navs = |
26 | reference_definition(db, Source::new(position.file_id.into(), &name_ref)).to_vec(); | ||
25 | return Some(RangeInfo::new(name_ref.syntax().text_range(), navs.to_vec())); | 27 | return Some(RangeInfo::new(name_ref.syntax().text_range(), navs.to_vec())); |
26 | } | 28 | } |
27 | if let Some(name) = find_node_at_offset::<ast::Name>(&syntax, position.offset) { | 29 | if let Some(name) = find_node_at_offset::<ast::Name>(&syntax, position.offset) { |
28 | let navs = name_definition(db, position.file_id, &name)?; | 30 | let navs = name_definition(db, Source::new(position.file_id.into(), &name))?; |
29 | return Some(RangeInfo::new(name.syntax().text_range(), navs)); | 31 | return Some(RangeInfo::new(name.syntax().text_range(), navs)); |
30 | } | 32 | } |
31 | None | 33 | None |
@@ -49,12 +51,11 @@ impl ReferenceResult { | |||
49 | 51 | ||
50 | pub(crate) fn reference_definition( | 52 | pub(crate) fn reference_definition( |
51 | db: &RootDatabase, | 53 | db: &RootDatabase, |
52 | file_id: FileId, | 54 | name_ref: Source<&ast::NameRef>, |
53 | name_ref: &ast::NameRef, | ||
54 | ) -> ReferenceResult { | 55 | ) -> ReferenceResult { |
55 | use self::ReferenceResult::*; | 56 | use self::ReferenceResult::*; |
56 | 57 | ||
57 | let name_kind = classify_name_ref(db, file_id, &name_ref).map(|d| d.kind); | 58 | let name_kind = classify_name_ref(db, name_ref).map(|d| d.kind); |
58 | match name_kind { | 59 | match name_kind { |
59 | Some(Macro(mac)) => return Exact(mac.to_nav(db)), | 60 | Some(Macro(mac)) => return Exact(mac.to_nav(db)), |
60 | Some(Field(field)) => return Exact(field.to_nav(db)), | 61 | Some(Field(field)) => return Exact(field.to_nav(db)), |
@@ -76,7 +77,7 @@ pub(crate) fn reference_definition( | |||
76 | }; | 77 | }; |
77 | 78 | ||
78 | // Fallback index based approach: | 79 | // Fallback index based approach: |
79 | let navs = crate::symbol_index::index_resolve(db, name_ref) | 80 | let navs = crate::symbol_index::index_resolve(db, name_ref.ast) |
80 | .into_iter() | 81 | .into_iter() |
81 | .map(|s| s.to_nav(db)) | 82 | .map(|s| s.to_nav(db)) |
82 | .collect(); | 83 | .collect(); |
@@ -85,14 +86,13 @@ pub(crate) fn reference_definition( | |||
85 | 86 | ||
86 | pub(crate) fn name_definition( | 87 | pub(crate) fn name_definition( |
87 | db: &RootDatabase, | 88 | db: &RootDatabase, |
88 | file_id: FileId, | 89 | name: Source<&ast::Name>, |
89 | name: &ast::Name, | ||
90 | ) -> Option<Vec<NavigationTarget>> { | 90 | ) -> Option<Vec<NavigationTarget>> { |
91 | let parent = name.syntax().parent()?; | 91 | let parent = name.ast.syntax().parent()?; |
92 | 92 | ||
93 | if let Some(module) = ast::Module::cast(parent.clone()) { | 93 | if let Some(module) = ast::Module::cast(parent.clone()) { |
94 | if module.has_semi() { | 94 | if module.has_semi() { |
95 | let src = hir::Source { file_id: file_id.into(), ast: module }; | 95 | let src = name.with_ast(module); |
96 | if let Some(child_module) = hir::Module::from_declaration(db, src) { | 96 | if let Some(child_module) = hir::Module::from_declaration(db, src) { |
97 | let nav = child_module.to_nav(db); | 97 | let nav = child_module.to_nav(db); |
98 | return Some(vec![nav]); | 98 | return Some(vec![nav]); |
@@ -100,20 +100,20 @@ pub(crate) fn name_definition( | |||
100 | } | 100 | } |
101 | } | 101 | } |
102 | 102 | ||
103 | if let Some(nav) = named_target(db, file_id, &parent) { | 103 | if let Some(nav) = named_target(db, name.with_ast(&parent)) { |
104 | return Some(vec![nav]); | 104 | return Some(vec![nav]); |
105 | } | 105 | } |
106 | 106 | ||
107 | None | 107 | None |
108 | } | 108 | } |
109 | 109 | ||
110 | fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option<NavigationTarget> { | 110 | fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<NavigationTarget> { |
111 | match_ast! { | 111 | match_ast! { |
112 | match node { | 112 | match (node.ast) { |
113 | ast::StructDef(it) => { | 113 | ast::StructDef(it) => { |
114 | Some(NavigationTarget::from_named( | 114 | Some(NavigationTarget::from_named( |
115 | db, | 115 | db, |
116 | file_id.into(), | 116 | node.file_id, |
117 | &it, | 117 | &it, |
118 | it.doc_comment_text(), | 118 | it.doc_comment_text(), |
119 | it.short_label(), | 119 | it.short_label(), |
@@ -122,7 +122,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option | |||
122 | ast::EnumDef(it) => { | 122 | ast::EnumDef(it) => { |
123 | Some(NavigationTarget::from_named( | 123 | Some(NavigationTarget::from_named( |
124 | db, | 124 | db, |
125 | file_id.into(), | 125 | node.file_id, |
126 | &it, | 126 | &it, |
127 | it.doc_comment_text(), | 127 | it.doc_comment_text(), |
128 | it.short_label(), | 128 | it.short_label(), |
@@ -131,7 +131,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option | |||
131 | ast::EnumVariant(it) => { | 131 | ast::EnumVariant(it) => { |
132 | Some(NavigationTarget::from_named( | 132 | Some(NavigationTarget::from_named( |
133 | db, | 133 | db, |
134 | file_id.into(), | 134 | node.file_id, |
135 | &it, | 135 | &it, |
136 | it.doc_comment_text(), | 136 | it.doc_comment_text(), |
137 | it.short_label(), | 137 | it.short_label(), |
@@ -140,7 +140,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option | |||
140 | ast::FnDef(it) => { | 140 | ast::FnDef(it) => { |
141 | Some(NavigationTarget::from_named( | 141 | Some(NavigationTarget::from_named( |
142 | db, | 142 | db, |
143 | file_id.into(), | 143 | node.file_id, |
144 | &it, | 144 | &it, |
145 | it.doc_comment_text(), | 145 | it.doc_comment_text(), |
146 | it.short_label(), | 146 | it.short_label(), |
@@ -149,7 +149,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option | |||
149 | ast::TypeAliasDef(it) => { | 149 | ast::TypeAliasDef(it) => { |
150 | Some(NavigationTarget::from_named( | 150 | Some(NavigationTarget::from_named( |
151 | db, | 151 | db, |
152 | file_id.into(), | 152 | node.file_id, |
153 | &it, | 153 | &it, |
154 | it.doc_comment_text(), | 154 | it.doc_comment_text(), |
155 | it.short_label(), | 155 | it.short_label(), |
@@ -158,7 +158,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option | |||
158 | ast::ConstDef(it) => { | 158 | ast::ConstDef(it) => { |
159 | Some(NavigationTarget::from_named( | 159 | Some(NavigationTarget::from_named( |
160 | db, | 160 | db, |
161 | file_id.into(), | 161 | node.file_id, |
162 | &it, | 162 | &it, |
163 | it.doc_comment_text(), | 163 | it.doc_comment_text(), |
164 | it.short_label(), | 164 | it.short_label(), |
@@ -167,7 +167,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option | |||
167 | ast::StaticDef(it) => { | 167 | ast::StaticDef(it) => { |
168 | Some(NavigationTarget::from_named( | 168 | Some(NavigationTarget::from_named( |
169 | db, | 169 | db, |
170 | file_id.into(), | 170 | node.file_id, |
171 | &it, | 171 | &it, |
172 | it.doc_comment_text(), | 172 | it.doc_comment_text(), |
173 | it.short_label(), | 173 | it.short_label(), |
@@ -176,7 +176,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option | |||
176 | ast::TraitDef(it) => { | 176 | ast::TraitDef(it) => { |
177 | Some(NavigationTarget::from_named( | 177 | Some(NavigationTarget::from_named( |
178 | db, | 178 | db, |
179 | file_id.into(), | 179 | node.file_id, |
180 | &it, | 180 | &it, |
181 | it.doc_comment_text(), | 181 | it.doc_comment_text(), |
182 | it.short_label(), | 182 | it.short_label(), |
@@ -185,7 +185,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option | |||
185 | ast::RecordFieldDef(it) => { | 185 | ast::RecordFieldDef(it) => { |
186 | Some(NavigationTarget::from_named( | 186 | Some(NavigationTarget::from_named( |
187 | db, | 187 | db, |
188 | file_id.into(), | 188 | node.file_id, |
189 | &it, | 189 | &it, |
190 | it.doc_comment_text(), | 190 | it.doc_comment_text(), |
191 | it.short_label(), | 191 | it.short_label(), |
@@ -194,7 +194,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option | |||
194 | ast::Module(it) => { | 194 | ast::Module(it) => { |
195 | Some(NavigationTarget::from_named( | 195 | Some(NavigationTarget::from_named( |
196 | db, | 196 | db, |
197 | file_id.into(), | 197 | node.file_id, |
198 | &it, | 198 | &it, |
199 | it.doc_comment_text(), | 199 | it.doc_comment_text(), |
200 | it.short_label(), | 200 | it.short_label(), |
@@ -203,7 +203,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option | |||
203 | ast::MacroCall(it) => { | 203 | ast::MacroCall(it) => { |
204 | Some(NavigationTarget::from_named( | 204 | Some(NavigationTarget::from_named( |
205 | db, | 205 | db, |
206 | file_id.into(), | 206 | node.file_id, |
207 | &it, | 207 | &it, |
208 | it.doc_comment_text(), | 208 | it.doc_comment_text(), |
209 | None, | 209 | None, |