diff options
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r-- | crates/ra_hir_def/src/keys.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres.rs | 36 |
2 files changed, 5 insertions, 35 deletions
diff --git a/crates/ra_hir_def/src/keys.rs b/crates/ra_hir_def/src/keys.rs index d844f7a62..5913f12b1 100644 --- a/crates/ra_hir_def/src/keys.rs +++ b/crates/ra_hir_def/src/keys.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use std::marker::PhantomData; | 3 | use std::marker::PhantomData; |
4 | 4 | ||
5 | use hir_expand::InFile; | 5 | use hir_expand::{InFile, MacroDefId}; |
6 | use ra_syntax::{ast, AstNode, AstPtr}; | 6 | use ra_syntax::{ast, AstNode, AstPtr}; |
7 | use rustc_hash::FxHashMap; | 7 | use rustc_hash::FxHashMap; |
8 | 8 | ||
@@ -29,6 +29,8 @@ pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new(); | |||
29 | pub const RECORD_FIELD: Key<ast::RecordFieldDef, StructFieldId> = Key::new(); | 29 | pub const RECORD_FIELD: Key<ast::RecordFieldDef, StructFieldId> = Key::new(); |
30 | pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new(); | 30 | pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new(); |
31 | 31 | ||
32 | pub const MACRO: Key<ast::MacroCall, MacroDefId> = Key::new(); | ||
33 | |||
32 | /// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are | 34 | /// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are |
33 | /// equal if they point to exactly the same object. | 35 | /// equal if they point to exactly the same object. |
34 | /// | 36 | /// |
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index e1a6a46df..27c12e46c 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs | |||
@@ -59,12 +59,9 @@ use std::sync::Arc; | |||
59 | 59 | ||
60 | use hir_expand::{diagnostics::DiagnosticSink, name::Name, InFile}; | 60 | use hir_expand::{diagnostics::DiagnosticSink, name::Name, InFile}; |
61 | use ra_arena::Arena; | 61 | use ra_arena::Arena; |
62 | use ra_db::{CrateId, Edition, FileId, FilePosition}; | 62 | use ra_db::{CrateId, Edition, FileId}; |
63 | use ra_prof::profile; | 63 | use ra_prof::profile; |
64 | use ra_syntax::{ | 64 | use ra_syntax::ast; |
65 | ast::{self, AstNode}, | ||
66 | SyntaxNode, | ||
67 | }; | ||
68 | use rustc_hash::FxHashMap; | 65 | use rustc_hash::FxHashMap; |
69 | 66 | ||
70 | use crate::{ | 67 | use crate::{ |
@@ -255,35 +252,6 @@ pub enum ModuleSource { | |||
255 | Module(ast::Module), | 252 | Module(ast::Module), |
256 | } | 253 | } |
257 | 254 | ||
258 | impl ModuleSource { | ||
259 | // FIXME: this methods do not belong here | ||
260 | pub fn from_position(db: &impl DefDatabase, position: FilePosition) -> ModuleSource { | ||
261 | let parse = db.parse(position.file_id); | ||
262 | match &ra_syntax::algo::find_node_at_offset::<ast::Module>( | ||
263 | parse.tree().syntax(), | ||
264 | position.offset, | ||
265 | ) { | ||
266 | Some(m) if !m.has_semi() => ModuleSource::Module(m.clone()), | ||
267 | _ => { | ||
268 | let source_file = parse.tree(); | ||
269 | ModuleSource::SourceFile(source_file) | ||
270 | } | ||
271 | } | ||
272 | } | ||
273 | |||
274 | pub fn from_child_node(db: &impl DefDatabase, child: InFile<&SyntaxNode>) -> ModuleSource { | ||
275 | if let Some(m) = | ||
276 | child.value.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) | ||
277 | { | ||
278 | ModuleSource::Module(m) | ||
279 | } else { | ||
280 | let file_id = child.file_id.original_file(db); | ||
281 | let source_file = db.parse(file_id).tree(); | ||
282 | ModuleSource::SourceFile(source_file) | ||
283 | } | ||
284 | } | ||
285 | } | ||
286 | |||
287 | mod diagnostics { | 255 | mod diagnostics { |
288 | use hir_expand::diagnostics::DiagnosticSink; | 256 | use hir_expand::diagnostics::DiagnosticSink; |
289 | use ra_db::RelativePathBuf; | 257 | use ra_db::RelativePathBuf; |