diff options
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/display/navigation_target.rs | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index f7ad08515..4703cfaf7 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir::{AssocItem, Either, FieldSource, HasSource, ModuleSource}; | 3 | use hir::{AssocItem, Either, FieldSource, HasSource, ModuleSource, Source}; |
4 | use ra_db::{FileId, SourceDatabase}; | 4 | use ra_db::{FileId, SourceDatabase}; |
5 | use ra_syntax::{ | 5 | use ra_syntax::{ |
6 | ast::{self, DocCommentsOwner, NameOwner}, | 6 | ast::{self, DocCommentsOwner, NameOwner}, |
@@ -79,7 +79,8 @@ impl NavigationTarget { | |||
79 | pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget { | 79 | pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget { |
80 | let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default(); | 80 | let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default(); |
81 | if let Some(src) = module.declaration_source(db) { | 81 | if let Some(src) = module.declaration_source(db) { |
82 | let (file_id, text_range) = find_range_from_node(db, src.file_id, src.ast.syntax()); | 82 | let (file_id, text_range) = |
83 | find_range_from_node(db, src.as_ref().map(|it| it.syntax())); | ||
83 | return NavigationTarget::from_syntax( | 84 | return NavigationTarget::from_syntax( |
84 | file_id, | 85 | file_id, |
85 | name, | 86 | name, |
@@ -147,8 +148,9 @@ impl NavigationTarget { | |||
147 | ) -> NavigationTarget { | 148 | ) -> NavigationTarget { |
148 | //FIXME: use `_` instead of empty string | 149 | //FIXME: use `_` instead of empty string |
149 | let name = node.name().map(|it| it.text().clone()).unwrap_or_default(); | 150 | let name = node.name().map(|it| it.text().clone()).unwrap_or_default(); |
150 | let focus_range = node.name().map(|it| find_range_from_node(db, file_id, it.syntax()).1); | 151 | let focus_range = |
151 | let (file_id, full_range) = find_range_from_node(db, file_id, node.syntax()); | 152 | node.name().map(|it| find_range_from_node(db, Source::new(file_id, it.syntax())).1); |
153 | let (file_id, full_range) = find_range_from_node(db, Source::new(file_id, node.syntax())); | ||
152 | 154 | ||
153 | NavigationTarget::from_syntax( | 155 | NavigationTarget::from_syntax( |
154 | file_id, | 156 | file_id, |
@@ -230,9 +232,9 @@ impl ToNav for hir::Module { | |||
230 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 232 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
231 | let src = self.definition_source(db); | 233 | let src = self.definition_source(db); |
232 | let name = self.name(db).map(|it| it.to_string().into()).unwrap_or_default(); | 234 | let name = self.name(db).map(|it| it.to_string().into()).unwrap_or_default(); |
233 | match src.ast { | 235 | match &src.ast { |
234 | ModuleSource::SourceFile(node) => { | 236 | ModuleSource::SourceFile(node) => { |
235 | let (file_id, text_range) = find_range_from_node(db, src.file_id, node.syntax()); | 237 | let (file_id, text_range) = find_range_from_node(db, src.with_ast(node.syntax())); |
236 | 238 | ||
237 | NavigationTarget::from_syntax( | 239 | NavigationTarget::from_syntax( |
238 | file_id, | 240 | file_id, |
@@ -245,7 +247,7 @@ impl ToNav for hir::Module { | |||
245 | ) | 247 | ) |
246 | } | 248 | } |
247 | ModuleSource::Module(node) => { | 249 | ModuleSource::Module(node) => { |
248 | let (file_id, text_range) = find_range_from_node(db, src.file_id, node.syntax()); | 250 | let (file_id, text_range) = find_range_from_node(db, src.with_ast(node.syntax())); |
249 | 251 | ||
250 | NavigationTarget::from_syntax( | 252 | NavigationTarget::from_syntax( |
251 | file_id, | 253 | file_id, |
@@ -264,7 +266,7 @@ impl ToNav for hir::Module { | |||
264 | impl ToNav for hir::ImplBlock { | 266 | impl ToNav for hir::ImplBlock { |
265 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 267 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
266 | let src = self.source(db); | 268 | let src = self.source(db); |
267 | let (file_id, text_range) = find_range_from_node(db, src.file_id, src.ast.syntax()); | 269 | let (file_id, text_range) = find_range_from_node(db, src.as_ref().map(|it| it.syntax())); |
268 | 270 | ||
269 | NavigationTarget::from_syntax( | 271 | NavigationTarget::from_syntax( |
270 | file_id, | 272 | file_id, |
@@ -282,16 +284,16 @@ impl ToNav for hir::StructField { | |||
282 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 284 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
283 | let src = self.source(db); | 285 | let src = self.source(db); |
284 | 286 | ||
285 | match src.ast { | 287 | match &src.ast { |
286 | FieldSource::Named(it) => NavigationTarget::from_named( | 288 | FieldSource::Named(it) => NavigationTarget::from_named( |
287 | db, | 289 | db, |
288 | src.file_id, | 290 | src.file_id, |
289 | &it, | 291 | it, |
290 | it.doc_comment_text(), | 292 | it.doc_comment_text(), |
291 | it.short_label(), | 293 | it.short_label(), |
292 | ), | 294 | ), |
293 | FieldSource::Pos(it) => { | 295 | FieldSource::Pos(it) => { |
294 | let (file_id, text_range) = find_range_from_node(db, src.file_id, it.syntax()); | 296 | let (file_id, text_range) = find_range_from_node(db, src.with_ast(it.syntax())); |
295 | NavigationTarget::from_syntax( | 297 | NavigationTarget::from_syntax( |
296 | file_id, | 298 | file_id, |
297 | "".into(), | 299 | "".into(), |
@@ -360,16 +362,13 @@ impl ToNav for hir::Local { | |||
360 | } | 362 | } |
361 | } | 363 | } |
362 | 364 | ||
363 | fn find_range_from_node( | 365 | fn find_range_from_node(db: &RootDatabase, node: Source<&SyntaxNode>) -> (FileId, TextRange) { |
364 | db: &RootDatabase, | 366 | let text_range = node.ast.text_range(); |
365 | src: hir::HirFileId, | 367 | let (file_id, text_range) = node |
366 | node: &SyntaxNode, | 368 | .file_id |
367 | ) -> (FileId, TextRange) { | ||
368 | let text_range = node.text_range(); | ||
369 | let (file_id, text_range) = src | ||
370 | .expansion_info(db) | 369 | .expansion_info(db) |
371 | .and_then(|expansion_info| expansion_info.find_range(text_range)) | 370 | .and_then(|expansion_info| expansion_info.find_range(text_range)) |
372 | .unwrap_or((src, text_range)); | 371 | .unwrap_or((node.file_id, text_range)); |
373 | 372 | ||
374 | // FIXME: handle recursive macro generated macro | 373 | // FIXME: handle recursive macro generated macro |
375 | (file_id.original_file(db), text_range) | 374 | (file_id.original_file(db), text_range) |