aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/query_definitions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/query_definitions.rs')
-rw-r--r--crates/ra_hir/src/query_definitions.rs43
1 files changed, 9 insertions, 34 deletions
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs
index 4a7958a12..721bd4195 100644
--- a/crates/ra_hir/src/query_definitions.rs
+++ b/crates/ra_hir/src/query_definitions.rs
@@ -5,55 +5,30 @@ use std::{
5 5
6use rustc_hash::FxHashMap; 6use rustc_hash::FxHashMap;
7use ra_syntax::{ 7use ra_syntax::{
8 AstNode, SyntaxNode, SmolStr, 8 AstNode, SyntaxNode,
9 ast::{self, FnDef, FnDefNode, NameOwner, ModuleItemOwner} 9 ast::{self, NameOwner, ModuleItemOwner}
10}; 10};
11use ra_db::{SourceRootId, FileId, Cancelable,}; 11use ra_db::{SourceRootId, FileId, Cancelable,};
12 12
13use crate::{ 13use crate::{
14 SourceFileItems, SourceItemId, DefKind, Function, DefId, 14 SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName,
15 db::HirDatabase, 15 db::HirDatabase,
16 function::{FnScopes, FnId}, 16 function::FnScopes,
17 module::{ 17 module::{
18 ModuleSource, ModuleSourceNode, ModuleId, 18 ModuleSource, ModuleSourceNode, ModuleId,
19 imp::Submodule, 19 imp::Submodule,
20 nameres::{InputModuleItems, ItemMap, Resolver}, 20 nameres::{InputModuleItems, ItemMap, Resolver},
21 }, 21 },
22 ty::{self, InferenceResult, Ty},
23 adt::{StructData, EnumData}, 22 adt::{StructData, EnumData},
24}; 23};
25 24
26/// Resolve `FnId` to the corresponding `SyntaxNode` 25pub(super) fn fn_scopes(db: &impl HirDatabase, def_id: DefId) -> Arc<FnScopes> {
27pub(super) fn fn_syntax(db: &impl HirDatabase, fn_id: FnId) -> FnDefNode { 26 let function = Function::new(def_id);
28 let def_loc = fn_id.0.loc(db); 27 let syntax = function.syntax(db);
29 assert!(def_loc.kind == DefKind::Function);
30 let syntax = db.file_item(def_loc.source_item_id);
31 FnDef::cast(syntax.borrowed()).unwrap().owned()
32}
33
34pub(super) fn fn_scopes(db: &impl HirDatabase, fn_id: FnId) -> Arc<FnScopes> {
35 let syntax = db.fn_syntax(fn_id);
36 let res = FnScopes::new(syntax.borrowed()); 28 let res = FnScopes::new(syntax.borrowed());
37 Arc::new(res) 29 Arc::new(res)
38} 30}
39 31
40pub(super) fn infer(db: &impl HirDatabase, fn_id: FnId) -> Cancelable<Arc<InferenceResult>> {
41 let function = Function { fn_id };
42 ty::infer(db, function).map(Arc::new)
43}
44
45pub(super) fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Ty> {
46 ty::type_for_def(db, def_id)
47}
48
49pub(super) fn type_for_field(
50 db: &impl HirDatabase,
51 def_id: DefId,
52 field: SmolStr,
53) -> Cancelable<Ty> {
54 ty::type_for_field(db, def_id, field)
55}
56
57pub(super) fn struct_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<StructData>> { 32pub(super) fn struct_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<StructData>> {
58 let def_loc = def_id.loc(db); 33 let def_loc = def_id.loc(db);
59 assert!(def_loc.kind == DefKind::Struct); 34 assert!(def_loc.kind == DefKind::Struct);
@@ -130,14 +105,14 @@ pub(crate) fn submodules(
130 105
131pub(crate) fn modules<'a>( 106pub(crate) fn modules<'a>(
132 root: impl ast::ModuleItemOwner<'a>, 107 root: impl ast::ModuleItemOwner<'a>,
133) -> impl Iterator<Item = (SmolStr, ast::Module<'a>)> { 108) -> impl Iterator<Item = (Name, ast::Module<'a>)> {
134 root.items() 109 root.items()
135 .filter_map(|item| match item { 110 .filter_map(|item| match item {
136 ast::ModuleItem::Module(m) => Some(m), 111 ast::ModuleItem::Module(m) => Some(m),
137 _ => None, 112 _ => None,
138 }) 113 })
139 .filter_map(|module| { 114 .filter_map(|module| {
140 let name = module.name()?.text(); 115 let name = module.name()?.as_name();
141 Some((name, module)) 116 Some((name, module))
142 }) 117 })
143} 118}