diff options
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index e4008058c..9405aa8ad 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -10,12 +10,13 @@ use crate::{ | |||
10 | nameres::{ModuleScope, lower::ImportId}, | 10 | nameres::{ModuleScope, lower::ImportId}, |
11 | db::HirDatabase, | 11 | db::HirDatabase, |
12 | expr::BodySyntaxMapping, | 12 | expr::BodySyntaxMapping, |
13 | ty::InferenceResult, | 13 | ty::{InferenceResult}, |
14 | adt::{EnumVariantId, StructFieldId, VariantDef}, | 14 | adt::{EnumVariantId, StructFieldId, VariantDef}, |
15 | generics::GenericParams, | 15 | generics::GenericParams, |
16 | docs::{Documentation, Docs, docs_from_ast}, | 16 | docs::{Documentation, Docs, docs_from_ast}, |
17 | module_tree::ModuleId, | 17 | module_tree::ModuleId, |
18 | ids::{FunctionId, StructId, EnumId, AstItemDef, ConstId, StaticId, TraitId, TypeId}, | 18 | ids::{FunctionId, StructId, EnumId, AstItemDef, ConstId, StaticId, TraitId, TypeId}, |
19 | impl_block::ImplId, | ||
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 |
@@ -51,7 +52,7 @@ pub enum Def { | |||
51 | 52 | ||
52 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 53 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
53 | pub struct Module { | 54 | pub struct Module { |
54 | pub(crate) krate: CrateId, | 55 | pub(crate) krate: Crate, |
55 | pub(crate) module_id: ModuleId, | 56 | pub(crate) module_id: ModuleId, |
56 | } | 57 | } |
57 | 58 | ||
@@ -126,9 +127,14 @@ impl Module { | |||
126 | self.import_source_impl(db, import) | 127 | self.import_source_impl(db, import) |
127 | } | 128 | } |
128 | 129 | ||
130 | /// Returns the syntax of the impl block in this module | ||
131 | pub fn impl_source(&self, db: &impl HirDatabase, impl_id: ImplId) -> TreeArc<ast::ImplBlock> { | ||
132 | self.impl_source_impl(db, impl_id) | ||
133 | } | ||
134 | |||
129 | /// Returns the crate this module is part of. | 135 | /// Returns the crate this module is part of. |
130 | pub fn krate(&self, db: &impl HirDatabase) -> Option<Crate> { | 136 | pub fn krate(&self, _db: &impl HirDatabase) -> Option<Crate> { |
131 | self.krate_impl(db) | 137 | Some(self.krate) |
132 | } | 138 | } |
133 | 139 | ||
134 | /// Topmost parent of this module. Every module has a `crate_root`, but some | 140 | /// Topmost parent of this module. Every module has a `crate_root`, but some |
@@ -272,6 +278,10 @@ impl Struct { | |||
272 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { | 278 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { |
273 | db.generic_params((*self).into()) | 279 | db.generic_params((*self).into()) |
274 | } | 280 | } |
281 | |||
282 | pub fn ty(&self, db: &impl HirDatabase) -> Ty { | ||
283 | db.type_for_def((*self).into()) | ||
284 | } | ||
275 | } | 285 | } |
276 | 286 | ||
277 | impl Docs for Struct { | 287 | impl Docs for Struct { |
@@ -317,6 +327,10 @@ impl Enum { | |||
317 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { | 327 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { |
318 | db.generic_params((*self).into()) | 328 | db.generic_params((*self).into()) |
319 | } | 329 | } |
330 | |||
331 | pub fn ty(&self, db: &impl HirDatabase) -> Ty { | ||
332 | db.type_for_def((*self).into()) | ||
333 | } | ||
320 | } | 334 | } |
321 | 335 | ||
322 | impl Docs for Enum { | 336 | impl Docs for Enum { |
@@ -382,7 +396,7 @@ pub struct Function { | |||
382 | pub(crate) id: FunctionId, | 396 | pub(crate) id: FunctionId, |
383 | } | 397 | } |
384 | 398 | ||
385 | pub use crate::code_model_impl::function::ScopeEntryWithSyntax; | 399 | pub use crate::expr::ScopeEntryWithSyntax; |
386 | 400 | ||
387 | /// The declared signature of a function. | 401 | /// The declared signature of a function. |
388 | #[derive(Debug, Clone, PartialEq, Eq)] | 402 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -433,7 +447,7 @@ impl Function { | |||
433 | } | 447 | } |
434 | 448 | ||
435 | pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping { | 449 | pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping { |
436 | let scopes = db.fn_scopes(*self); | 450 | let scopes = db.expr_scopes(*self); |
437 | let syntax_mapping = db.body_syntax_mapping(*self); | 451 | let syntax_mapping = db.body_syntax_mapping(*self); |
438 | ScopesWithSyntaxMapping { | 452 | ScopesWithSyntaxMapping { |
439 | scopes, | 453 | scopes, |