diff options
-rw-r--r-- | crates/ra_hir/src/generics.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir/src/impl_block.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir/src/resolve.rs | 30 | ||||
-rw-r--r-- | crates/ra_hir/src/ty.rs | 18 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_item.rs | 28 | ||||
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 6 |
7 files changed, 41 insertions, 53 deletions
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index b0bd735bd..a82205f0b 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs | |||
@@ -12,6 +12,7 @@ use crate::{db::PersistentHirDatabase, Name, AsName, Function, Struct, Enum, Tra | |||
12 | /// Data about a generic parameter (to a function, struct, impl, ...). | 12 | /// Data about a generic parameter (to a function, struct, impl, ...). |
13 | #[derive(Clone, PartialEq, Eq, Debug)] | 13 | #[derive(Clone, PartialEq, Eq, Debug)] |
14 | pub struct GenericParam { | 14 | pub struct GenericParam { |
15 | // TODO: give generic params proper IDs | ||
15 | pub(crate) idx: u32, | 16 | pub(crate) idx: u32, |
16 | pub(crate) name: Name, | 17 | pub(crate) name: Name, |
17 | } | 18 | } |
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index a3908048b..738c58fbe 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs | |||
@@ -90,9 +90,8 @@ impl ImplBlock { | |||
90 | pub fn target_trait(&self, db: &impl HirDatabase) -> Option<Trait> { | 90 | pub fn target_trait(&self, db: &impl HirDatabase) -> Option<Trait> { |
91 | if let Some(TypeRef::Path(path)) = self.target_trait_ref() { | 91 | if let Some(TypeRef::Path(path)) = self.target_trait_ref() { |
92 | let resolver = self.resolver(db); | 92 | let resolver = self.resolver(db); |
93 | if let Some(Resolution::Def { | 93 | if let Some(Resolution::Def(ModuleDef::Trait(tr))) = |
94 | def: ModuleDef::Trait(tr), | 94 | resolver.resolve_path(db, path).take_types() |
95 | }) = resolver.resolve_path(db, path).take_types() | ||
96 | { | 95 | { |
97 | return Some(tr); | 96 | return Some(tr); |
98 | } | 97 | } |
@@ -106,7 +105,7 @@ impl ImplBlock { | |||
106 | 105 | ||
107 | pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { | 106 | pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { |
108 | let r = self.module().resolver(db); | 107 | let r = self.module().resolver(db); |
109 | // FIXME: add generics | 108 | // TODO: add generics |
110 | let r = r.push_impl_block_scope(self.clone()); | 109 | let r = r.push_impl_block_scope(self.clone()); |
111 | r | 110 | r |
112 | } | 111 | } |
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 3e0af3a43..7929e8b7c 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs | |||
@@ -48,17 +48,11 @@ pub(crate) enum Scope { | |||
48 | pub enum Resolution { | 48 | pub enum Resolution { |
49 | // FIXME make these tuple variants | 49 | // FIXME make these tuple variants |
50 | /// An item | 50 | /// An item |
51 | Def { | 51 | Def(ModuleDef), |
52 | def: ModuleDef, | ||
53 | }, | ||
54 | /// A local binding (only value namespace) | 52 | /// A local binding (only value namespace) |
55 | LocalBinding { | 53 | LocalBinding(PatId), |
56 | pat: PatId, | ||
57 | }, | ||
58 | /// A generic parameter | 54 | /// A generic parameter |
59 | GenericParam { | 55 | GenericParam(u32), |
60 | idx: u32, | ||
61 | }, | ||
62 | SelfType(ImplBlock), | 56 | SelfType(ImplBlock), |
63 | } | 57 | } |
64 | 58 | ||
@@ -85,7 +79,7 @@ impl Resolver { | |||
85 | _ => return PerNs::none(), | 79 | _ => return PerNs::none(), |
86 | }; | 80 | }; |
87 | let module_res = item_map.resolve_path(db, module, path); | 81 | let module_res = item_map.resolve_path(db, module, path); |
88 | module_res.map(|def| Resolution::Def { def }) | 82 | module_res.map(|def| Resolution::Def(def)) |
89 | } | 83 | } |
90 | } | 84 | } |
91 | 85 | ||
@@ -157,18 +151,16 @@ impl Scope { | |||
157 | match self { | 151 | match self { |
158 | Scope::ModuleScope(m) => { | 152 | Scope::ModuleScope(m) => { |
159 | if let Some(KnownName::SelfParam) = name.as_known_name() { | 153 | if let Some(KnownName::SelfParam) = name.as_known_name() { |
160 | PerNs::types(Resolution::Def { | 154 | PerNs::types(Resolution::Def(m.module.into())) |
161 | def: m.module.into(), | ||
162 | }) | ||
163 | } else { | 155 | } else { |
164 | match m.item_map[m.module.module_id].get(name) { | 156 | match m.item_map[m.module.module_id].get(name) { |
165 | Some(res) => res.def.map(|def| Resolution::Def { def }), | 157 | Some(res) => res.def.map(Resolution::Def), |
166 | None => PerNs::none(), | 158 | None => PerNs::none(), |
167 | } | 159 | } |
168 | } | 160 | } |
169 | } | 161 | } |
170 | Scope::GenericParams(gp) => match gp.find_by_name(name) { | 162 | Scope::GenericParams(gp) => match gp.find_by_name(name) { |
171 | Some(gp) => PerNs::types(Resolution::GenericParam { idx: gp.idx }), | 163 | Some(gp) => PerNs::types(Resolution::GenericParam(gp.idx)), |
172 | None => PerNs::none(), | 164 | None => PerNs::none(), |
173 | }, | 165 | }, |
174 | Scope::ImplBlockScope(i) => { | 166 | Scope::ImplBlockScope(i) => { |
@@ -185,7 +177,7 @@ impl Scope { | |||
185 | .iter() | 177 | .iter() |
186 | .find(|entry| entry.name() == name); | 178 | .find(|entry| entry.name() == name); |
187 | match entry { | 179 | match entry { |
188 | Some(e) => PerNs::values(Resolution::LocalBinding { pat: e.pat() }), | 180 | Some(e) => PerNs::values(Resolution::LocalBinding(e.pat())), |
189 | None => PerNs::none(), | 181 | None => PerNs::none(), |
190 | } | 182 | } |
191 | } | 183 | } |
@@ -205,14 +197,14 @@ impl Scope { | |||
205 | m.item_map[m.module.module_id] | 197 | m.item_map[m.module.module_id] |
206 | .entries() | 198 | .entries() |
207 | .for_each(|(name, res)| { | 199 | .for_each(|(name, res)| { |
208 | f(name.clone(), res.def.map(|def| Resolution::Def { def })); | 200 | f(name.clone(), res.def.map(Resolution::Def)); |
209 | }) | 201 | }) |
210 | } | 202 | } |
211 | Scope::GenericParams(gp) => { | 203 | Scope::GenericParams(gp) => { |
212 | for param in &gp.params { | 204 | for param in &gp.params { |
213 | f( | 205 | f( |
214 | param.name.clone(), | 206 | param.name.clone(), |
215 | PerNs::types(Resolution::GenericParam { idx: param.idx }), | 207 | PerNs::types(Resolution::GenericParam(param.idx)), |
216 | ) | 208 | ) |
217 | } | 209 | } |
218 | } | 210 | } |
@@ -226,7 +218,7 @@ impl Scope { | |||
226 | e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { | 218 | e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { |
227 | f( | 219 | f( |
228 | e.name().clone(), | 220 | e.name().clone(), |
229 | PerNs::values(Resolution::LocalBinding { pat: e.pat() }), | 221 | PerNs::values(Resolution::LocalBinding(e.pat())), |
230 | ); | 222 | ); |
231 | }); | 223 | }); |
232 | } | 224 | } |
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index d9c62f84c..cc5afad75 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -368,12 +368,12 @@ impl Ty { | |||
368 | let resolution = resolver.resolve_path(db, path).take_types(); | 368 | let resolution = resolver.resolve_path(db, path).take_types(); |
369 | 369 | ||
370 | let def = match resolution { | 370 | let def = match resolution { |
371 | Some(Resolution::Def { def, .. }) => def, | 371 | Some(Resolution::Def(def)) => def, |
372 | Some(Resolution::LocalBinding { .. }) => { | 372 | Some(Resolution::LocalBinding(..)) => { |
373 | // this should never happen | 373 | // this should never happen |
374 | panic!("path resolved to local binding in type ns"); | 374 | panic!("path resolved to local binding in type ns"); |
375 | } | 375 | } |
376 | Some(Resolution::GenericParam { idx }) => { | 376 | Some(Resolution::GenericParam(idx)) => { |
377 | return Ty::Param { | 377 | return Ty::Param { |
378 | idx, | 378 | idx, |
379 | // TODO: maybe return name in resolution? | 379 | // TODO: maybe return name in resolution? |
@@ -1107,7 +1107,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1107 | fn infer_path_expr(&mut self, resolver: &Resolver, path: &Path) -> Option<Ty> { | 1107 | fn infer_path_expr(&mut self, resolver: &Resolver, path: &Path) -> Option<Ty> { |
1108 | let resolved = resolver.resolve_path(self.db, &path).take_values()?; | 1108 | let resolved = resolver.resolve_path(self.db, &path).take_values()?; |
1109 | match resolved { | 1109 | match resolved { |
1110 | Resolution::Def { def, .. } => { | 1110 | Resolution::Def(def) => { |
1111 | let typable: Option<TypableDef> = def.into(); | 1111 | let typable: Option<TypableDef> = def.into(); |
1112 | let typable = typable?; | 1112 | let typable = typable?; |
1113 | let substs = Ty::substs_from_path(self.db, &self.resolver, path, typable); | 1113 | let substs = Ty::substs_from_path(self.db, &self.resolver, path, typable); |
@@ -1115,12 +1115,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1115 | let ty = self.insert_type_vars(ty); | 1115 | let ty = self.insert_type_vars(ty); |
1116 | Some(ty) | 1116 | Some(ty) |
1117 | } | 1117 | } |
1118 | Resolution::LocalBinding { pat } => { | 1118 | Resolution::LocalBinding(pat) => { |
1119 | let ty = self.type_of_pat.get(pat)?; | 1119 | let ty = self.type_of_pat.get(pat)?; |
1120 | let ty = self.resolve_ty_as_possible(&mut vec![], ty.clone()); | 1120 | let ty = self.resolve_ty_as_possible(&mut vec![], ty.clone()); |
1121 | Some(ty) | 1121 | Some(ty) |
1122 | } | 1122 | } |
1123 | Resolution::GenericParam { .. } => { | 1123 | Resolution::GenericParam(..) => { |
1124 | // generic params can't refer to values... yet | 1124 | // generic params can't refer to values... yet |
1125 | None | 1125 | None |
1126 | } | 1126 | } |
@@ -1138,13 +1138,13 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1138 | }; | 1138 | }; |
1139 | let resolver = &self.resolver; | 1139 | let resolver = &self.resolver; |
1140 | let typable: Option<TypableDef> = match resolver.resolve_path(self.db, &path).take_types() { | 1140 | let typable: Option<TypableDef> = match resolver.resolve_path(self.db, &path).take_types() { |
1141 | Some(Resolution::Def { def, .. }) => def.into(), | 1141 | Some(Resolution::Def(def)) => def.into(), |
1142 | Some(Resolution::LocalBinding { .. }) => { | 1142 | Some(Resolution::LocalBinding(..)) => { |
1143 | // this cannot happen | 1143 | // this cannot happen |
1144 | log::error!("path resolved to local binding in type ns"); | 1144 | log::error!("path resolved to local binding in type ns"); |
1145 | return (Ty::Unknown, None); | 1145 | return (Ty::Unknown, None); |
1146 | } | 1146 | } |
1147 | Some(Resolution::GenericParam { .. }) => { | 1147 | Some(Resolution::GenericParam(..)) => { |
1148 | // generic params can't be used in struct literals | 1148 | // generic params can't be used in struct literals |
1149 | return (Ty::Unknown, None); | 1149 | return (Ty::Unknown, None); |
1150 | } | 1150 | } |
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 5b89c64ad..8e0f6a79e 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -12,7 +12,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
12 | _ => return, | 12 | _ => return, |
13 | }; | 13 | }; |
14 | let def = match ctx.resolver.resolve_path(ctx.db, &path).take_types() { | 14 | let def = match ctx.resolver.resolve_path(ctx.db, &path).take_types() { |
15 | Some(Resolution::Def { def }) => def, | 15 | Some(Resolution::Def(def)) => def, |
16 | _ => return, | 16 | _ => return, |
17 | }; | 17 | }; |
18 | match def { | 18 | match def { |
@@ -24,7 +24,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
24 | ctx.source_range(), | 24 | ctx.source_range(), |
25 | name.to_string(), | 25 | name.to_string(), |
26 | ) | 26 | ) |
27 | .from_resolution(ctx, &res.def.map(|def| hir::Resolution::Def { def })) | 27 | .from_resolution(ctx, &res.def.map(hir::Resolution::Def)) |
28 | .add_to(acc); | 28 | .add_to(acc); |
29 | } | 29 | } |
30 | } | 30 | } |
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index 4101ce88a..bada6a33b 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs | |||
@@ -223,22 +223,18 @@ impl Builder { | |||
223 | Some(it) => it, | 223 | Some(it) => it, |
224 | }; | 224 | }; |
225 | let (kind, docs) = match def { | 225 | let (kind, docs) = match def { |
226 | Resolution::Def { def: Module(it) } => (CompletionItemKind::Module, it.docs(ctx.db)), | 226 | Resolution::Def(Module(it)) => (CompletionItemKind::Module, it.docs(ctx.db)), |
227 | Resolution::Def { | 227 | Resolution::Def(Function(func)) => return self.from_function(ctx, *func), |
228 | def: Function(func), | 228 | Resolution::Def(Struct(it)) => (CompletionItemKind::Struct, it.docs(ctx.db)), |
229 | } => return self.from_function(ctx, *func), | 229 | Resolution::Def(Enum(it)) => (CompletionItemKind::Enum, it.docs(ctx.db)), |
230 | Resolution::Def { def: Struct(it) } => (CompletionItemKind::Struct, it.docs(ctx.db)), | 230 | Resolution::Def(EnumVariant(it)) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)), |
231 | Resolution::Def { def: Enum(it) } => (CompletionItemKind::Enum, it.docs(ctx.db)), | 231 | Resolution::Def(Const(it)) => (CompletionItemKind::Const, it.docs(ctx.db)), |
232 | Resolution::Def { | 232 | Resolution::Def(Static(it)) => (CompletionItemKind::Static, it.docs(ctx.db)), |
233 | def: EnumVariant(it), | 233 | Resolution::Def(Trait(it)) => (CompletionItemKind::Trait, it.docs(ctx.db)), |
234 | } => (CompletionItemKind::EnumVariant, it.docs(ctx.db)), | 234 | Resolution::Def(Type(it)) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), |
235 | Resolution::Def { def: Const(it) } => (CompletionItemKind::Const, it.docs(ctx.db)), | 235 | Resolution::GenericParam(..) => (CompletionItemKind::TypeParam, None), |
236 | Resolution::Def { def: Static(it) } => (CompletionItemKind::Static, it.docs(ctx.db)), | 236 | Resolution::LocalBinding(..) => (CompletionItemKind::Binding, None), |
237 | Resolution::Def { def: Trait(it) } => (CompletionItemKind::Trait, it.docs(ctx.db)), | 237 | Resolution::SelfType(..) => ( |
238 | Resolution::Def { def: Type(it) } => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), | ||
239 | Resolution::GenericParam { .. } => (CompletionItemKind::TypeParam, None), | ||
240 | Resolution::LocalBinding { .. } => (CompletionItemKind::Binding, None), | ||
241 | Resolution::SelfType { .. } => ( | ||
242 | CompletionItemKind::TypeParam, // (does this need its own kind?) | 238 | CompletionItemKind::TypeParam, // (does this need its own kind?) |
243 | None, | 239 | None, |
244 | ), | 240 | ), |
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 48080b6e1..88efcea2a 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -90,8 +90,8 @@ pub(crate) fn reference_definition( | |||
90 | { | 90 | { |
91 | let resolved = resolver.resolve_path(db, &path); | 91 | let resolved = resolver.resolve_path(db, &path); |
92 | match resolved.clone().take_types().or(resolved.take_values()) { | 92 | match resolved.clone().take_types().or(resolved.take_values()) { |
93 | Some(Resolution::Def { def }) => return Exact(NavigationTarget::from_def(db, def)), | 93 | Some(Resolution::Def(def)) => return Exact(NavigationTarget::from_def(db, def)), |
94 | Some(Resolution::LocalBinding { pat }) => { | 94 | Some(Resolution::LocalBinding(pat)) => { |
95 | let body = resolver.body().expect("no body for local binding"); | 95 | let body = resolver.body().expect("no body for local binding"); |
96 | let syntax_mapping = body.syntax_mapping(db); | 96 | let syntax_mapping = body.syntax_mapping(db); |
97 | let ptr = syntax_mapping | 97 | let ptr = syntax_mapping |
@@ -104,7 +104,7 @@ pub(crate) fn reference_definition( | |||
104 | let nav = NavigationTarget::from_scope_entry(file_id, name, ptr); | 104 | let nav = NavigationTarget::from_scope_entry(file_id, name, ptr); |
105 | return Exact(nav); | 105 | return Exact(nav); |
106 | } | 106 | } |
107 | Some(Resolution::GenericParam { .. }) => { | 107 | Some(Resolution::GenericParam(..)) => { |
108 | // TODO go to the generic param def | 108 | // TODO go to the generic param def |
109 | } | 109 | } |
110 | Some(Resolution::SelfType(_impl_block)) => { | 110 | Some(Resolution::SelfType(_impl_block)) => { |