Move source-related traits to a separate module
This commit is contained in:
parent
2c7f6b573e
commit
8f1f5a783a
@ -1,6 +1,9 @@
|
||||
//! FIXME: write short doc here
|
||||
|
||||
use hir_def::{AstItemDef, HasChildSource, HasSource as _, Lookup, VariantId};
|
||||
use hir_def::{
|
||||
src::{HasChildSource, HasSource as _},
|
||||
AstItemDef, Lookup, VariantId,
|
||||
};
|
||||
use hir_expand::either::Either;
|
||||
use ra_syntax::ast;
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
|
||||
|
||||
use crate::{
|
||||
db::DefDatabase, trace::Trace, type_ref::TypeRef, AstItemDef, EnumId, HasChildSource,
|
||||
db::DefDatabase, src::HasChildSource, trace::Trace, type_ref::TypeRef, AstItemDef, EnumId,
|
||||
LocalEnumVariantId, LocalStructFieldId, StructId, UnionId, VariantId,
|
||||
};
|
||||
|
||||
|
@ -11,7 +11,8 @@
|
||||
use tt::Subtree;
|
||||
|
||||
use crate::{
|
||||
db::DefDatabase, path::Path, AdtId, AstItemDef, AttrDefId, HasChildSource, HasSource, Lookup,
|
||||
db::DefDatabase, path::Path, src::HasChildSource, src::HasSource, AdtId, AstItemDef, AttrDefId,
|
||||
Lookup,
|
||||
};
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
||||
|
@ -17,7 +17,8 @@
|
||||
expr::{Expr, ExprId, Pat, PatId},
|
||||
nameres::CrateDefMap,
|
||||
path::Path,
|
||||
DefWithBodyId, HasModule, HasSource, Lookup, ModuleId,
|
||||
src::HasSource,
|
||||
DefWithBodyId, HasModule, Lookup, ModuleId,
|
||||
};
|
||||
|
||||
struct Expander {
|
||||
|
@ -10,9 +10,10 @@
|
||||
|
||||
use crate::{
|
||||
db::DefDatabase,
|
||||
src::HasSource,
|
||||
type_ref::{Mutability, TypeRef},
|
||||
AssocItemId, AstItemDef, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, HasSource,
|
||||
ImplId, Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc,
|
||||
AssocItemId, AstItemDef, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, ImplId,
|
||||
Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
@ -8,7 +8,11 @@
|
||||
use hir_expand::either::Either;
|
||||
use ra_syntax::ast;
|
||||
|
||||
use crate::{db::DefDatabase, AdtId, AstItemDef, AttrDefId, HasChildSource, HasSource, Lookup};
|
||||
use crate::{
|
||||
db::DefDatabase,
|
||||
src::{HasChildSource, HasSource},
|
||||
AdtId, AstItemDef, AttrDefId, Lookup,
|
||||
};
|
||||
|
||||
/// Holds documentation
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
@ -9,8 +9,9 @@
|
||||
|
||||
use crate::{
|
||||
db::DefDatabase,
|
||||
src::HasSource,
|
||||
type_ref::{TypeBound, TypeRef},
|
||||
AdtId, AstItemDef, ContainerId, GenericDefId, HasSource, Lookup,
|
||||
AdtId, AstItemDef, ContainerId, GenericDefId, Lookup,
|
||||
};
|
||||
|
||||
/// Data about a generic parameter (to a function, struct, impl, ...).
|
||||
|
@ -29,6 +29,8 @@
|
||||
mod trace;
|
||||
pub mod nameres;
|
||||
|
||||
pub mod src;
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_db;
|
||||
#[cfg(test)]
|
||||
@ -37,7 +39,7 @@
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, InFile, MacroDefId};
|
||||
use ra_arena::{impl_arena_id, map::ArenaMap, RawId};
|
||||
use ra_arena::{impl_arena_id, RawId};
|
||||
use ra_db::{impl_intern_key, salsa, CrateId};
|
||||
use ra_syntax::{ast, AstNode};
|
||||
|
||||
@ -514,53 +516,3 @@ fn module(&self, _db: &impl db::DefDatabase) -> ModuleId {
|
||||
self.container
|
||||
}
|
||||
}
|
||||
|
||||
pub trait HasSource {
|
||||
type Value;
|
||||
fn source(&self, db: &impl db::DefDatabase) -> InFile<Self::Value>;
|
||||
}
|
||||
|
||||
impl HasSource for FunctionLoc {
|
||||
type Value = ast::FnDef;
|
||||
|
||||
fn source(&self, db: &impl db::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 db::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 db::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 db::DefDatabase) -> InFile<ast::StaticDef> {
|
||||
let node = self.ast_id.to_node(db);
|
||||
InFile::new(self.ast_id.file_id, node)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait HasChildSource {
|
||||
type ChildId;
|
||||
type Value;
|
||||
fn child_source(
|
||||
&self,
|
||||
db: &impl db::DefDatabase,
|
||||
) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;
|
||||
}
|
||||
|
54
crates/ra_hir_def/src/src.rs
Normal file
54
crates/ra_hir_def/src/src.rs
Normal file
@ -0,0 +1,54 @@
|
||||
//! Utilities for mapping between hir IDs and the surface syntax.
|
||||
|
||||
use hir_expand::InFile;
|
||||
use ra_arena::map::ArenaMap;
|
||||
use ra_syntax::ast;
|
||||
|
||||
use crate::{db::DefDatabase, ConstLoc, FunctionLoc, StaticLoc, TypeAliasLoc};
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait HasChildSource {
|
||||
type ChildId;
|
||||
type Value;
|
||||
fn child_source(&self, db: &impl DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;
|
||||
}
|
@ -693,7 +693,7 @@ fn none() -> Self {
|
||||
}
|
||||
|
||||
mod diagnostics {
|
||||
use hir_def::{expr::ExprId, FunctionId, HasSource, Lookup};
|
||||
use hir_def::{expr::ExprId, src::HasSource, FunctionId, Lookup};
|
||||
use hir_expand::diagnostics::DiagnosticSink;
|
||||
|
||||
use crate::{db::HirDatabase, diagnostics::NoSuchField};
|
||||
|
Loading…
Reference in New Issue
Block a user