diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/code_model/src.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 17 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 20 |
4 files changed, 23 insertions, 20 deletions
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index 0f4c78df7..bd0c3c226 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs | |||
@@ -10,7 +10,7 @@ use crate::{ | |||
10 | ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, | 10 | ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, |
11 | }; | 11 | }; |
12 | 12 | ||
13 | pub use hir_def::Source; | 13 | pub use hir_expand::Source; |
14 | 14 | ||
15 | pub trait HasSource { | 15 | pub trait HasSource { |
16 | type Ast; | 16 | type Ast; |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 40f5562b4..0ba17e571 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -62,7 +62,7 @@ pub use crate::{ | |||
62 | adt::VariantDef, | 62 | adt::VariantDef, |
63 | code_model::{ | 63 | code_model::{ |
64 | docs::{DocDef, Docs, Documentation}, | 64 | docs::{DocDef, Docs, Documentation}, |
65 | src::{HasBodySource, HasSource, Source}, | 65 | src::{HasBodySource, HasSource}, |
66 | Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, | 66 | Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, |
67 | EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef, | 67 | EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef, |
68 | ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, | 68 | ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, |
@@ -85,4 +85,4 @@ pub use hir_def::{ | |||
85 | path::{Path, PathKind}, | 85 | path::{Path, PathKind}, |
86 | type_ref::Mutability, | 86 | type_ref::Mutability, |
87 | }; | 87 | }; |
88 | pub use hir_expand::{either::Either, name::Name}; | 88 | pub use hir_expand::{either::Either, name::Name, Source}; |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 76d5f1852..6d66f481d 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -19,19 +19,13 @@ pub mod nameres; | |||
19 | 19 | ||
20 | use std::hash::{Hash, Hasher}; | 20 | use std::hash::{Hash, Hasher}; |
21 | 21 | ||
22 | use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId}; | 22 | use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, Source}; |
23 | use ra_arena::{impl_arena_id, RawId}; | 23 | use ra_arena::{impl_arena_id, RawId}; |
24 | use ra_db::{salsa, CrateId, FileId}; | 24 | use ra_db::{salsa, CrateId, FileId}; |
25 | use ra_syntax::{ast, AstNode, SyntaxNode}; | 25 | use ra_syntax::{ast, AstNode, SyntaxNode}; |
26 | 26 | ||
27 | use crate::{builtin_type::BuiltinType, db::InternDatabase}; | 27 | use crate::{builtin_type::BuiltinType, db::InternDatabase}; |
28 | 28 | ||
29 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | ||
30 | pub struct Source<T> { | ||
31 | pub file_id: HirFileId, | ||
32 | pub ast: T, | ||
33 | } | ||
34 | |||
35 | pub enum ModuleSource { | 29 | pub enum ModuleSource { |
36 | SourceFile(ast::SourceFile), | 30 | SourceFile(ast::SourceFile), |
37 | Module(ast::Module), | 31 | Module(ast::Module), |
@@ -94,15 +88,6 @@ impl ModuleSource { | |||
94 | } | 88 | } |
95 | } | 89 | } |
96 | 90 | ||
97 | impl<T> Source<T> { | ||
98 | pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> { | ||
99 | Source { file_id: self.file_id, ast: f(self.ast) } | ||
100 | } | ||
101 | pub fn file_syntax(&self, db: &impl AstDatabase) -> SyntaxNode { | ||
102 | db.parse_or_expand(self.file_id).expect("source created from invalid file") | ||
103 | } | ||
104 | } | ||
105 | |||
106 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 91 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
107 | pub struct ModuleId { | 92 | pub struct ModuleId { |
108 | pub krate: CrateId, | 93 | pub krate: CrateId, |
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 5a0e5a19c..85c2b22ac 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -13,7 +13,10 @@ pub mod hygiene; | |||
13 | use std::hash::{Hash, Hasher}; | 13 | use std::hash::{Hash, Hasher}; |
14 | 14 | ||
15 | use ra_db::{salsa, CrateId, FileId}; | 15 | use ra_db::{salsa, CrateId, FileId}; |
16 | use ra_syntax::ast::{self, AstNode}; | 16 | use ra_syntax::{ |
17 | ast::{self, AstNode}, | ||
18 | SyntaxNode, | ||
19 | }; | ||
17 | 20 | ||
18 | use crate::ast_id_map::FileAstId; | 21 | use crate::ast_id_map::FileAstId; |
19 | 22 | ||
@@ -151,3 +154,18 @@ impl<N: AstNode> AstId<N> { | |||
151 | db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root) | 154 | db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root) |
152 | } | 155 | } |
153 | } | 156 | } |
157 | |||
158 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | ||
159 | pub struct Source<T> { | ||
160 | pub file_id: HirFileId, | ||
161 | pub ast: T, | ||
162 | } | ||
163 | |||
164 | impl<T> Source<T> { | ||
165 | pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> { | ||
166 | Source { file_id: self.file_id, ast: f(self.ast) } | ||
167 | } | ||
168 | pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode { | ||
169 | db.parse_or_expand(self.file_id).expect("source created from invalid file") | ||
170 | } | ||
171 | } | ||