aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/keys.rs4
-rw-r--r--crates/ra_hir_def/src/nameres.rs36
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
3use std::marker::PhantomData; 3use std::marker::PhantomData;
4 4
5use hir_expand::InFile; 5use hir_expand::{InFile, MacroDefId};
6use ra_syntax::{ast, AstNode, AstPtr}; 6use ra_syntax::{ast, AstNode, AstPtr};
7use rustc_hash::FxHashMap; 7use rustc_hash::FxHashMap;
8 8
@@ -29,6 +29,8 @@ pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new();
29pub const RECORD_FIELD: Key<ast::RecordFieldDef, StructFieldId> = Key::new(); 29pub const RECORD_FIELD: Key<ast::RecordFieldDef, StructFieldId> = Key::new();
30pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new(); 30pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new();
31 31
32pub 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
60use hir_expand::{diagnostics::DiagnosticSink, name::Name, InFile}; 60use hir_expand::{diagnostics::DiagnosticSink, name::Name, InFile};
61use ra_arena::Arena; 61use ra_arena::Arena;
62use ra_db::{CrateId, Edition, FileId, FilePosition}; 62use ra_db::{CrateId, Edition, FileId};
63use ra_prof::profile; 63use ra_prof::profile;
64use ra_syntax::{ 64use ra_syntax::ast;
65 ast::{self, AstNode},
66 SyntaxNode,
67};
68use rustc_hash::FxHashMap; 65use rustc_hash::FxHashMap;
69 66
70use crate::{ 67use crate::{
@@ -255,35 +252,6 @@ pub enum ModuleSource {
255 Module(ast::Module), 252 Module(ast::Module),
256} 253}
257 254
258impl 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
287mod diagnostics { 255mod diagnostics {
288 use hir_expand::diagnostics::DiagnosticSink; 256 use hir_expand::diagnostics::DiagnosticSink;
289 use ra_db::RelativePathBuf; 257 use ra_db::RelativePathBuf;