diff options
Diffstat (limited to 'crates/ra_hir/src/from_source.rs')
-rw-r--r-- | crates/ra_hir/src/from_source.rs | 44 |
1 files changed, 2 insertions, 42 deletions
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index 93713bb14..a9de01455 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs | |||
@@ -1,16 +1,11 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use ra_db::{FileId, FilePosition}; | 3 | use hir_expand::name::AsName; |
4 | use ra_syntax::{ | 4 | use ra_syntax::ast::{self, AstNode, NameOwner}; |
5 | algo::find_node_at_offset, | ||
6 | ast::{self, AstNode, NameOwner}, | ||
7 | SyntaxNode, | ||
8 | }; | ||
9 | 5 | ||
10 | use crate::{ | 6 | use crate::{ |
11 | db::{AstDatabase, DefDatabase, HirDatabase}, | 7 | db::{AstDatabase, DefDatabase, HirDatabase}, |
12 | ids::{AstItemDef, LocationCtx}, | 8 | ids::{AstItemDef, LocationCtx}, |
13 | name::AsName, | ||
14 | AstId, Const, Crate, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock, Module, | 9 | AstId, Const, Crate, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock, Module, |
15 | ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, VariantDef, | 10 | ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, VariantDef, |
16 | }; | 11 | }; |
@@ -129,41 +124,6 @@ impl FromSource for StructField { | |||
129 | } | 124 | } |
130 | } | 125 | } |
131 | 126 | ||
132 | // FIXME: simplify it | ||
133 | impl ModuleSource { | ||
134 | pub fn from_position( | ||
135 | db: &(impl DefDatabase + AstDatabase), | ||
136 | position: FilePosition, | ||
137 | ) -> ModuleSource { | ||
138 | let parse = db.parse(position.file_id); | ||
139 | match &find_node_at_offset::<ast::Module>(parse.tree().syntax(), position.offset) { | ||
140 | Some(m) if !m.has_semi() => ModuleSource::Module(m.clone()), | ||
141 | _ => { | ||
142 | let source_file = parse.tree(); | ||
143 | ModuleSource::SourceFile(source_file) | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | |||
148 | pub fn from_child_node( | ||
149 | db: &(impl DefDatabase + AstDatabase), | ||
150 | file_id: FileId, | ||
151 | child: &SyntaxNode, | ||
152 | ) -> ModuleSource { | ||
153 | if let Some(m) = child.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) { | ||
154 | ModuleSource::Module(m) | ||
155 | } else { | ||
156 | let source_file = db.parse(file_id).tree(); | ||
157 | ModuleSource::SourceFile(source_file) | ||
158 | } | ||
159 | } | ||
160 | |||
161 | pub fn from_file_id(db: &(impl DefDatabase + AstDatabase), file_id: FileId) -> ModuleSource { | ||
162 | let source_file = db.parse(file_id).tree(); | ||
163 | ModuleSource::SourceFile(source_file) | ||
164 | } | ||
165 | } | ||
166 | |||
167 | impl Module { | 127 | impl Module { |
168 | pub fn from_declaration(db: &impl HirDatabase, src: Source<ast::Module>) -> Option<Self> { | 128 | pub fn from_declaration(db: &impl HirDatabase, src: Source<ast::Module>) -> Option<Self> { |
169 | let src_parent = Source { | 129 | let src_parent = Source { |