diff options
author | Aleksey Kladov <[email protected]> | 2019-11-09 21:32:00 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-11 11:42:08 +0000 |
commit | 8b7f853cc19d0940ec542e10bc23aa78455bbb3b (patch) | |
tree | eb418bb0df37516dcf24ffc754a862ffea1ab789 /crates/ra_ide_api/src/display | |
parent | 5ac4ffbc121c8231fe3ea5c2bb918f7aae60f197 (diff) |
Add hir::Local
Diffstat (limited to 'crates/ra_ide_api/src/display')
-rw-r--r-- | crates/ra_ide_api/src/display/navigation_target.rs | 70 |
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 | ||
3 | use hir::{AssocItem, FieldSource, HasSource, ModuleSource}; | 3 | use hir::{AssocItem, Either, FieldSource, HasSource, ModuleSource}; |
4 | use ra_db::{FileId, SourceDatabase}; | 4 | use ra_db::{FileId, SourceDatabase}; |
5 | use ra_syntax::{ | 5 | use 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 | ||
337 | impl 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 | |||
373 | fn find_range_from_node( | 363 | fn find_range_from_node( |
374 | db: &RootDatabase, | 364 | db: &RootDatabase, |
375 | src: hir::HirFileId, | 365 | src: hir::HirFileId, |