aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs4
-rw-r--r--crates/ra_ide_api/src/navigation_target.rs45
2 files changed, 11 insertions, 38 deletions
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index 45b4c56ef..dc0c50918 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -97,9 +97,7 @@ pub(crate) fn reference_definition(
97 { 97 {
98 let resolved = module.resolve_path(db, &path); 98 let resolved = module.resolve_path(db, &path);
99 if let Some(def_id) = resolved.take_types().or(resolved.take_values()) { 99 if let Some(def_id) = resolved.take_types().or(resolved.take_values()) {
100 if let Some(target) = NavigationTarget::from_def(db, def_id) { 100 return Exact(NavigationTarget::from_def(db, def_id));
101 return Exact(target);
102 }
103 } 101 }
104 } 102 }
105 } 103 }
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs
index ae2175dbc..d73d4afa7 100644
--- a/crates/ra_ide_api/src/navigation_target.rs
+++ b/crates/ra_ide_api/src/navigation_target.rs
@@ -112,62 +112,37 @@ impl NavigationTarget {
112 } 112 }
113 } 113 }
114 114
115 // TODO once Def::Item is gone, this should be able to always return a NavigationTarget 115 pub(crate) fn from_def(db: &RootDatabase, module_def: hir::ModuleDef) -> NavigationTarget {
116 pub(crate) fn from_def(
117 db: &RootDatabase,
118 module_def: hir::ModuleDef,
119 ) -> Option<NavigationTarget> {
120 match module_def { 116 match module_def {
121 hir::ModuleDef::Module(module) => Some(NavigationTarget::from_module(db, module)), 117 hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module),
122 hir::ModuleDef::Function(func) => Some(NavigationTarget::from_function(db, func)), 118 hir::ModuleDef::Function(func) => NavigationTarget::from_function(db, func),
123 hir::ModuleDef::Struct(s) => { 119 hir::ModuleDef::Struct(s) => {
124 let (file_id, node) = s.source(db); 120 let (file_id, node) = s.source(db);
125 Some(NavigationTarget::from_named( 121 NavigationTarget::from_named(file_id.original_file(db), &*node)
126 file_id.original_file(db),
127 &*node,
128 ))
129 } 122 }
130 hir::ModuleDef::Const(s) => { 123 hir::ModuleDef::Const(s) => {
131 let (file_id, node) = s.source(db); 124 let (file_id, node) = s.source(db);
132 Some(NavigationTarget::from_named( 125 NavigationTarget::from_named(file_id.original_file(db), &*node)
133 file_id.original_file(db),
134 &*node,
135 ))
136 } 126 }
137 hir::ModuleDef::Static(s) => { 127 hir::ModuleDef::Static(s) => {
138 let (file_id, node) = s.source(db); 128 let (file_id, node) = s.source(db);
139 Some(NavigationTarget::from_named( 129 NavigationTarget::from_named(file_id.original_file(db), &*node)
140 file_id.original_file(db),
141 &*node,
142 ))
143 } 130 }
144 hir::ModuleDef::Enum(e) => { 131 hir::ModuleDef::Enum(e) => {
145 let (file_id, node) = e.source(db); 132 let (file_id, node) = e.source(db);
146 Some(NavigationTarget::from_named( 133 NavigationTarget::from_named(file_id.original_file(db), &*node)
147 file_id.original_file(db),
148 &*node,
149 ))
150 } 134 }
151 hir::ModuleDef::EnumVariant(var) => { 135 hir::ModuleDef::EnumVariant(var) => {
152 let (file_id, node) = var.source(db); 136 let (file_id, node) = var.source(db);
153 Some(NavigationTarget::from_named( 137 NavigationTarget::from_named(file_id.original_file(db), &*node)
154 file_id.original_file(db),
155 &*node,
156 ))
157 } 138 }
158 hir::ModuleDef::Trait(e) => { 139 hir::ModuleDef::Trait(e) => {
159 let (file_id, node) = e.source(db); 140 let (file_id, node) = e.source(db);
160 Some(NavigationTarget::from_named( 141 NavigationTarget::from_named(file_id.original_file(db), &*node)
161 file_id.original_file(db),
162 &*node,
163 ))
164 } 142 }
165 hir::ModuleDef::Type(e) => { 143 hir::ModuleDef::Type(e) => {
166 let (file_id, node) = e.source(db); 144 let (file_id, node) = e.source(db);
167 Some(NavigationTarget::from_named( 145 NavigationTarget::from_named(file_id.original_file(db), &*node)
168 file_id.original_file(db),
169 &*node,
170 ))
171 } 146 }
172 } 147 }
173 } 148 }