diff options
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r-- | crates/ra_hir/src/ids.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 66adacc7d..4d6378e02 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -2,7 +2,7 @@ use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId}; | |||
2 | use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, SourceFile, AstNode, ast}; | 2 | use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, SourceFile, AstNode, ast}; |
3 | use ra_arena::{Arena, RawId, impl_arena_id}; | 3 | use ra_arena::{Arena, RawId, impl_arena_id}; |
4 | 4 | ||
5 | use crate::{HirDatabase, PerNs, ModuleId, Module, Def, Function, Struct, Enum}; | 5 | use crate::{HirDatabase, PerNs, ModuleId, Module, Def, Function, Struct, Enum, ImplBlock, Crate}; |
6 | 6 | ||
7 | /// hir makes a heavy use of ids: integer (u32) handlers to various things. You | 7 | /// hir makes a heavy use of ids: integer (u32) handlers to various things. You |
8 | /// can think of id as a pointer (but without a lifetime) or a file descriptor | 8 | /// can think of id as a pointer (but without a lifetime) or a file descriptor |
@@ -177,6 +177,18 @@ impl DefId { | |||
177 | let loc = self.loc(db); | 177 | let loc = self.loc(db); |
178 | Module::new(db, loc.source_root_id, loc.module_id) | 178 | Module::new(db, loc.source_root_id, loc.module_id) |
179 | } | 179 | } |
180 | |||
181 | /// Returns the containing crate. | ||
182 | pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> { | ||
183 | Ok(self.module(db)?.krate(db)) | ||
184 | } | ||
185 | |||
186 | /// Returns the containing impl block, if this is an impl item. | ||
187 | pub fn impl_block(self, db: &impl HirDatabase) -> Cancelable<Option<ImplBlock>> { | ||
188 | let loc = self.loc(db); | ||
189 | let module_impls = db.impls_in_module(loc.source_root_id, loc.module_id)?; | ||
190 | Ok(ImplBlock::containing(module_impls, self)) | ||
191 | } | ||
180 | } | 192 | } |
181 | 193 | ||
182 | impl DefLoc { | 194 | impl DefLoc { |