diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-24 22:56:13 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-24 22:56:13 +0000 |
commit | c42db0bbd750fae19a91f0a0354240ea6c3bafce (patch) | |
tree | beb7030248280fd8c67eb2b2c9cc4b19c6074c17 /crates/ra_ide_api/src/navigation_target.rs | |
parent | b308375b82a33687f93468d75c7cc628b83a1351 (diff) | |
parent | 31d3a56b1865c33ef54e5d76e606965c87676695 (diff) |
Merge #623
623: WIP: module id is not def id r=matklad a=matklad
This achieves two things:
* makes module_tree & item_map per crate, not per source_root
* begins the refactoring to remove universal `DefId` in favor of having separate ids for each kind of `Def`. Currently, only modules get a differnt ID though.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/navigation_target.rs')
-rw-r--r-- | crates/ra_ide_api/src/navigation_target.rs | 86 |
1 files changed, 55 insertions, 31 deletions
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs index 21c15c0c0..c5be8e01b 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 | }; |
6 | use hir::{Def, ModuleSource}; | 6 | use hir::{ModuleSource}; |
7 | 7 | ||
8 | use crate::{FileSymbol, db::RootDatabase}; | 8 | use crate::{FileSymbol, db::RootDatabase}; |
9 | 9 | ||
@@ -96,45 +96,69 @@ impl NavigationTarget { | |||
96 | NavigationTarget::from_module(db, module) | 96 | NavigationTarget::from_module(db, module) |
97 | } | 97 | } |
98 | 98 | ||
99 | pub(crate) fn from_function(db: &RootDatabase, func: hir::Function) -> NavigationTarget { | ||
100 | let (file_id, fn_def) = func.source(db); | ||
101 | NavigationTarget::from_named(file_id.original_file(db), &*fn_def) | ||
102 | } | ||
103 | |||
99 | // TODO once Def::Item is gone, this should be able to always return a NavigationTarget | 104 | // TODO once Def::Item is gone, this should be able to always return a NavigationTarget |
100 | pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Option<NavigationTarget> { | 105 | pub(crate) fn from_def( |
101 | let res = match def { | 106 | db: &RootDatabase, |
102 | Def::Struct(s) => { | 107 | module_def: hir::ModuleDef, |
108 | ) -> Option<NavigationTarget> { | ||
109 | match module_def { | ||
110 | hir::ModuleDef::Module(module) => Some(NavigationTarget::from_module(db, module)), | ||
111 | hir::ModuleDef::Function(func) => Some(NavigationTarget::from_function(db, func)), | ||
112 | hir::ModuleDef::Struct(s) => { | ||
103 | let (file_id, node) = s.source(db); | 113 | let (file_id, node) = s.source(db); |
104 | NavigationTarget::from_named(file_id.original_file(db), &*node) | 114 | Some(NavigationTarget::from_named( |
115 | file_id.original_file(db), | ||
116 | &*node, | ||
117 | )) | ||
105 | } | 118 | } |
106 | Def::Enum(e) => { | 119 | hir::ModuleDef::Const(s) => { |
107 | let (file_id, node) = e.source(db); | 120 | let (file_id, node) = s.source(db); |
108 | NavigationTarget::from_named(file_id.original_file(db), &*node) | 121 | Some(NavigationTarget::from_named( |
109 | } | 122 | file_id.original_file(db), |
110 | Def::EnumVariant(ev) => { | 123 | &*node, |
111 | let (file_id, node) = ev.source(db); | 124 | )) |
112 | NavigationTarget::from_named(file_id.original_file(db), &*node) | ||
113 | } | 125 | } |
114 | Def::Function(f) => { | 126 | hir::ModuleDef::Static(s) => { |
115 | let (file_id, node) = f.source(db); | 127 | let (file_id, node) = s.source(db); |
116 | NavigationTarget::from_named(file_id.original_file(db), &*node) | 128 | Some(NavigationTarget::from_named( |
129 | file_id.original_file(db), | ||
130 | &*node, | ||
131 | )) | ||
117 | } | 132 | } |
118 | Def::Trait(f) => { | 133 | hir::ModuleDef::Enum(e) => { |
119 | let (file_id, node) = f.source(db); | 134 | let (file_id, node) = e.source(db); |
120 | NavigationTarget::from_named(file_id.original_file(db), &*node) | 135 | Some(NavigationTarget::from_named( |
136 | file_id.original_file(db), | ||
137 | &*node, | ||
138 | )) | ||
121 | } | 139 | } |
122 | Def::Type(f) => { | 140 | hir::ModuleDef::EnumVariant(var) => { |
123 | let (file_id, node) = f.source(db); | 141 | let (file_id, node) = var.source(db); |
124 | NavigationTarget::from_named(file_id.original_file(db), &*node) | 142 | Some(NavigationTarget::from_named( |
143 | file_id.original_file(db), | ||
144 | &*node, | ||
145 | )) | ||
125 | } | 146 | } |
126 | Def::Static(f) => { | 147 | hir::ModuleDef::Trait(e) => { |
127 | let (file_id, node) = f.source(db); | 148 | let (file_id, node) = e.source(db); |
128 | NavigationTarget::from_named(file_id.original_file(db), &*node) | 149 | Some(NavigationTarget::from_named( |
150 | file_id.original_file(db), | ||
151 | &*node, | ||
152 | )) | ||
129 | } | 153 | } |
130 | Def::Const(f) => { | 154 | hir::ModuleDef::Type(e) => { |
131 | let (file_id, node) = f.source(db); | 155 | let (file_id, node) = e.source(db); |
132 | NavigationTarget::from_named(file_id.original_file(db), &*node) | 156 | Some(NavigationTarget::from_named( |
157 | file_id.original_file(db), | ||
158 | &*node, | ||
159 | )) | ||
133 | } | 160 | } |
134 | Def::Module(m) => NavigationTarget::from_module(db, m), | 161 | } |
135 | Def::Item => return None, | ||
136 | }; | ||
137 | Some(res) | ||
138 | } | 162 | } |
139 | 163 | ||
140 | #[cfg(test)] | 164 | #[cfg(test)] |