From 8f1f5a783a3ffd0afbf5b1fdf22ff9caf7fda928 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 28 Nov 2019 18:05:28 +0300 Subject: Move source-related traits to a separate module --- crates/ra_hir/src/code_model/src.rs | 5 +++- crates/ra_hir_def/src/adt.rs | 2 +- crates/ra_hir_def/src/attr.rs | 3 ++- crates/ra_hir_def/src/body.rs | 3 ++- crates/ra_hir_def/src/data.rs | 5 ++-- crates/ra_hir_def/src/docs.rs | 6 ++++- crates/ra_hir_def/src/generics.rs | 3 ++- crates/ra_hir_def/src/lib.rs | 54 +++---------------------------------- crates/ra_hir_def/src/src.rs | 54 +++++++++++++++++++++++++++++++++++++ crates/ra_hir_ty/src/infer.rs | 2 +- 10 files changed, 77 insertions(+), 60 deletions(-) create mode 100644 crates/ra_hir_def/src/src.rs diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index 9a755704f..2cf210349 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs @@ -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; diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index 3d21dedee..9ab829aab 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs @@ -11,7 +11,7 @@ use ra_arena::{map::ArenaMap, Arena}; 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, }; diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index 346019f88..bc7ade921 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs @@ -11,7 +11,8 @@ use ra_syntax::{ 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)] diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index f21937f10..69508dd8a 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs @@ -17,7 +17,8 @@ use crate::{ expr::{Expr, ExprId, Pat, PatId}, nameres::CrateDefMap, path::Path, - DefWithBodyId, HasModule, HasSource, Lookup, ModuleId, + src::HasSource, + DefWithBodyId, HasModule, Lookup, ModuleId, }; struct Expander { diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index fee10b237..095d7064a 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs @@ -10,9 +10,10 @@ use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; 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)] diff --git a/crates/ra_hir_def/src/docs.rs b/crates/ra_hir_def/src/docs.rs index 34ed9b7a5..ec944373d 100644 --- a/crates/ra_hir_def/src/docs.rs +++ b/crates/ra_hir_def/src/docs.rs @@ -8,7 +8,11 @@ use std::sync::Arc; 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)] diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index 3f94e40e4..5f648ffc3 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs @@ -9,8 +9,9 @@ use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner}; 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, ...). diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 6daf7d3a3..cfeacfded 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -29,6 +29,8 @@ pub mod resolver; mod trace; pub mod nameres; +pub mod src; + #[cfg(test)] mod test_db; #[cfg(test)] @@ -37,7 +39,7 @@ mod marks; 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 @@ impl HasModule for StaticLoc { self.container } } - -pub trait HasSource { - type Value; - fn source(&self, db: &impl db::DefDatabase) -> InFile; -} - -impl HasSource for FunctionLoc { - type Value = ast::FnDef; - - fn source(&self, db: &impl db::DefDatabase) -> InFile { - 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 { - 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 { - 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 { - 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>; -} diff --git a/crates/ra_hir_def/src/src.rs b/crates/ra_hir_def/src/src.rs new file mode 100644 index 000000000..27caa02cc --- /dev/null +++ b/crates/ra_hir_def/src/src.rs @@ -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; +} + +impl HasSource for FunctionLoc { + type Value = ast::FnDef; + + fn source(&self, db: &impl DefDatabase) -> InFile { + 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 { + 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 { + 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 { + 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>; +} diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index 1e9f4b208..f6283ab6d 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs @@ -693,7 +693,7 @@ impl Expectation { } 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}; -- cgit v1.2.3