aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs39
1 files changed, 19 insertions, 20 deletions
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index 5b7fb3c15..821796e5f 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -1,7 +1,7 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::Source; 3use hir::Source;
4use ra_db::{FileId, SourceDatabase}; 4use ra_db::SourceDatabase;
5use ra_syntax::{ 5use ra_syntax::{
6 algo::find_node_at_offset, 6 algo::find_node_at_offset,
7 ast::{self, DocCommentsOwner}, 7 ast::{self, DocCommentsOwner},
@@ -27,7 +27,7 @@ pub(crate) fn goto_definition(
27 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()));
28 } 28 }
29 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) {
30 let navs = name_definition(db, position.file_id, &name)?; 30 let navs = name_definition(db, Source::new(position.file_id.into(), &name))?;
31 return Some(RangeInfo::new(name.syntax().text_range(), navs)); 31 return Some(RangeInfo::new(name.syntax().text_range(), navs));
32 } 32 }
33 None 33 None
@@ -86,14 +86,13 @@ pub(crate) fn reference_definition(
86 86
87pub(crate) fn name_definition( 87pub(crate) fn name_definition(
88 db: &RootDatabase, 88 db: &RootDatabase,
89 file_id: FileId, 89 name: Source<&ast::Name>,
90 name: &ast::Name,
91) -> Option<Vec<NavigationTarget>> { 90) -> Option<Vec<NavigationTarget>> {
92 let parent = name.syntax().parent()?; 91 let parent = name.ast.syntax().parent()?;
93 92
94 if let Some(module) = ast::Module::cast(parent.clone()) { 93 if let Some(module) = ast::Module::cast(parent.clone()) {
95 if module.has_semi() { 94 if module.has_semi() {
96 let src = hir::Source { file_id: file_id.into(), ast: module }; 95 let src = name.with_ast(module);
97 if let Some(child_module) = hir::Module::from_declaration(db, src) { 96 if let Some(child_module) = hir::Module::from_declaration(db, src) {
98 let nav = child_module.to_nav(db); 97 let nav = child_module.to_nav(db);
99 return Some(vec![nav]); 98 return Some(vec![nav]);
@@ -101,20 +100,20 @@ pub(crate) fn name_definition(
101 } 100 }
102 } 101 }
103 102
104 if let Some(nav) = named_target(db, file_id, &parent) { 103 if let Some(nav) = named_target(db, name.with_ast(&parent)) {
105 return Some(vec![nav]); 104 return Some(vec![nav]);
106 } 105 }
107 106
108 None 107 None
109} 108}
110 109
111fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option<NavigationTarget> { 110fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<NavigationTarget> {
112 match_ast! { 111 match_ast! {
113 match node { 112 match (node.ast) {
114 ast::StructDef(it) => { 113 ast::StructDef(it) => {
115 Some(NavigationTarget::from_named( 114 Some(NavigationTarget::from_named(
116 db, 115 db,
117 file_id.into(), 116 node.file_id,
118 &it, 117 &it,
119 it.doc_comment_text(), 118 it.doc_comment_text(),
120 it.short_label(), 119 it.short_label(),
@@ -123,7 +122,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option
123 ast::EnumDef(it) => { 122 ast::EnumDef(it) => {
124 Some(NavigationTarget::from_named( 123 Some(NavigationTarget::from_named(
125 db, 124 db,
126 file_id.into(), 125 node.file_id,
127 &it, 126 &it,
128 it.doc_comment_text(), 127 it.doc_comment_text(),
129 it.short_label(), 128 it.short_label(),
@@ -132,7 +131,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option
132 ast::EnumVariant(it) => { 131 ast::EnumVariant(it) => {
133 Some(NavigationTarget::from_named( 132 Some(NavigationTarget::from_named(
134 db, 133 db,
135 file_id.into(), 134 node.file_id,
136 &it, 135 &it,
137 it.doc_comment_text(), 136 it.doc_comment_text(),
138 it.short_label(), 137 it.short_label(),
@@ -141,7 +140,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option
141 ast::FnDef(it) => { 140 ast::FnDef(it) => {
142 Some(NavigationTarget::from_named( 141 Some(NavigationTarget::from_named(
143 db, 142 db,
144 file_id.into(), 143 node.file_id,
145 &it, 144 &it,
146 it.doc_comment_text(), 145 it.doc_comment_text(),
147 it.short_label(), 146 it.short_label(),
@@ -150,7 +149,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option
150 ast::TypeAliasDef(it) => { 149 ast::TypeAliasDef(it) => {
151 Some(NavigationTarget::from_named( 150 Some(NavigationTarget::from_named(
152 db, 151 db,
153 file_id.into(), 152 node.file_id,
154 &it, 153 &it,
155 it.doc_comment_text(), 154 it.doc_comment_text(),
156 it.short_label(), 155 it.short_label(),
@@ -159,7 +158,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option
159 ast::ConstDef(it) => { 158 ast::ConstDef(it) => {
160 Some(NavigationTarget::from_named( 159 Some(NavigationTarget::from_named(
161 db, 160 db,
162 file_id.into(), 161 node.file_id,
163 &it, 162 &it,
164 it.doc_comment_text(), 163 it.doc_comment_text(),
165 it.short_label(), 164 it.short_label(),
@@ -168,7 +167,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option
168 ast::StaticDef(it) => { 167 ast::StaticDef(it) => {
169 Some(NavigationTarget::from_named( 168 Some(NavigationTarget::from_named(
170 db, 169 db,
171 file_id.into(), 170 node.file_id,
172 &it, 171 &it,
173 it.doc_comment_text(), 172 it.doc_comment_text(),
174 it.short_label(), 173 it.short_label(),
@@ -177,7 +176,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option
177 ast::TraitDef(it) => { 176 ast::TraitDef(it) => {
178 Some(NavigationTarget::from_named( 177 Some(NavigationTarget::from_named(
179 db, 178 db,
180 file_id.into(), 179 node.file_id,
181 &it, 180 &it,
182 it.doc_comment_text(), 181 it.doc_comment_text(),
183 it.short_label(), 182 it.short_label(),
@@ -186,7 +185,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option
186 ast::RecordFieldDef(it) => { 185 ast::RecordFieldDef(it) => {
187 Some(NavigationTarget::from_named( 186 Some(NavigationTarget::from_named(
188 db, 187 db,
189 file_id.into(), 188 node.file_id,
190 &it, 189 &it,
191 it.doc_comment_text(), 190 it.doc_comment_text(),
192 it.short_label(), 191 it.short_label(),
@@ -195,7 +194,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option
195 ast::Module(it) => { 194 ast::Module(it) => {
196 Some(NavigationTarget::from_named( 195 Some(NavigationTarget::from_named(
197 db, 196 db,
198 file_id.into(), 197 node.file_id,
199 &it, 198 &it,
200 it.doc_comment_text(), 199 it.doc_comment_text(),
201 it.short_label(), 200 it.short_label(),
@@ -204,7 +203,7 @@ fn named_target(db: &RootDatabase, file_id: FileId, node: &SyntaxNode) -> Option
204 ast::MacroCall(it) => { 203 ast::MacroCall(it) => {
205 Some(NavigationTarget::from_named( 204 Some(NavigationTarget::from_named(
206 db, 205 db,
207 file_id.into(), 206 node.file_id,
208 &it, 207 &it,
209 it.doc_comment_text(), 208 it.doc_comment_text(),
210 None, 209 None,