aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/db.rs10
-rw-r--r--crates/ra_hir/src/function.rs23
-rw-r--r--crates/ra_hir/src/mock.rs1
-rw-r--r--crates/ra_hir/src/query_definitions.rs23
4 files changed, 21 insertions, 36 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index e7f9afa77..ba43a4502 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -3,7 +3,6 @@ use std::sync::Arc;
3use ra_syntax::{ 3use ra_syntax::{
4 SmolStr, 4 SmolStr,
5 SyntaxNode, 5 SyntaxNode,
6 ast::FnDefNode,
7}; 6};
8use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, FileId, Cancelable}; 7use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, FileId, Cancelable};
9 8
@@ -12,7 +11,6 @@ use crate::{
12 SourceFileItems, SourceItemId, 11 SourceFileItems, SourceItemId,
13 query_definitions, 12 query_definitions,
14 FnScopes, 13 FnScopes,
15 function::FnId,
16 module::{ModuleId, ModuleTree, ModuleSource, 14 module::{ModuleId, ModuleTree, ModuleSource,
17 nameres::{ItemMap, InputModuleItems}}, 15 nameres::{ItemMap, InputModuleItems}},
18 ty::{InferenceResult, Ty}, 16 ty::{InferenceResult, Ty},
@@ -24,14 +22,10 @@ salsa::query_group! {
24pub trait HirDatabase: SyntaxDatabase 22pub trait HirDatabase: SyntaxDatabase
25 + AsRef<LocationIntener<DefLoc, DefId>> 23 + AsRef<LocationIntener<DefLoc, DefId>>
26{ 24{
27 fn fn_scopes(fn_id: FnId) -> Arc<FnScopes> { 25 fn fn_scopes(def_id: DefId) -> Arc<FnScopes> {
28 type FnScopesQuery; 26 type FnScopesQuery;
29 use fn query_definitions::fn_scopes; 27 use fn query_definitions::fn_scopes;
30 } 28 }
31 fn fn_syntax(fn_id: FnId) -> FnDefNode {
32 type FnSyntaxQuery;
33 use fn query_definitions::fn_syntax;
34 }
35 29
36 fn struct_data(def_id: DefId) -> Cancelable<Arc<StructData>> { 30 fn struct_data(def_id: DefId) -> Cancelable<Arc<StructData>> {
37 type StructDataQuery; 31 type StructDataQuery;
@@ -43,7 +37,7 @@ pub trait HirDatabase: SyntaxDatabase
43 use fn query_definitions::enum_data; 37 use fn query_definitions::enum_data;
44 } 38 }
45 39
46 fn infer(fn_id: FnId) -> Cancelable<Arc<InferenceResult>> { 40 fn infer(def_id: DefId) -> Cancelable<Arc<InferenceResult>> {
47 type InferQuery; 41 type InferQuery;
48 use fn query_definitions::infer; 42 use fn query_definitions::infer;
49 } 43 }
diff --git a/crates/ra_hir/src/function.rs b/crates/ra_hir/src/function.rs
index d4159cee2..5a44132fc 100644
--- a/crates/ra_hir/src/function.rs
+++ b/crates/ra_hir/src/function.rs
@@ -11,43 +11,42 @@ use ra_syntax::{
11 ast::{self, AstNode, DocCommentsOwner, NameOwner}, 11 ast::{self, AstNode, DocCommentsOwner, NameOwner},
12}; 12};
13 13
14use crate::{ DefId, HirDatabase, ty::InferenceResult, Module }; 14use crate::{DefId, DefKind, HirDatabase, ty::InferenceResult, Module};
15 15
16pub use self::scope::FnScopes; 16pub use self::scope::FnScopes;
17 17
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
19pub struct FnId(pub(crate) DefId);
20
21#[derive(Debug)] 18#[derive(Debug)]
22pub struct Function { 19pub struct Function {
23 pub(crate) fn_id: FnId, 20 def_id: DefId,
24} 21}
25 22
26impl Function { 23impl Function {
27 pub(crate) fn new(def_id: DefId) -> Function { 24 pub(crate) fn new(def_id: DefId) -> Function {
28 let fn_id = FnId(def_id); 25 Function { def_id }
29 Function { fn_id }
30 } 26 }
31 27
32 pub fn syntax(&self, db: &impl HirDatabase) -> ast::FnDefNode { 28 pub fn syntax(&self, db: &impl HirDatabase) -> ast::FnDefNode {
33 db.fn_syntax(self.fn_id) 29 let def_loc = self.def_id.loc(db);
30 assert!(def_loc.kind == DefKind::Function);
31 let syntax = db.file_item(def_loc.source_item_id);
32 ast::FnDef::cast(syntax.borrowed()).unwrap().owned()
34 } 33 }
35 34
36 pub fn scopes(&self, db: &impl HirDatabase) -> Arc<FnScopes> { 35 pub fn scopes(&self, db: &impl HirDatabase) -> Arc<FnScopes> {
37 db.fn_scopes(self.fn_id) 36 db.fn_scopes(self.def_id)
38 } 37 }
39 38
40 pub fn signature_info(&self, db: &impl HirDatabase) -> Option<FnSignatureInfo> { 39 pub fn signature_info(&self, db: &impl HirDatabase) -> Option<FnSignatureInfo> {
41 let syntax = db.fn_syntax(self.fn_id); 40 let syntax = self.syntax(db);
42 FnSignatureInfo::new(syntax.borrowed()) 41 FnSignatureInfo::new(syntax.borrowed())
43 } 42 }
44 43
45 pub fn infer(&self, db: &impl HirDatabase) -> Cancelable<Arc<InferenceResult>> { 44 pub fn infer(&self, db: &impl HirDatabase) -> Cancelable<Arc<InferenceResult>> {
46 db.infer(self.fn_id) 45 db.infer(self.def_id)
47 } 46 }
48 47
49 pub fn module(&self, db: &impl HirDatabase) -> Cancelable<Module> { 48 pub fn module(&self, db: &impl HirDatabase) -> Cancelable<Module> {
50 self.fn_id.0.module(db) 49 self.def_id.module(db)
51 } 50 }
52} 51}
53 52
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index f6882cb77..a2507c9b5 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/mock.rs
@@ -189,7 +189,6 @@ salsa::database_storage! {
189 fn file_item() for db::FileItemQuery; 189 fn file_item() for db::FileItemQuery;
190 fn input_module_items() for db::InputModuleItemsQuery; 190 fn input_module_items() for db::InputModuleItemsQuery;
191 fn item_map() for db::ItemMapQuery; 191 fn item_map() for db::ItemMapQuery;
192 fn fn_syntax() for db::FnSyntaxQuery;
193 fn submodules() for db::SubmodulesQuery; 192 fn submodules() for db::SubmodulesQuery;
194 fn infer() for db::InferQuery; 193 fn infer() for db::InferQuery;
195 fn type_for_def() for db::TypeForDefQuery; 194 fn type_for_def() for db::TypeForDefQuery;
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs
index e6241342a..56e3f7e9d 100644
--- a/crates/ra_hir/src/query_definitions.rs
+++ b/crates/ra_hir/src/query_definitions.rs
@@ -5,15 +5,15 @@ 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, SmolStr,
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, Name, AsName, 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,
@@ -23,22 +23,15 @@ use crate::{
23 adt::{StructData, EnumData}, 23 adt::{StructData, EnumData},
24}; 24};
25 25
26/// Resolve `FnId` to the corresponding `SyntaxNode` 26pub(super) fn fn_scopes(db: &impl HirDatabase, def_id: DefId) -> Arc<FnScopes> {
27pub(super) fn fn_syntax(db: &impl HirDatabase, fn_id: FnId) -> FnDefNode { 27 let function = Function::new(def_id);
28 let def_loc = fn_id.0.loc(db); 28 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()); 29 let res = FnScopes::new(syntax.borrowed());
37 Arc::new(res) 30 Arc::new(res)
38} 31}
39 32
40pub(super) fn infer(db: &impl HirDatabase, fn_id: FnId) -> Cancelable<Arc<InferenceResult>> { 33pub(super) fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> {
41 let function = Function { fn_id }; 34 let function = Function::new(def_id);
42 ty::infer(db, function).map(Arc::new) 35 ty::infer(db, function).map(Arc::new)
43} 36}
44 37