diff options
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r-- | crates/ra_hir/src/ids.rs | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 3d0a881c2..18401f865 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -10,7 +10,7 @@ use ra_arena::{Arena, RawId, ArenaId, impl_arena_id}; | |||
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | Module, | 12 | Module, |
13 | PersistentHirDatabase, | 13 | DefDatabase, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | #[derive(Debug, Default)] | 16 | #[derive(Debug, Default)] |
@@ -63,7 +63,7 @@ pub struct HirFileId(HirFileIdRepr); | |||
63 | impl HirFileId { | 63 | impl HirFileId { |
64 | /// For macro-expansion files, returns the file original source file the | 64 | /// For macro-expansion files, returns the file original source file the |
65 | /// expansion originated from. | 65 | /// expansion originated from. |
66 | pub fn original_file(self, db: &impl PersistentHirDatabase) -> FileId { | 66 | pub fn original_file(self, db: &impl DefDatabase) -> FileId { |
67 | match self.0 { | 67 | match self.0 { |
68 | HirFileIdRepr::File(file_id) => file_id, | 68 | HirFileIdRepr::File(file_id) => file_id, |
69 | HirFileIdRepr::Macro(macro_call_id) => { | 69 | HirFileIdRepr::Macro(macro_call_id) => { |
@@ -83,10 +83,7 @@ impl HirFileId { | |||
83 | } | 83 | } |
84 | } | 84 | } |
85 | 85 | ||
86 | pub(crate) fn hir_parse( | 86 | pub(crate) fn hir_parse(db: &impl DefDatabase, file_id: HirFileId) -> TreeArc<SourceFile> { |
87 | db: &impl PersistentHirDatabase, | ||
88 | file_id: HirFileId, | ||
89 | ) -> TreeArc<SourceFile> { | ||
90 | match file_id.0 { | 87 | match file_id.0 { |
91 | HirFileIdRepr::File(file_id) => db.parse(file_id), | 88 | HirFileIdRepr::File(file_id) => db.parse(file_id), |
92 | HirFileIdRepr::Macro(macro_call_id) => { | 89 | HirFileIdRepr::Macro(macro_call_id) => { |
@@ -97,10 +94,7 @@ impl HirFileId { | |||
97 | } | 94 | } |
98 | } | 95 | } |
99 | 96 | ||
100 | fn parse_macro( | 97 | fn parse_macro(db: &impl DefDatabase, macro_call_id: MacroCallId) -> Option<TreeArc<SourceFile>> { |
101 | db: &impl PersistentHirDatabase, | ||
102 | macro_call_id: MacroCallId, | ||
103 | ) -> Option<TreeArc<SourceFile>> { | ||
104 | let loc = macro_call_id.loc(db); | 98 | let loc = macro_call_id.loc(db); |
105 | let syntax = db.file_item(loc.source_item_id); | 99 | let syntax = db.file_item(loc.source_item_id); |
106 | let macro_call = ast::MacroCall::cast(&syntax).unwrap(); | 100 | let macro_call = ast::MacroCall::cast(&syntax).unwrap(); |
@@ -190,7 +184,7 @@ pub(crate) struct LocationCtx<DB> { | |||
190 | file_id: HirFileId, | 184 | file_id: HirFileId, |
191 | } | 185 | } |
192 | 186 | ||
193 | impl<'a, DB: PersistentHirDatabase> LocationCtx<&'a DB> { | 187 | impl<'a, DB: DefDatabase> LocationCtx<&'a DB> { |
194 | 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> { |
195 | LocationCtx { db, module, file_id } | 189 | LocationCtx { db, module, file_id } |
196 | } | 190 | } |
@@ -205,13 +199,13 @@ impl<'a, DB: PersistentHirDatabase> LocationCtx<&'a DB> { | |||
205 | 199 | ||
206 | pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone { | 200 | pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone { |
207 | fn interner(interner: &HirInterner) -> &LocationInterner<ItemLoc<N>, Self>; | 201 | fn interner(interner: &HirInterner) -> &LocationInterner<ItemLoc<N>, Self>; |
208 | fn from_ast(ctx: LocationCtx<&impl PersistentHirDatabase>, ast: &N) -> Self { | 202 | fn from_ast(ctx: LocationCtx<&impl DefDatabase>, ast: &N) -> Self { |
209 | let items = ctx.db.file_items(ctx.file_id); | 203 | let items = ctx.db.file_items(ctx.file_id); |
210 | let item_id = items.id_of(ctx.file_id, ast.syntax()); | 204 | let item_id = items.id_of(ctx.file_id, ast.syntax()); |
211 | Self::from_source_item_id_unchecked(ctx, item_id) | 205 | Self::from_source_item_id_unchecked(ctx, item_id) |
212 | } | 206 | } |
213 | fn from_source_item_id_unchecked( | 207 | fn from_source_item_id_unchecked( |
214 | ctx: LocationCtx<&impl PersistentHirDatabase>, | 208 | ctx: LocationCtx<&impl DefDatabase>, |
215 | item_id: SourceFileItemId, | 209 | item_id: SourceFileItemId, |
216 | ) -> Self { | 210 | ) -> Self { |
217 | let raw = SourceItemId { file_id: ctx.file_id, item_id }; | 211 | let raw = SourceItemId { file_id: ctx.file_id, item_id }; |
@@ -219,7 +213,7 @@ pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone { | |||
219 | 213 | ||
220 | Self::interner(ctx.db.as_ref()).loc2id(&loc) | 214 | Self::interner(ctx.db.as_ref()).loc2id(&loc) |
221 | } | 215 | } |
222 | fn source(self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<N>) { | 216 | fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<N>) { |
223 | let int = Self::interner(db.as_ref()); | 217 | let int = Self::interner(db.as_ref()); |
224 | let loc = int.id2loc(self); | 218 | let loc = int.id2loc(self); |
225 | let syntax = db.file_item(loc.raw); | 219 | let syntax = db.file_item(loc.raw); |
@@ -227,7 +221,7 @@ pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone { | |||
227 | N::cast(&syntax).unwrap_or_else(|| panic!("invalid ItemLoc: {:?}", loc.raw)).to_owned(); | 221 | N::cast(&syntax).unwrap_or_else(|| panic!("invalid ItemLoc: {:?}", loc.raw)).to_owned(); |
228 | (loc.raw.file_id, ast) | 222 | (loc.raw.file_id, ast) |
229 | } | 223 | } |
230 | fn module(self, db: &impl PersistentHirDatabase) -> Module { | 224 | fn module(self, db: &impl DefDatabase) -> Module { |
231 | let int = Self::interner(db.as_ref()); | 225 | let int = Self::interner(db.as_ref()); |
232 | let loc = int.id2loc(self); | 226 | let loc = int.id2loc(self); |
233 | loc.module | 227 | loc.module |
@@ -324,7 +318,7 @@ pub struct SourceFileItems { | |||
324 | 318 | ||
325 | impl SourceFileItems { | 319 | impl SourceFileItems { |
326 | pub(crate) fn file_items_query( | 320 | pub(crate) fn file_items_query( |
327 | db: &impl PersistentHirDatabase, | 321 | db: &impl DefDatabase, |
328 | file_id: HirFileId, | 322 | file_id: HirFileId, |
329 | ) -> Arc<SourceFileItems> { | 323 | ) -> Arc<SourceFileItems> { |
330 | let source_file = db.hir_parse(file_id); | 324 | let source_file = db.hir_parse(file_id); |
@@ -332,7 +326,7 @@ impl SourceFileItems { | |||
332 | } | 326 | } |
333 | 327 | ||
334 | pub(crate) fn file_item_query( | 328 | pub(crate) fn file_item_query( |
335 | db: &impl PersistentHirDatabase, | 329 | db: &impl DefDatabase, |
336 | source_item_id: SourceItemId, | 330 | source_item_id: SourceItemId, |
337 | ) -> TreeArc<SyntaxNode> { | 331 | ) -> TreeArc<SyntaxNode> { |
338 | let source_file = db.hir_parse(source_item_id.file_id); | 332 | let source_file = db.hir_parse(source_item_id.file_id); |