aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-11-27 19:58:09 +0000
committerAleksey Kladov <[email protected]>2018-11-27 19:58:09 +0000
commit109a7f3717612c58c73c5c153b632385b922fc9d (patch)
tree195ab74809d05b38938a25a68d327084abb25984 /crates/ra_analysis/src/hir
parentf4d0cb64fc8b3010bdc4b168a2fa6d96a6cf90b1 (diff)
itroduce FunctionDescriptor
Diffstat (limited to 'crates/ra_analysis/src/hir')
-rw-r--r--crates/ra_analysis/src/hir/function/mod.rs25
-rw-r--r--crates/ra_analysis/src/hir/mod.rs9
2 files changed, 30 insertions, 4 deletions
diff --git a/crates/ra_analysis/src/hir/function/mod.rs b/crates/ra_analysis/src/hir/function/mod.rs
index 86eee5e93..c8af6bc21 100644
--- a/crates/ra_analysis/src/hir/function/mod.rs
+++ b/crates/ra_analysis/src/hir/function/mod.rs
@@ -1,7 +1,10 @@
1pub(super) mod imp; 1pub(super) mod imp;
2mod scope; 2mod scope;
3 3
4use std::cmp::{max, min}; 4use std::{
5 cmp::{max, min},
6 sync::Arc,
7};
5 8
6use ra_syntax::{ 9use ra_syntax::{
7 ast::{self, AstNode, DocCommentsOwner, NameOwner}, 10 ast::{self, AstNode, DocCommentsOwner, NameOwner},
@@ -9,6 +12,7 @@ use ra_syntax::{
9}; 12};
10 13
11use crate::{ 14use crate::{
15 hir::HirDatabase,
12 syntax_ptr::SyntaxPtr, FileId, 16 syntax_ptr::SyntaxPtr, FileId,
13 loc2id::IdDatabase, 17 loc2id::IdDatabase,
14}; 18};
@@ -23,6 +27,25 @@ impl FnId {
23 } 27 }
24} 28}
25 29
30pub(crate) struct FunctionDescriptor {
31 fn_id: FnId,
32}
33
34impl FunctionDescriptor {
35 pub(crate) fn guess_from_source(
36 db: &impl HirDatabase,
37 file_id: FileId,
38 fn_def: ast::FnDef,
39 ) -> FunctionDescriptor {
40 let fn_id = FnId::get(db, file_id, fn_def);
41 FunctionDescriptor { fn_id }
42 }
43
44 pub(crate) fn scope(&self, db: &impl HirDatabase) -> Arc<FnScopes> {
45 db.fn_scopes(self.fn_id)
46 }
47}
48
26#[derive(Debug, Clone)] 49#[derive(Debug, Clone)]
27pub struct FnDescriptor { 50pub struct FnDescriptor {
28 pub name: String, 51 pub name: String,
diff --git a/crates/ra_analysis/src/hir/mod.rs b/crates/ra_analysis/src/hir/mod.rs
index 232a8558b..edeaeb8e6 100644
--- a/crates/ra_analysis/src/hir/mod.rs
+++ b/crates/ra_analysis/src/hir/mod.rs
@@ -21,7 +21,7 @@ use crate::{
21 db::SyntaxDatabase, 21 db::SyntaxDatabase,
22 hir::function::{resolve_local_name, FnId, FnScopes}, 22 hir::function::{resolve_local_name, FnId, FnScopes},
23 hir::module::{ 23 hir::module::{
24 ModuleId, ModuleTree, ModuleSource, ModuleDescriptor, 24 ModuleId, ModuleTree, ModuleSource,
25 nameres::{ItemMap, InputModuleItems, FileItems} 25 nameres::{ItemMap, InputModuleItems, FileItems}
26 }, 26 },
27 input::SourceRootId, 27 input::SourceRootId,
@@ -30,8 +30,11 @@ use crate::{
30 Cancelable, 30 Cancelable,
31}; 31};
32 32
33pub(crate) use self::path::{Path, PathKind}; 33pub(crate) use self::{
34pub(crate) use self::module::nameres::FileItemId; 34 path::{Path, PathKind},
35 module::{ModuleDescriptor, nameres::FileItemId},
36 function::FunctionDescriptor,
37};
35 38
36salsa::query_group! { 39salsa::query_group! {
37pub(crate) trait HirDatabase: SyntaxDatabase + IdDatabase { 40pub(crate) trait HirDatabase: SyntaxDatabase + IdDatabase {