diff options
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index f59a60c07..905615127 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -16,6 +16,7 @@ use crate::{ | |||
16 | code_model_impl::def_id_to_ast, | 16 | code_model_impl::def_id_to_ast, |
17 | docs::{Documentation, Docs, docs_from_ast}, | 17 | docs::{Documentation, Docs, docs_from_ast}, |
18 | module_tree::ModuleId, | 18 | module_tree::ModuleId, |
19 | ids::FunctionId, | ||
19 | }; | 20 | }; |
20 | 21 | ||
21 | /// hir::Crate describes a single crate. It's the main interface with which | 22 | /// hir::Crate describes a single crate. It's the main interface with which |
@@ -49,7 +50,6 @@ pub enum Def { | |||
49 | Struct(Struct), | 50 | Struct(Struct), |
50 | Enum(Enum), | 51 | Enum(Enum), |
51 | EnumVariant(EnumVariant), | 52 | EnumVariant(EnumVariant), |
52 | Function(Function), | ||
53 | Const(Const), | 53 | Const(Const), |
54 | Static(Static), | 54 | Static(Static), |
55 | Trait(Trait), | 55 | Trait(Trait), |
@@ -67,6 +67,7 @@ pub struct Module { | |||
67 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 67 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
68 | pub enum ModuleDef { | 68 | pub enum ModuleDef { |
69 | Module(Module), | 69 | Module(Module), |
70 | Function(Function), | ||
70 | Def(DefId), | 71 | Def(DefId), |
71 | } | 72 | } |
72 | 73 | ||
@@ -76,6 +77,12 @@ impl Into<ModuleDef> for Module { | |||
76 | } | 77 | } |
77 | } | 78 | } |
78 | 79 | ||
80 | impl Into<ModuleDef> for Function { | ||
81 | fn into(self) -> ModuleDef { | ||
82 | ModuleDef::Function(self) | ||
83 | } | ||
84 | } | ||
85 | |||
79 | impl Into<ModuleDef> for DefId { | 86 | impl Into<ModuleDef> for DefId { |
80 | fn into(self) -> ModuleDef { | 87 | fn into(self) -> ModuleDef { |
81 | ModuleDef::Def(self) | 88 | ModuleDef::Def(self) |
@@ -225,7 +232,7 @@ impl Struct { | |||
225 | } | 232 | } |
226 | 233 | ||
227 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { | 234 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { |
228 | db.generic_params(self.def_id) | 235 | db.generic_params(self.def_id.into()) |
229 | } | 236 | } |
230 | } | 237 | } |
231 | 238 | ||
@@ -262,7 +269,7 @@ impl Enum { | |||
262 | } | 269 | } |
263 | 270 | ||
264 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { | 271 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { |
265 | db.generic_params(self.def_id) | 272 | db.generic_params(self.def_id.into()) |
266 | } | 273 | } |
267 | } | 274 | } |
268 | 275 | ||
@@ -320,9 +327,9 @@ impl Docs for EnumVariant { | |||
320 | } | 327 | } |
321 | } | 328 | } |
322 | 329 | ||
323 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 330 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
324 | pub struct Function { | 331 | pub struct Function { |
325 | pub(crate) def_id: DefId, | 332 | pub(crate) id: FunctionId, |
326 | } | 333 | } |
327 | 334 | ||
328 | pub use crate::code_model_impl::function::ScopeEntryWithSyntax; | 335 | pub use crate::code_model_impl::function::ScopeEntryWithSyntax; |
@@ -359,21 +366,17 @@ impl FnSignature { | |||
359 | } | 366 | } |
360 | 367 | ||
361 | impl Function { | 368 | impl Function { |
362 | pub fn def_id(&self) -> DefId { | ||
363 | self.def_id | ||
364 | } | ||
365 | |||
366 | pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::FnDef>) { | 369 | pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::FnDef>) { |
367 | def_id_to_ast(db, self.def_id) | 370 | self.id.loc(db).source(db) |
368 | } | 371 | } |
369 | 372 | ||
370 | pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Arc<BodySyntaxMapping> { | 373 | pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Arc<BodySyntaxMapping> { |
371 | db.body_syntax_mapping(self.def_id) | 374 | db.body_syntax_mapping(*self) |
372 | } | 375 | } |
373 | 376 | ||
374 | pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping { | 377 | pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping { |
375 | let scopes = db.fn_scopes(self.def_id); | 378 | let scopes = db.fn_scopes(*self); |
376 | let syntax_mapping = db.body_syntax_mapping(self.def_id); | 379 | let syntax_mapping = db.body_syntax_mapping(*self); |
377 | ScopesWithSyntaxMapping { | 380 | ScopesWithSyntaxMapping { |
378 | scopes, | 381 | scopes, |
379 | syntax_mapping, | 382 | syntax_mapping, |
@@ -381,15 +384,15 @@ impl Function { | |||
381 | } | 384 | } |
382 | 385 | ||
383 | pub fn signature(&self, db: &impl HirDatabase) -> Arc<FnSignature> { | 386 | pub fn signature(&self, db: &impl HirDatabase) -> Arc<FnSignature> { |
384 | db.fn_signature(self.def_id) | 387 | db.fn_signature(*self) |
385 | } | 388 | } |
386 | 389 | ||
387 | pub fn infer(&self, db: &impl HirDatabase) -> Arc<InferenceResult> { | 390 | pub fn infer(&self, db: &impl HirDatabase) -> Arc<InferenceResult> { |
388 | db.infer(self.def_id) | 391 | db.infer(*self) |
389 | } | 392 | } |
390 | 393 | ||
391 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { | 394 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { |
392 | db.generic_params(self.def_id) | 395 | db.generic_params((*self).into()) |
393 | } | 396 | } |
394 | } | 397 | } |
395 | 398 | ||
@@ -456,7 +459,7 @@ impl Trait { | |||
456 | } | 459 | } |
457 | 460 | ||
458 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { | 461 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { |
459 | db.generic_params(self.def_id) | 462 | db.generic_params(self.def_id.into()) |
460 | } | 463 | } |
461 | } | 464 | } |
462 | 465 | ||
@@ -481,7 +484,7 @@ impl Type { | |||
481 | } | 484 | } |
482 | 485 | ||
483 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { | 486 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { |
484 | db.generic_params(self.def_id) | 487 | db.generic_params(self.def_id.into()) |
485 | } | 488 | } |
486 | } | 489 | } |
487 | 490 | ||