aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/lib.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-23 11:44:43 +0000
committerAleksey Kladov <[email protected]>2019-11-23 11:49:45 +0000
commitfc1e543f7abb69b8cab308410fa0a127950ee1c5 (patch)
tree5e30f4e18a0ea83215fd48776f372546dece9431 /crates/ra_hir_def/src/lib.rs
parent958862093e83083b188427246323047a2c9e7bab (diff)
Get rid of DefDatabase2
Diffstat (limited to 'crates/ra_hir_def/src/lib.rs')
-rw-r--r--crates/ra_hir_def/src/lib.rs45
1 files changed, 21 insertions, 24 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 1ba7c7ee3..1b2bc6f45 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -48,7 +48,7 @@ pub enum ModuleSource {
48 48
49impl ModuleSource { 49impl ModuleSource {
50 pub fn new( 50 pub fn new(
51 db: &impl db::DefDatabase2, 51 db: &impl db::DefDatabase,
52 file_id: Option<FileId>, 52 file_id: Option<FileId>,
53 decl_id: Option<AstId<ast::Module>>, 53 decl_id: Option<AstId<ast::Module>>,
54 ) -> ModuleSource { 54 ) -> ModuleSource {
@@ -67,10 +67,7 @@ impl ModuleSource {
67 } 67 }
68 68
69 // FIXME: this methods do not belong here 69 // FIXME: this methods do not belong here
70 pub fn from_position( 70 pub fn from_position(db: &impl db::DefDatabase, position: ra_db::FilePosition) -> ModuleSource {
71 db: &impl db::DefDatabase2,
72 position: ra_db::FilePosition,
73 ) -> ModuleSource {
74 let parse = db.parse(position.file_id); 71 let parse = db.parse(position.file_id);
75 match &ra_syntax::algo::find_node_at_offset::<ast::Module>( 72 match &ra_syntax::algo::find_node_at_offset::<ast::Module>(
76 parse.tree().syntax(), 73 parse.tree().syntax(),
@@ -84,7 +81,7 @@ impl ModuleSource {
84 } 81 }
85 } 82 }
86 83
87 pub fn from_child_node(db: &impl db::DefDatabase2, child: Source<&SyntaxNode>) -> ModuleSource { 84 pub fn from_child_node(db: &impl db::DefDatabase, child: Source<&SyntaxNode>) -> ModuleSource {
88 if let Some(m) = 85 if let Some(m) =
89 child.value.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) 86 child.value.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi())
90 { 87 {
@@ -96,7 +93,7 @@ impl ModuleSource {
96 } 93 }
97 } 94 }
98 95
99 pub fn from_file_id(db: &impl db::DefDatabase2, file_id: FileId) -> ModuleSource { 96 pub fn from_file_id(db: &impl db::DefDatabase, file_id: FileId) -> ModuleSource {
100 let source_file = db.parse(file_id).tree(); 97 let source_file = db.parse(file_id).tree();
101 ModuleSource::SourceFile(source_file) 98 ModuleSource::SourceFile(source_file)
102 } 99 }
@@ -211,14 +208,14 @@ pub struct FunctionLoc {
211 208
212impl Intern for FunctionLoc { 209impl Intern for FunctionLoc {
213 type ID = FunctionId; 210 type ID = FunctionId;
214 fn intern(self, db: &impl db::DefDatabase2) -> FunctionId { 211 fn intern(self, db: &impl db::DefDatabase) -> FunctionId {
215 db.intern_function(self) 212 db.intern_function(self)
216 } 213 }
217} 214}
218 215
219impl Lookup for FunctionId { 216impl Lookup for FunctionId {
220 type Data = FunctionLoc; 217 type Data = FunctionLoc;
221 fn lookup(&self, db: &impl db::DefDatabase2) -> FunctionLoc { 218 fn lookup(&self, db: &impl db::DefDatabase) -> FunctionLoc {
222 db.lookup_intern_function(*self) 219 db.lookup_intern_function(*self)
223 } 220 }
224} 221}
@@ -301,14 +298,14 @@ pub struct ConstLoc {
301 298
302impl Intern for ConstLoc { 299impl Intern for ConstLoc {
303 type ID = ConstId; 300 type ID = ConstId;
304 fn intern(self, db: &impl db::DefDatabase2) -> ConstId { 301 fn intern(self, db: &impl db::DefDatabase) -> ConstId {
305 db.intern_const(self) 302 db.intern_const(self)
306 } 303 }
307} 304}
308 305
309impl Lookup for ConstId { 306impl Lookup for ConstId {
310 type Data = ConstLoc; 307 type Data = ConstLoc;
311 fn lookup(&self, db: &impl db::DefDatabase2) -> ConstLoc { 308 fn lookup(&self, db: &impl db::DefDatabase) -> ConstLoc {
312 db.lookup_intern_const(*self) 309 db.lookup_intern_const(*self)
313 } 310 }
314} 311}
@@ -349,14 +346,14 @@ pub struct TypeAliasLoc {
349 346
350impl Intern for TypeAliasLoc { 347impl Intern for TypeAliasLoc {
351 type ID = TypeAliasId; 348 type ID = TypeAliasId;
352 fn intern(self, db: &impl db::DefDatabase2) -> TypeAliasId { 349 fn intern(self, db: &impl db::DefDatabase) -> TypeAliasId {
353 db.intern_type_alias(self) 350 db.intern_type_alias(self)
354 } 351 }
355} 352}
356 353
357impl Lookup for TypeAliasId { 354impl Lookup for TypeAliasId {
358 type Data = TypeAliasLoc; 355 type Data = TypeAliasLoc;
359 fn lookup(&self, db: &impl db::DefDatabase2) -> TypeAliasLoc { 356 fn lookup(&self, db: &impl db::DefDatabase) -> TypeAliasLoc {
360 db.lookup_intern_type_alias(*self) 357 db.lookup_intern_type_alias(*self)
361 } 358 }
362} 359}
@@ -510,20 +507,20 @@ impl_froms!(
510 507
511trait Intern { 508trait Intern {
512 type ID; 509 type ID;
513 fn intern(self, db: &impl db::DefDatabase2) -> Self::ID; 510 fn intern(self, db: &impl db::DefDatabase) -> Self::ID;
514} 511}
515 512
516pub trait Lookup { 513pub trait Lookup {
517 type Data; 514 type Data;
518 fn lookup(&self, db: &impl db::DefDatabase2) -> Self::Data; 515 fn lookup(&self, db: &impl db::DefDatabase) -> Self::Data;
519} 516}
520 517
521pub trait HasModule { 518pub trait HasModule {
522 fn module(&self, db: &impl db::DefDatabase2) -> ModuleId; 519 fn module(&self, db: &impl db::DefDatabase) -> ModuleId;
523} 520}
524 521
525impl HasModule for FunctionLoc { 522impl HasModule for FunctionLoc {
526 fn module(&self, db: &impl db::DefDatabase2) -> ModuleId { 523 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
527 match self.container { 524 match self.container {
528 ContainerId::ModuleId(it) => it, 525 ContainerId::ModuleId(it) => it,
529 ContainerId::ImplId(it) => it.module(db), 526 ContainerId::ImplId(it) => it.module(db),
@@ -533,7 +530,7 @@ impl HasModule for FunctionLoc {
533} 530}
534 531
535impl HasModule for TypeAliasLoc { 532impl HasModule for TypeAliasLoc {
536 fn module(&self, db: &impl db::DefDatabase2) -> ModuleId { 533 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
537 match self.container { 534 match self.container {
538 ContainerId::ModuleId(it) => it, 535 ContainerId::ModuleId(it) => it,
539 ContainerId::ImplId(it) => it.module(db), 536 ContainerId::ImplId(it) => it.module(db),
@@ -543,7 +540,7 @@ impl HasModule for TypeAliasLoc {
543} 540}
544 541
545impl HasModule for ConstLoc { 542impl HasModule for ConstLoc {
546 fn module(&self, db: &impl db::DefDatabase2) -> ModuleId { 543 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
547 match self.container { 544 match self.container {
548 ContainerId::ModuleId(it) => it, 545 ContainerId::ModuleId(it) => it,
549 ContainerId::ImplId(it) => it.module(db), 546 ContainerId::ImplId(it) => it.module(db),
@@ -554,13 +551,13 @@ impl HasModule for ConstLoc {
554 551
555pub trait HasSource { 552pub trait HasSource {
556 type Value; 553 type Value;
557 fn source(&self, db: &impl db::DefDatabase2) -> Source<Self::Value>; 554 fn source(&self, db: &impl db::DefDatabase) -> Source<Self::Value>;
558} 555}
559 556
560impl HasSource for FunctionLoc { 557impl HasSource for FunctionLoc {
561 type Value = ast::FnDef; 558 type Value = ast::FnDef;
562 559
563 fn source(&self, db: &impl db::DefDatabase2) -> Source<ast::FnDef> { 560 fn source(&self, db: &impl db::DefDatabase) -> Source<ast::FnDef> {
564 let node = self.ast_id.to_node(db); 561 let node = self.ast_id.to_node(db);
565 Source::new(self.ast_id.file_id(), node) 562 Source::new(self.ast_id.file_id(), node)
566 } 563 }
@@ -569,7 +566,7 @@ impl HasSource for FunctionLoc {
569impl HasSource for TypeAliasLoc { 566impl HasSource for TypeAliasLoc {
570 type Value = ast::TypeAliasDef; 567 type Value = ast::TypeAliasDef;
571 568
572 fn source(&self, db: &impl db::DefDatabase2) -> Source<ast::TypeAliasDef> { 569 fn source(&self, db: &impl db::DefDatabase) -> Source<ast::TypeAliasDef> {
573 let node = self.ast_id.to_node(db); 570 let node = self.ast_id.to_node(db);
574 Source::new(self.ast_id.file_id(), node) 571 Source::new(self.ast_id.file_id(), node)
575 } 572 }
@@ -578,7 +575,7 @@ impl HasSource for TypeAliasLoc {
578impl HasSource for ConstLoc { 575impl HasSource for ConstLoc {
579 type Value = ast::ConstDef; 576 type Value = ast::ConstDef;
580 577
581 fn source(&self, db: &impl db::DefDatabase2) -> Source<ast::ConstDef> { 578 fn source(&self, db: &impl db::DefDatabase) -> Source<ast::ConstDef> {
582 let node = self.ast_id.to_node(db); 579 let node = self.ast_id.to_node(db);
583 Source::new(self.ast_id.file_id(), node) 580 Source::new(self.ast_id.file_id(), node)
584 } 581 }
@@ -589,6 +586,6 @@ pub trait HasChildSource {
589 type Value; 586 type Value;
590 fn child_source( 587 fn child_source(
591 &self, 588 &self,
592 db: &impl db::DefDatabase2, 589 db: &impl db::DefDatabase,
593 ) -> Source<ArenaMap<Self::ChildId, Self::Value>>; 590 ) -> Source<ArenaMap<Self::ChildId, Self::Value>>;
594} 591}