aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/display
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/display')
-rw-r--r--crates/ra_ide_api/src/display/navigation_target.rs70
1 files changed, 30 insertions, 40 deletions
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs
index 41d467564..f7ad08515 100644
--- a/crates/ra_ide_api/src/display/navigation_target.rs
+++ b/crates/ra_ide_api/src/display/navigation_target.rs
@@ -1,11 +1,11 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::{AssocItem, FieldSource, HasSource, ModuleSource}; 3use hir::{AssocItem, Either, FieldSource, HasSource, ModuleSource};
4use ra_db::{FileId, SourceDatabase}; 4use ra_db::{FileId, SourceDatabase};
5use ra_syntax::{ 5use ra_syntax::{
6 ast::{self, DocCommentsOwner}, 6 ast::{self, DocCommentsOwner, NameOwner},
7 match_ast, AstNode, AstPtr, SmolStr, 7 match_ast, AstNode, SmolStr,
8 SyntaxKind::{self, NAME}, 8 SyntaxKind::{self, BIND_PAT},
9 SyntaxNode, TextRange, 9 SyntaxNode, TextRange,
10}; 10};
11 11
@@ -76,42 +76,6 @@ impl NavigationTarget {
76 self.focus_range 76 self.focus_range
77 } 77 }
78 78
79 pub(crate) fn from_bind_pat(
80 db: &RootDatabase,
81 file_id: FileId,
82 pat: &ast::BindPat,
83 ) -> NavigationTarget {
84 NavigationTarget::from_named(db, file_id.into(), pat, None, None)
85 }
86
87 pub(crate) fn from_pat(
88 db: &RootDatabase,
89 file_id: FileId,
90 pat: AstPtr<ast::BindPat>,
91 ) -> NavigationTarget {
92 let parse = db.parse(file_id);
93 let pat = pat.to_node(parse.tree().syntax());
94 NavigationTarget::from_bind_pat(db, file_id, &pat)
95 }
96
97 pub(crate) fn from_self_param(
98 file_id: FileId,
99 par: AstPtr<ast::SelfParam>,
100 ) -> NavigationTarget {
101 let (name, full_range) = ("self".into(), par.syntax_node_ptr().range());
102
103 NavigationTarget {
104 file_id,
105 name,
106 full_range,
107 focus_range: None,
108 kind: NAME,
109 container_name: None,
110 description: None, //< No document node for SelfParam
111 docs: None, //< No document node for SelfParam
112 }
113 }
114
115 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 {
116 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();
117 if let Some(src) = module.declaration_source(db) { 81 if let Some(src) = module.declaration_source(db) {
@@ -370,6 +334,32 @@ impl ToNav for hir::AssocItem {
370 } 334 }
371} 335}
372 336
337impl ToNav for hir::Local {
338 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
339 let src = self.source(db);
340 let (full_range, focus_range) = match src.ast {
341 Either::A(it) => {
342 (it.syntax().text_range(), it.name().map(|it| it.syntax().text_range()))
343 }
344 Either::B(it) => (it.syntax().text_range(), Some(it.self_kw_token().text_range())),
345 };
346 let name = match self.name(db) {
347 Some(it) => it.to_string().into(),
348 None => "".into(),
349 };
350 NavigationTarget {
351 file_id: src.file_id.original_file(db),
352 name,
353 kind: BIND_PAT,
354 full_range,
355 focus_range,
356 container_name: None,
357 description: None,
358 docs: None,
359 }
360 }
361}
362
373fn find_range_from_node( 363fn find_range_from_node(
374 db: &RootDatabase, 364 db: &RootDatabase,
375 src: hir::HirFileId, 365 src: hir::HirFileId,