aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/navigation_target.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/navigation_target.rs')
-rw-r--r--crates/ra_ide_api/src/navigation_target.rs58
1 files changed, 22 insertions, 36 deletions
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs
index c5be8e01b..d73d4afa7 100644
--- a/crates/ra_ide_api/src/navigation_target.rs
+++ b/crates/ra_ide_api/src/navigation_target.rs
@@ -3,7 +3,7 @@ use ra_syntax::{
3 SyntaxNode, AstNode, SmolStr, TextRange, ast, 3 SyntaxNode, AstNode, SmolStr, TextRange, ast,
4 SyntaxKind::{self, NAME}, 4 SyntaxKind::{self, NAME},
5}; 5};
6use hir::{ModuleSource}; 6use hir::{ModuleSource, FieldSource};
7 7
8use crate::{FileSymbol, db::RootDatabase}; 8use crate::{FileSymbol, db::RootDatabase};
9 9
@@ -101,62 +101,48 @@ impl NavigationTarget {
101 NavigationTarget::from_named(file_id.original_file(db), &*fn_def) 101 NavigationTarget::from_named(file_id.original_file(db), &*fn_def)
102 } 102 }
103 103
104 // TODO once Def::Item is gone, this should be able to always return a NavigationTarget 104 pub(crate) fn from_field(db: &RootDatabase, field: hir::StructField) -> NavigationTarget {
105 pub(crate) fn from_def( 105 let (file_id, field) = field.source(db);
106 db: &RootDatabase, 106 let file_id = file_id.original_file(db);
107 module_def: hir::ModuleDef, 107 match field {
108 ) -> Option<NavigationTarget> { 108 FieldSource::Named(it) => NavigationTarget::from_named(file_id, &*it),
109 FieldSource::Pos(it) => {
110 NavigationTarget::from_syntax(file_id, "".into(), None, it.syntax())
111 }
112 }
113 }
114
115 pub(crate) fn from_def(db: &RootDatabase, module_def: hir::ModuleDef) -> NavigationTarget {
109 match module_def { 116 match module_def {
110 hir::ModuleDef::Module(module) => Some(NavigationTarget::from_module(db, module)), 117 hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module),
111 hir::ModuleDef::Function(func) => Some(NavigationTarget::from_function(db, func)), 118 hir::ModuleDef::Function(func) => NavigationTarget::from_function(db, func),
112 hir::ModuleDef::Struct(s) => { 119 hir::ModuleDef::Struct(s) => {
113 let (file_id, node) = s.source(db); 120 let (file_id, node) = s.source(db);
114 Some(NavigationTarget::from_named( 121 NavigationTarget::from_named(file_id.original_file(db), &*node)
115 file_id.original_file(db),
116 &*node,
117 ))
118 } 122 }
119 hir::ModuleDef::Const(s) => { 123 hir::ModuleDef::Const(s) => {
120 let (file_id, node) = s.source(db); 124 let (file_id, node) = s.source(db);
121 Some(NavigationTarget::from_named( 125 NavigationTarget::from_named(file_id.original_file(db), &*node)
122 file_id.original_file(db),
123 &*node,
124 ))
125 } 126 }
126 hir::ModuleDef::Static(s) => { 127 hir::ModuleDef::Static(s) => {
127 let (file_id, node) = s.source(db); 128 let (file_id, node) = s.source(db);
128 Some(NavigationTarget::from_named( 129 NavigationTarget::from_named(file_id.original_file(db), &*node)
129 file_id.original_file(db),
130 &*node,
131 ))
132 } 130 }
133 hir::ModuleDef::Enum(e) => { 131 hir::ModuleDef::Enum(e) => {
134 let (file_id, node) = e.source(db); 132 let (file_id, node) = e.source(db);
135 Some(NavigationTarget::from_named( 133 NavigationTarget::from_named(file_id.original_file(db), &*node)
136 file_id.original_file(db),
137 &*node,
138 ))
139 } 134 }
140 hir::ModuleDef::EnumVariant(var) => { 135 hir::ModuleDef::EnumVariant(var) => {
141 let (file_id, node) = var.source(db); 136 let (file_id, node) = var.source(db);
142 Some(NavigationTarget::from_named( 137 NavigationTarget::from_named(file_id.original_file(db), &*node)
143 file_id.original_file(db),
144 &*node,
145 ))
146 } 138 }
147 hir::ModuleDef::Trait(e) => { 139 hir::ModuleDef::Trait(e) => {
148 let (file_id, node) = e.source(db); 140 let (file_id, node) = e.source(db);
149 Some(NavigationTarget::from_named( 141 NavigationTarget::from_named(file_id.original_file(db), &*node)
150 file_id.original_file(db),
151 &*node,
152 ))
153 } 142 }
154 hir::ModuleDef::Type(e) => { 143 hir::ModuleDef::Type(e) => {
155 let (file_id, node) = e.source(db); 144 let (file_id, node) = e.source(db);
156 Some(NavigationTarget::from_named( 145 NavigationTarget::from_named(file_id.original_file(db), &*node)
157 file_id.original_file(db),
158 &*node,
159 ))
160 } 146 }
161 } 147 }
162 } 148 }