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