diff options
author | Aleksey Kladov <[email protected]> | 2019-02-08 11:49:43 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-08 11:49:43 +0000 |
commit | 12e3b4c70b5ef23b2fdfc197296d483680e125f9 (patch) | |
tree | 71baa0e0a62f9f6b61450501c5f821f67badf9e4 /crates/ra_hir/src/code_model_api.rs | |
parent | 5cb1d41a30d25cbe136402644bf5434dd667f1e5 (diff) |
reformat the world
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 71 |
1 files changed, 13 insertions, 58 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index a58bf8f87..cafc5279d 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -71,17 +71,7 @@ pub enum ModuleDef { | |||
71 | Trait(Trait), | 71 | Trait(Trait), |
72 | Type(Type), | 72 | Type(Type), |
73 | } | 73 | } |
74 | impl_froms!( | 74 | impl_froms!(ModuleDef: Module, Function, Struct, Enum, EnumVariant, Const, Static, Trait, Type); |
75 | ModuleDef: Module, | ||
76 | Function, | ||
77 | Struct, | ||
78 | Enum, | ||
79 | EnumVariant, | ||
80 | Const, | ||
81 | Static, | ||
82 | Trait, | ||
83 | Type | ||
84 | ); | ||
85 | 75 | ||
86 | pub enum ModuleSource { | 76 | pub enum ModuleSource { |
87 | SourceFile(TreeArc<ast::SourceFile>), | 77 | SourceFile(TreeArc<ast::SourceFile>), |
@@ -90,13 +80,8 @@ pub enum ModuleSource { | |||
90 | 80 | ||
91 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] | 81 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] |
92 | pub enum Problem { | 82 | pub enum Problem { |
93 | UnresolvedModule { | 83 | UnresolvedModule { candidate: RelativePathBuf }, |
94 | candidate: RelativePathBuf, | 84 | NotDirOwner { move_to: RelativePathBuf, candidate: RelativePathBuf }, |
95 | }, | ||
96 | NotDirOwner { | ||
97 | move_to: RelativePathBuf, | ||
98 | candidate: RelativePathBuf, | ||
99 | }, | ||
100 | } | 85 | } |
101 | 86 | ||
102 | impl Module { | 87 | impl Module { |
@@ -187,8 +172,7 @@ impl Module { | |||
187 | 172 | ||
188 | impl Docs for Module { | 173 | impl Docs for Module { |
189 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> { | 174 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> { |
190 | self.declaration_source(db) | 175 | self.declaration_source(db).and_then(|it| docs_from_ast(&*it.1)) |
191 | .and_then(|it| docs_from_ast(&*it.1)) | ||
192 | } | 176 | } |
193 | } | 177 | } |
194 | 178 | ||
@@ -206,9 +190,7 @@ pub enum FieldSource { | |||
206 | 190 | ||
207 | impl StructField { | 191 | impl StructField { |
208 | pub fn name(&self, db: &impl HirDatabase) -> Name { | 192 | pub fn name(&self, db: &impl HirDatabase) -> Name { |
209 | self.parent.variant_data(db).fields().unwrap()[self.id] | 193 | self.parent.variant_data(db).fields().unwrap()[self.id].name.clone() |
210 | .name | ||
211 | .clone() | ||
212 | } | 194 | } |
213 | 195 | ||
214 | pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, FieldSource) { | 196 | pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, FieldSource) { |
@@ -257,10 +239,7 @@ impl Struct { | |||
257 | .fields() | 239 | .fields() |
258 | .into_iter() | 240 | .into_iter() |
259 | .flat_map(|it| it.iter()) | 241 | .flat_map(|it| it.iter()) |
260 | .map(|(id, _)| StructField { | 242 | .map(|(id, _)| StructField { parent: (*self).into(), id }) |
261 | parent: (*self).into(), | ||
262 | id, | ||
263 | }) | ||
264 | .collect() | 243 | .collect() |
265 | } | 244 | } |
266 | 245 | ||
@@ -271,10 +250,7 @@ impl Struct { | |||
271 | .into_iter() | 250 | .into_iter() |
272 | .flat_map(|it| it.iter()) | 251 | .flat_map(|it| it.iter()) |
273 | .find(|(_id, data)| data.name == *name) | 252 | .find(|(_id, data)| data.name == *name) |
274 | .map(|(id, _)| StructField { | 253 | .map(|(id, _)| StructField { parent: (*self).into(), id }) |
275 | parent: (*self).into(), | ||
276 | id, | ||
277 | }) | ||
278 | } | 254 | } |
279 | 255 | ||
280 | pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { | 256 | pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { |
@@ -292,11 +268,7 @@ impl Struct { | |||
292 | let r = self.module(db).resolver(db); | 268 | let r = self.module(db).resolver(db); |
293 | // ...and add generic params, if present | 269 | // ...and add generic params, if present |
294 | let p = self.generic_params(db); | 270 | let p = self.generic_params(db); |
295 | let r = if !p.params.is_empty() { | 271 | let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r }; |
296 | r.push_generic_params_scope(p) | ||
297 | } else { | ||
298 | r | ||
299 | }; | ||
300 | r | 272 | r |
301 | } | 273 | } |
302 | } | 274 | } |
@@ -356,11 +328,7 @@ impl Enum { | |||
356 | let r = self.module(db).resolver(db); | 328 | let r = self.module(db).resolver(db); |
357 | // ...and add generic params, if present | 329 | // ...and add generic params, if present |
358 | let p = self.generic_params(db); | 330 | let p = self.generic_params(db); |
359 | let r = if !p.params.is_empty() { | 331 | let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r }; |
360 | r.push_generic_params_scope(p) | ||
361 | } else { | ||
362 | r | ||
363 | }; | ||
364 | r | 332 | r |
365 | } | 333 | } |
366 | } | 334 | } |
@@ -400,10 +368,7 @@ impl EnumVariant { | |||
400 | .fields() | 368 | .fields() |
401 | .into_iter() | 369 | .into_iter() |
402 | .flat_map(|it| it.iter()) | 370 | .flat_map(|it| it.iter()) |
403 | .map(|(id, _)| StructField { | 371 | .map(|(id, _)| StructField { parent: (*self).into(), id }) |
404 | parent: (*self).into(), | ||
405 | id, | ||
406 | }) | ||
407 | .collect() | 372 | .collect() |
408 | } | 373 | } |
409 | 374 | ||
@@ -413,10 +378,7 @@ impl EnumVariant { | |||
413 | .into_iter() | 378 | .into_iter() |
414 | .flat_map(|it| it.iter()) | 379 | .flat_map(|it| it.iter()) |
415 | .find(|(_id, data)| data.name == *name) | 380 | .find(|(_id, data)| data.name == *name) |
416 | .map(|(id, _)| StructField { | 381 | .map(|(id, _)| StructField { parent: (*self).into(), id }) |
417 | parent: (*self).into(), | ||
418 | id, | ||
419 | }) | ||
420 | } | 382 | } |
421 | } | 383 | } |
422 | 384 | ||
@@ -488,10 +450,7 @@ impl Function { | |||
488 | pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping { | 450 | pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping { |
489 | let scopes = db.expr_scopes(*self); | 451 | let scopes = db.expr_scopes(*self); |
490 | let syntax_mapping = db.body_syntax_mapping(*self); | 452 | let syntax_mapping = db.body_syntax_mapping(*self); |
491 | ScopesWithSyntaxMapping { | 453 | ScopesWithSyntaxMapping { scopes, syntax_mapping } |
492 | scopes, | ||
493 | syntax_mapping, | ||
494 | } | ||
495 | } | 454 | } |
496 | 455 | ||
497 | pub fn signature(&self, db: &impl HirDatabase) -> Arc<FnSignature> { | 456 | pub fn signature(&self, db: &impl HirDatabase) -> Arc<FnSignature> { |
@@ -516,11 +475,7 @@ impl Function { | |||
516 | .unwrap_or_else(|| self.module(db).resolver(db)); | 475 | .unwrap_or_else(|| self.module(db).resolver(db)); |
517 | // ...and add generic params, if present | 476 | // ...and add generic params, if present |
518 | let p = self.generic_params(db); | 477 | let p = self.generic_params(db); |
519 | let r = if !p.params.is_empty() { | 478 | let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r }; |
520 | r.push_generic_params_scope(p) | ||
521 | } else { | ||
522 | r | ||
523 | }; | ||
524 | r | 479 | r |
525 | } | 480 | } |
526 | } | 481 | } |