diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide_api/src/navigation_target.rs | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs index eaf46fd01..cff11eeab 100644 --- a/crates/ra_ide_api/src/navigation_target.rs +++ b/crates/ra_ide_api/src/navigation_target.rs | |||
@@ -1,6 +1,9 @@ | |||
1 | use ra_db::{FileId, LocalSyntaxPtr, Cancelable}; | 1 | use ra_db::{FileId, LocalSyntaxPtr, Cancelable}; |
2 | use ra_syntax::{SyntaxNode, AstNode}; | 2 | use ra_syntax::{ |
3 | use hir::{Name, Def, ModuleSource}; | 3 | SyntaxNode, AstNode, SmolStr, |
4 | ast | ||
5 | }; | ||
6 | use hir::{Def, ModuleSource}; | ||
4 | 7 | ||
5 | use crate::{ | 8 | use crate::{ |
6 | NavigationTarget, | 9 | NavigationTarget, |
@@ -24,46 +27,44 @@ impl NavigationTarget { | |||
24 | Ok(match def { | 27 | Ok(match def { |
25 | Def::Struct(s) => { | 28 | Def::Struct(s) => { |
26 | let (file_id, node) = s.source(db)?; | 29 | let (file_id, node) = s.source(db)?; |
27 | Some(NavigationTarget::from_syntax( | 30 | Some(NavigationTarget::from_named( |
28 | s.name(db)?, | ||
29 | file_id.original_file(db), | 31 | file_id.original_file(db), |
30 | node.syntax(), | 32 | &*node, |
31 | )) | 33 | )) |
32 | } | 34 | } |
33 | Def::Enum(e) => { | 35 | Def::Enum(e) => { |
34 | let (file_id, node) = e.source(db)?; | 36 | let (file_id, node) = e.source(db)?; |
35 | Some(NavigationTarget::from_syntax( | 37 | Some(NavigationTarget::from_named( |
36 | e.name(db)?, | ||
37 | file_id.original_file(db), | 38 | file_id.original_file(db), |
38 | node.syntax(), | 39 | &*node, |
39 | )) | 40 | )) |
40 | } | 41 | } |
41 | Def::EnumVariant(ev) => { | 42 | Def::EnumVariant(ev) => { |
42 | let (file_id, node) = ev.source(db)?; | 43 | let (file_id, node) = ev.source(db)?; |
43 | Some(NavigationTarget::from_syntax( | 44 | Some(NavigationTarget::from_named( |
44 | ev.name(db)?, | ||
45 | file_id.original_file(db), | 45 | file_id.original_file(db), |
46 | node.syntax(), | 46 | &*node, |
47 | )) | 47 | )) |
48 | } | 48 | } |
49 | Def::Function(f) => { | 49 | Def::Function(f) => { |
50 | let (file_id, node) = f.source(db)?; | 50 | let (file_id, node) = f.source(db)?; |
51 | let name = f.signature(db).name().clone(); | 51 | Some(NavigationTarget::from_named( |
52 | Some(NavigationTarget::from_syntax( | ||
53 | Some(name), | ||
54 | file_id.original_file(db), | 52 | file_id.original_file(db), |
55 | node.syntax(), | 53 | &*node, |
56 | )) | 54 | )) |
57 | } | 55 | } |
58 | Def::Module(m) => { | 56 | Def::Module(m) => { |
59 | let (file_id, source) = m.definition_source(db)?; | 57 | let (file_id, source) = m.definition_source(db)?; |
60 | let name = m.name(db)?; | 58 | let name = m |
59 | .name(db)? | ||
60 | .map(|it| it.to_string().into()) | ||
61 | .unwrap_or_else(|| SmolStr::new("")); | ||
61 | match source { | 62 | match source { |
62 | ModuleSource::SourceFile(node) => { | 63 | ModuleSource::SourceFile(node) => { |
63 | Some(NavigationTarget::from_syntax(name, file_id, node.syntax())) | 64 | Some(NavigationTarget::from_syntax(file_id, name, node.syntax())) |
64 | } | 65 | } |
65 | ModuleSource::Module(node) => { | 66 | ModuleSource::Module(node) => { |
66 | Some(NavigationTarget::from_syntax(name, file_id, node.syntax())) | 67 | Some(NavigationTarget::from_syntax(file_id, name, node.syntax())) |
67 | } | 68 | } |
68 | } | 69 | } |
69 | } | 70 | } |
@@ -71,10 +72,18 @@ impl NavigationTarget { | |||
71 | }) | 72 | }) |
72 | } | 73 | } |
73 | 74 | ||
74 | fn from_syntax(name: Option<Name>, file_id: FileId, node: &SyntaxNode) -> NavigationTarget { | 75 | fn from_named(file_id: FileId, node: &impl ast::NameOwner) -> NavigationTarget { |
76 | let name = node | ||
77 | .name() | ||
78 | .map(|it| it.text().clone()) | ||
79 | .unwrap_or_else(|| SmolStr::new("")); | ||
80 | NavigationTarget::from_syntax(file_id, name, node.syntax()) | ||
81 | } | ||
82 | |||
83 | fn from_syntax(file_id: FileId, name: SmolStr, node: &SyntaxNode) -> NavigationTarget { | ||
75 | NavigationTarget { | 84 | NavigationTarget { |
76 | file_id, | 85 | file_id, |
77 | name: name.map(|n| n.to_string().into()).unwrap_or("".into()), | 86 | name, |
78 | kind: node.kind(), | 87 | kind: node.kind(), |
79 | range: node.range(), | 88 | range: node.range(), |
80 | ptr: Some(LocalSyntaxPtr::new(node)), | 89 | ptr: Some(LocalSyntaxPtr::new(node)), |