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;
|
|
|
|
use ra_syntax::ast;
|
|
|
|
|
2019-12-12 13:09:13 +00:00
|
|
|
use crate::{db::DefDatabase, ConstLoc, FunctionLoc, ImplLoc, StaticLoc, TypeAliasLoc};
|
2019-11-28 15:05:28 +00:00
|
|
|
|
|
|
|
pub trait HasSource {
|
|
|
|
type Value;
|
|
|
|
fn source(&self, db: &impl DefDatabase) -> InFile<Self::Value>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HasSource for FunctionLoc {
|
|
|
|
type Value = ast::FnDef;
|
|
|
|
|
|
|
|
fn source(&self, db: &impl DefDatabase) -> InFile<ast::FnDef> {
|
|
|
|
let node = self.ast_id.to_node(db);
|
|
|
|
InFile::new(self.ast_id.file_id, node)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HasSource for TypeAliasLoc {
|
|
|
|
type Value = ast::TypeAliasDef;
|
|
|
|
|
|
|
|
fn source(&self, db: &impl DefDatabase) -> InFile<ast::TypeAliasDef> {
|
|
|
|
let node = self.ast_id.to_node(db);
|
|
|
|
InFile::new(self.ast_id.file_id, node)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HasSource for ConstLoc {
|
|
|
|
type Value = ast::ConstDef;
|
|
|
|
|
|
|
|
fn source(&self, db: &impl DefDatabase) -> InFile<ast::ConstDef> {
|
|
|
|
let node = self.ast_id.to_node(db);
|
|
|
|
InFile::new(self.ast_id.file_id, node)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HasSource for StaticLoc {
|
|
|
|
type Value = ast::StaticDef;
|
|
|
|
|
|
|
|
fn source(&self, db: &impl DefDatabase) -> InFile<ast::StaticDef> {
|
|
|
|
let node = self.ast_id.to_node(db);
|
|
|
|
InFile::new(self.ast_id.file_id, node)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-12 13:09:13 +00:00
|
|
|
impl HasSource for ImplLoc {
|
|
|
|
type Value = ast::ImplBlock;
|
|
|
|
|
|
|
|
fn source(&self, db: &impl DefDatabase) -> InFile<ast::ImplBlock> {
|
|
|
|
let node = self.ast_id.to_node(db);
|
|
|
|
InFile::new(self.ast_id.file_id, node)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-28 15:05:28 +00:00
|
|
|
pub trait HasChildSource {
|
|
|
|
type ChildId;
|
|
|
|
type Value;
|
|
|
|
fn child_source(&self, db: &impl DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;
|
|
|
|
}
|