diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-01 14:31:23 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-01 14:31:23 +0000 |
commit | 2b5c226e86892113bcab478cdf4c9adaf1e7b2f6 (patch) | |
tree | 3904cb714292f3e1abe5081e4e516eea1b2568fa /crates/ra_hir/src/ids.rs | |
parent | 21c593593163c22b996f7c8bffe05b9708f5b2d0 (diff) | |
parent | 4dffdcf14abe0c79f9d7a9702be77958be1f75b1 (diff) |
Merge #718
718: split HirDatabase r=matklad a=csmoe
Closes #706
Co-authored-by: csmoe <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r-- | crates/ra_hir/src/ids.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 0e4dc6261..95678bf70 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -10,6 +10,7 @@ use ra_arena::{Arena, RawId, ArenaId, impl_arena_id}; | |||
10 | use crate::{ | 10 | use crate::{ |
11 | HirDatabase, | 11 | HirDatabase, |
12 | Module, | 12 | Module, |
13 | PersistentHirDatabase, | ||
13 | }; | 14 | }; |
14 | 15 | ||
15 | #[derive(Debug, Default)] | 16 | #[derive(Debug, Default)] |
@@ -62,7 +63,7 @@ pub struct HirFileId(HirFileIdRepr); | |||
62 | impl HirFileId { | 63 | impl HirFileId { |
63 | /// For macro-expansion files, returns the file original source file the | 64 | /// For macro-expansion files, returns the file original source file the |
64 | /// expansionoriginated from. | 65 | /// expansionoriginated from. |
65 | pub fn original_file(self, db: &impl HirDatabase) -> FileId { | 66 | pub fn original_file(self, db: &impl PersistentHirDatabase) -> FileId { |
66 | match self.0 { | 67 | match self.0 { |
67 | HirFileIdRepr::File(file_id) => file_id, | 68 | HirFileIdRepr::File(file_id) => file_id, |
68 | HirFileIdRepr::Macro(macro_call_id) => { | 69 | HirFileIdRepr::Macro(macro_call_id) => { |
@@ -86,7 +87,10 @@ impl HirFileId { | |||
86 | } | 87 | } |
87 | } | 88 | } |
88 | 89 | ||
89 | pub(crate) fn hir_parse(db: &impl HirDatabase, file_id: HirFileId) -> TreeArc<SourceFile> { | 90 | pub(crate) fn hir_parse( |
91 | db: &impl PersistentHirDatabase, | ||
92 | file_id: HirFileId, | ||
93 | ) -> TreeArc<SourceFile> { | ||
90 | match file_id.0 { | 94 | match file_id.0 { |
91 | HirFileIdRepr::File(file_id) => db.parse(file_id), | 95 | HirFileIdRepr::File(file_id) => db.parse(file_id), |
92 | HirFileIdRepr::Macro(m) => { | 96 | HirFileIdRepr::Macro(m) => { |
@@ -180,7 +184,7 @@ pub(crate) struct LocationCtx<DB> { | |||
180 | file_id: HirFileId, | 184 | file_id: HirFileId, |
181 | } | 185 | } |
182 | 186 | ||
183 | impl<'a, DB: HirDatabase> LocationCtx<&'a DB> { | 187 | impl<'a, DB: PersistentHirDatabase> LocationCtx<&'a DB> { |
184 | pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx<&'a DB> { | 188 | pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx<&'a DB> { |
185 | LocationCtx { | 189 | LocationCtx { |
186 | db, | 190 | db, |
@@ -199,7 +203,7 @@ impl<'a, DB: HirDatabase> LocationCtx<&'a DB> { | |||
199 | 203 | ||
200 | pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone { | 204 | pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone { |
201 | fn interner(interner: &HirInterner) -> &LocationIntener<ItemLoc<N>, Self>; | 205 | fn interner(interner: &HirInterner) -> &LocationIntener<ItemLoc<N>, Self>; |
202 | fn from_ast(ctx: LocationCtx<&impl HirDatabase>, ast: &N) -> Self { | 206 | fn from_ast(ctx: LocationCtx<&impl PersistentHirDatabase>, ast: &N) -> Self { |
203 | let items = ctx.db.file_items(ctx.file_id); | 207 | let items = ctx.db.file_items(ctx.file_id); |
204 | let raw = SourceItemId { | 208 | let raw = SourceItemId { |
205 | file_id: ctx.file_id, | 209 | file_id: ctx.file_id, |
@@ -213,7 +217,7 @@ pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone { | |||
213 | 217 | ||
214 | Self::interner(ctx.db.as_ref()).loc2id(&loc) | 218 | Self::interner(ctx.db.as_ref()).loc2id(&loc) |
215 | } | 219 | } |
216 | fn source(self, db: &impl HirDatabase) -> (HirFileId, TreeArc<N>) { | 220 | fn source(self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<N>) { |
217 | let int = Self::interner(db.as_ref()); | 221 | let int = Self::interner(db.as_ref()); |
218 | let loc = int.id2loc(self); | 222 | let loc = int.id2loc(self); |
219 | let syntax = db.file_item(loc.raw); | 223 | let syntax = db.file_item(loc.raw); |