From 5e8c22dbf35e815af148fbdd8dd6da4b50f7aea7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 18 Nov 2019 14:36:11 +0300 Subject: More sources --- crates/ra_ide_api/src/display/navigation_target.rs | 40 ++++++++++++---------- crates/ra_ide_api/src/goto_definition.rs | 33 ++++++------------ 2 files changed, 32 insertions(+), 41 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index 291b5ee40..b30ef8e05 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs @@ -6,7 +6,7 @@ use ra_syntax::{ ast::{self, DocCommentsOwner, NameOwner}, match_ast, AstNode, SmolStr, SyntaxKind::{self, BIND_PAT}, - SyntaxNode, TextRange, + TextRange, }; use crate::{db::RootDatabase, expand::original_range, FileSymbol}; @@ -86,7 +86,7 @@ impl NavigationTarget { name, None, frange.range, - src.ast.syntax(), + src.ast.syntax().kind(), src.ast.doc_comment_text(), src.ast.short_label(), ); @@ -141,23 +141,22 @@ impl NavigationTarget { /// Allows `NavigationTarget` to be created from a `NameOwner` pub(crate) fn from_named( db: &RootDatabase, - file_id: hir::HirFileId, - node: &impl ast::NameOwner, + node: Source<&dyn ast::NameOwner>, docs: Option, description: Option, ) -> NavigationTarget { //FIXME: use `_` instead of empty string - let name = node.name().map(|it| it.text().clone()).unwrap_or_default(); + let name = node.ast.name().map(|it| it.text().clone()).unwrap_or_default(); let focus_range = - node.name().map(|it| original_range(db, Source::new(file_id, it.syntax())).range); - let frange = original_range(db, Source::new(file_id, node.syntax())); + node.ast.name().map(|it| original_range(db, node.with_ast(it.syntax())).range); + let frange = original_range(db, node.map(|it| it.syntax())); NavigationTarget::from_syntax( frange.file_id, name, focus_range, frange.range, - node.syntax(), + node.ast.syntax().kind(), docs, description, ) @@ -168,14 +167,14 @@ impl NavigationTarget { name: SmolStr, focus_range: Option, full_range: TextRange, - node: &SyntaxNode, + kind: SyntaxKind, docs: Option, description: Option, ) -> NavigationTarget { NavigationTarget { file_id, name, - kind: node.kind(), + kind, full_range, focus_range, container_name: None, @@ -220,8 +219,7 @@ where let src = self.source(db); NavigationTarget::from_named( db, - src.file_id, - &src.ast, + src.as_ref().map(|it| it as &dyn ast::NameOwner), src.ast.doc_comment_text(), src.ast.short_label(), ) @@ -241,7 +239,7 @@ impl ToNav for hir::Module { name, None, frange.range, - node.syntax(), + node.syntax().kind(), None, None, ) @@ -254,7 +252,7 @@ impl ToNav for hir::Module { name, None, frange.range, - node.syntax(), + node.syntax().kind(), node.doc_comment_text(), node.short_label(), ) @@ -273,7 +271,7 @@ impl ToNav for hir::ImplBlock { "impl".into(), None, frange.range, - src.ast.syntax(), + src.ast.syntax().kind(), None, None, ) @@ -287,8 +285,7 @@ impl ToNav for hir::StructField { match &src.ast { FieldSource::Named(it) => NavigationTarget::from_named( db, - src.file_id, - it, + src.with_ast(it), it.doc_comment_text(), it.short_label(), ), @@ -299,7 +296,7 @@ impl ToNav for hir::StructField { "".into(), None, frange.range, - it.syntax(), + it.syntax().kind(), None, None, ) @@ -312,7 +309,12 @@ impl ToNav for hir::MacroDef { fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { let src = self.source(db); log::debug!("nav target {:#?}", src.ast.syntax()); - NavigationTarget::from_named(db, src.file_id, &src.ast, src.ast.doc_comment_text(), None) + NavigationTarget::from_named( + db, + src.as_ref().map(|it| it as &dyn ast::NameOwner), + src.ast.doc_comment_text(), + None, + ) } } diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 1a8db0ea0..3f16e9566 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -120,8 +120,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.file_id, - &it, + node.with_ast(&it), it.doc_comment_text(), it.short_label(), )) @@ -129,8 +128,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.file_id, - &it, + node.with_ast(&it), it.doc_comment_text(), it.short_label(), )) @@ -138,8 +136,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.file_id, - &it, + node.with_ast(&it), it.doc_comment_text(), it.short_label(), )) @@ -147,8 +144,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.file_id, - &it, + node.with_ast(&it), it.doc_comment_text(), it.short_label(), )) @@ -156,8 +152,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.file_id, - &it, + node.with_ast(&it), it.doc_comment_text(), it.short_label(), )) @@ -165,8 +160,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.file_id, - &it, + node.with_ast(&it), it.doc_comment_text(), it.short_label(), )) @@ -174,8 +168,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.file_id, - &it, + node.with_ast(&it), it.doc_comment_text(), it.short_label(), )) @@ -183,8 +176,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.file_id, - &it, + node.with_ast(&it), it.doc_comment_text(), it.short_label(), )) @@ -192,8 +184,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.file_id, - &it, + node.with_ast(&it), it.doc_comment_text(), it.short_label(), )) @@ -201,8 +192,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.file_id, - &it, + node.with_ast(&it), it.doc_comment_text(), it.short_label(), )) @@ -210,8 +200,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option { Some(NavigationTarget::from_named( db, - node.file_id, - &it, + node.with_ast(&it), it.doc_comment_text(), None, )) -- cgit v1.2.3