diff options
author | Aleksey Kladov <[email protected]> | 2019-06-11 14:40:49 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-06-11 16:28:51 +0100 |
commit | 36865adcb946d5567fb61d3547b78fc71df58b20 (patch) | |
tree | 4cec6a3d18de8242c334fe303717c1f2b1c42be1 /crates/ra_hir/src | |
parent | 2a1fe26b6d354dbbd1b3843d288d56e74fa00557 (diff) |
Introduce HasSource trait
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 26 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 2 |
2 files changed, 27 insertions, 1 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 63fdca55e..765850488 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -31,6 +31,11 @@ impl<T> From<(HirFileId, T)> for Source<T> { | |||
31 | } | 31 | } |
32 | } | 32 | } |
33 | 33 | ||
34 | pub trait HasSource { | ||
35 | type Ast; | ||
36 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<Self::Ast>; | ||
37 | } | ||
38 | |||
34 | /// hir::Crate describes a single crate. It's the main interface with which | 39 | /// hir::Crate describes a single crate. It's the main interface with which |
35 | /// a crate's dependencies interact. Mostly, it should be just a proxy for the | 40 | /// a crate's dependencies interact. Mostly, it should be just a proxy for the |
36 | /// root module. | 41 | /// root module. |
@@ -364,6 +369,13 @@ pub struct Struct { | |||
364 | pub(crate) id: StructId, | 369 | pub(crate) id: StructId, |
365 | } | 370 | } |
366 | 371 | ||
372 | impl HasSource for Struct { | ||
373 | type Ast = TreeArc<ast::StructDef>; | ||
374 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> { | ||
375 | self.id.source(db).into() | ||
376 | } | ||
377 | } | ||
378 | |||
367 | impl Struct { | 379 | impl Struct { |
368 | pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> { | 380 | pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> { |
369 | self.id.source(db).into() | 381 | self.id.source(db).into() |
@@ -422,6 +434,13 @@ pub struct Union { | |||
422 | pub(crate) id: StructId, | 434 | pub(crate) id: StructId, |
423 | } | 435 | } |
424 | 436 | ||
437 | impl HasSource for Union { | ||
438 | type Ast = TreeArc<ast::StructDef>; | ||
439 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> { | ||
440 | self.id.source(db).into() | ||
441 | } | ||
442 | } | ||
443 | |||
425 | impl Union { | 444 | impl Union { |
426 | pub fn source( | 445 | pub fn source( |
427 | self, | 446 | self, |
@@ -455,6 +474,13 @@ pub struct Enum { | |||
455 | pub(crate) id: EnumId, | 474 | pub(crate) id: EnumId, |
456 | } | 475 | } |
457 | 476 | ||
477 | impl HasSource for Enum { | ||
478 | type Ast = TreeArc<ast::EnumDef>; | ||
479 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> { | ||
480 | self.id.source(db).into() | ||
481 | } | ||
482 | } | ||
483 | |||
458 | impl Enum { | 484 | impl Enum { |
459 | pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> { | 485 | pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> { |
460 | self.id.source(db).into() | 486 | self.id.source(db).into() |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 90e3f1275..02f5f7f40 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -81,5 +81,5 @@ pub use self::code_model::{ | |||
81 | StructField, FieldSource, | 81 | StructField, FieldSource, |
82 | Static, Const, ConstSignature, | 82 | Static, Const, ConstSignature, |
83 | Trait, TypeAlias, MacroDef, Container, | 83 | Trait, TypeAlias, MacroDef, Container, |
84 | BuiltinType, Source, | 84 | BuiltinType, Source, HasSource, |
85 | }; | 85 | }; |