2019-11-28 15:05:28 +00:00
|
|
|
//! Utilities for mapping between hir IDs and the surface syntax.
|
|
|
|
|
|
|
|
use hir_expand::InFile;
|
|
|
|
use ra_arena::map::ArenaMap;
|
2019-12-20 12:58:09 +00:00
|
|
|
use ra_syntax::AstNode;
|
2019-11-28 15:05:28 +00:00
|
|
|
|
2019-12-20 12:58:09 +00:00
|
|
|
use crate::{db::DefDatabase, AssocItemLoc, ItemLoc};
|
2019-11-28 15:05:28 +00:00
|
|
|
|
|
|
|
pub trait HasSource {
|
|
|
|
type Value;
|
2020-03-13 15:05:46 +00:00
|
|
|
fn source(&self, db: &dyn DefDatabase) -> InFile<Self::Value>;
|
2019-11-28 15:05:28 +00:00
|
|
|
}
|
|
|
|
|
2019-12-20 12:58:09 +00:00
|
|
|
impl<N: AstNode> HasSource for AssocItemLoc<N> {
|
|
|
|
type Value = N;
|
2019-11-28 15:05:28 +00:00
|
|
|
|
2020-03-13 15:05:46 +00:00
|
|
|
fn source(&self, db: &dyn DefDatabase) -> InFile<N> {
|
|
|
|
let node = self.ast_id.to_node(db.upcast());
|
2019-11-28 15:05:28 +00:00
|
|
|
InFile::new(self.ast_id.file_id, node)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-20 12:58:09 +00:00
|
|
|
impl<N: AstNode> HasSource for ItemLoc<N> {
|
|
|
|
type Value = N;
|
2019-11-28 15:05:28 +00:00
|
|
|
|
2020-03-13 15:05:46 +00:00
|
|
|
fn source(&self, db: &dyn DefDatabase) -> InFile<N> {
|
|
|
|
let node = self.ast_id.to_node(db.upcast());
|
2019-12-12 14:11:57 +00:00
|
|
|
InFile::new(self.ast_id.file_id, node)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-28 15:05:28 +00:00
|
|
|
pub trait HasChildSource {
|
|
|
|
type ChildId;
|
|
|
|
type Value;
|
2020-03-13 15:05:46 +00:00
|
|
|
fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;
|
2019-11-28 15:05:28 +00:00
|
|
|
}
|