aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/function
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-11-28 01:09:44 +0000
committerAleksey Kladov <[email protected]>2018-11-28 01:09:44 +0000
commit59e29aef633e906837f8fed604435976a46be691 (patch)
tree0e5aa7337c000dd8c6ef3a7fedba68abf7feca8a /crates/ra_hir/src/function
parent0e4b710af83844f4a7c471c5335c99aaaa25a90c (diff)
Move hir to a separate crate
Diffstat (limited to 'crates/ra_hir/src/function')
-rw-r--r--crates/ra_hir/src/function/mod.rs16
-rw-r--r--crates/ra_hir/src/function/scope.rs17
2 files changed, 15 insertions, 18 deletions
diff --git a/crates/ra_hir/src/function/mod.rs b/crates/ra_hir/src/function/mod.rs
index a3ed00f02..c8af2e54f 100644
--- a/crates/ra_hir/src/function/mod.rs
+++ b/crates/ra_hir/src/function/mod.rs
@@ -15,10 +15,10 @@ use crate::{
15 FnId, HirDatabase, SourceItemId, 15 FnId, HirDatabase, SourceItemId,
16}; 16};
17 17
18pub(crate) use self::scope::FnScopes; 18pub use self::scope::FnScopes;
19 19
20impl FnId { 20impl FnId {
21 pub(crate) fn get(db: &impl HirDatabase, file_id: FileId, fn_def: ast::FnDef) -> FnId { 21 pub fn get(db: &impl HirDatabase, file_id: FileId, fn_def: ast::FnDef) -> FnId {
22 let file_items = db.file_items(file_id); 22 let file_items = db.file_items(file_id);
23 let item_id = file_items.id_of(fn_def.syntax()); 23 let item_id = file_items.id_of(fn_def.syntax());
24 let item_id = SourceItemId { file_id, item_id }; 24 let item_id = SourceItemId { file_id, item_id };
@@ -26,12 +26,12 @@ impl FnId {
26 } 26 }
27} 27}
28 28
29pub(crate) struct Function { 29pub struct Function {
30 fn_id: FnId, 30 fn_id: FnId,
31} 31}
32 32
33impl Function { 33impl Function {
34 pub(crate) fn guess_from_source( 34 pub fn guess_from_source(
35 db: &impl HirDatabase, 35 db: &impl HirDatabase,
36 file_id: FileId, 36 file_id: FileId,
37 fn_def: ast::FnDef, 37 fn_def: ast::FnDef,
@@ -40,7 +40,7 @@ impl Function {
40 Function { fn_id } 40 Function { fn_id }
41 } 41 }
42 42
43 pub(crate) fn guess_for_name_ref( 43 pub fn guess_for_name_ref(
44 db: &impl HirDatabase, 44 db: &impl HirDatabase,
45 file_id: FileId, 45 file_id: FileId,
46 name_ref: ast::NameRef, 46 name_ref: ast::NameRef,
@@ -48,7 +48,7 @@ impl Function {
48 Function::guess_for_node(db, file_id, name_ref.syntax()) 48 Function::guess_for_node(db, file_id, name_ref.syntax())
49 } 49 }
50 50
51 pub(crate) fn guess_for_bind_pat( 51 pub fn guess_for_bind_pat(
52 db: &impl HirDatabase, 52 db: &impl HirDatabase,
53 file_id: FileId, 53 file_id: FileId,
54 bind_pat: ast::BindPat, 54 bind_pat: ast::BindPat,
@@ -66,11 +66,11 @@ impl Function {
66 Some(res) 66 Some(res)
67 } 67 }
68 68
69 pub(crate) fn scope(&self, db: &impl HirDatabase) -> Arc<FnScopes> { 69 pub fn scope(&self, db: &impl HirDatabase) -> Arc<FnScopes> {
70 db.fn_scopes(self.fn_id) 70 db.fn_scopes(self.fn_id)
71 } 71 }
72 72
73 pub(crate) fn signature_info(&self, db: &impl HirDatabase) -> Option<FnSignatureInfo> { 73 pub fn signature_info(&self, db: &impl HirDatabase) -> Option<FnSignatureInfo> {
74 let syntax = db.fn_syntax(self.fn_id); 74 let syntax = db.fn_syntax(self.fn_id);
75 FnSignatureInfo::new(syntax.borrowed()) 75 FnSignatureInfo::new(syntax.borrowed())
76 } 76 }
diff --git a/crates/ra_hir/src/function/scope.rs b/crates/ra_hir/src/function/scope.rs
index c8b6b1934..863453291 100644
--- a/crates/ra_hir/src/function/scope.rs
+++ b/crates/ra_hir/src/function/scope.rs
@@ -15,7 +15,7 @@ pub(crate) type ScopeId = Id<ScopeData>;
15 15
16#[derive(Debug, PartialEq, Eq)] 16#[derive(Debug, PartialEq, Eq)]
17pub struct FnScopes { 17pub struct FnScopes {
18 pub(crate) self_param: Option<LocalSyntaxPtr>, 18 pub self_param: Option<LocalSyntaxPtr>,
19 scopes: Arena<ScopeData>, 19 scopes: Arena<ScopeData>,
20 scope_for: FxHashMap<LocalSyntaxPtr, ScopeId>, 20 scope_for: FxHashMap<LocalSyntaxPtr, ScopeId>,
21} 21}
@@ -27,13 +27,13 @@ pub struct ScopeEntry {
27} 27}
28 28
29#[derive(Debug, PartialEq, Eq)] 29#[derive(Debug, PartialEq, Eq)]
30pub(crate) struct ScopeData { 30pub struct ScopeData {
31 parent: Option<ScopeId>, 31 parent: Option<ScopeId>,
32 entries: Vec<ScopeEntry>, 32 entries: Vec<ScopeEntry>,
33} 33}
34 34
35impl FnScopes { 35impl FnScopes {
36 pub(crate) fn new(fn_def: ast::FnDef) -> FnScopes { 36 pub fn new(fn_def: ast::FnDef) -> FnScopes {
37 let mut scopes = FnScopes { 37 let mut scopes = FnScopes {
38 self_param: fn_def 38 self_param: fn_def
39 .param_list() 39 .param_list()
@@ -49,7 +49,7 @@ impl FnScopes {
49 } 49 }
50 scopes 50 scopes
51 } 51 }
52 pub(crate) fn entries(&self, scope: ScopeId) -> &[ScopeEntry] { 52 pub fn entries(&self, scope: ScopeId) -> &[ScopeEntry] {
53 &self.scopes[scope].entries 53 &self.scopes[scope].entries
54 } 54 }
55 pub fn scope_chain<'a>(&'a self, node: SyntaxNodeRef) -> impl Iterator<Item = ScopeId> + 'a { 55 pub fn scope_chain<'a>(&'a self, node: SyntaxNodeRef) -> impl Iterator<Item = ScopeId> + 'a {
@@ -57,10 +57,7 @@ impl FnScopes {
57 self.scopes[scope].parent 57 self.scopes[scope].parent
58 }) 58 })
59 } 59 }
60 pub(crate) fn resolve_local_name<'a>( 60 pub fn resolve_local_name<'a>(&'a self, name_ref: ast::NameRef) -> Option<&'a ScopeEntry> {
61 &'a self,
62 name_ref: ast::NameRef,
63 ) -> Option<&'a ScopeEntry> {
64 let mut shadowed = FxHashSet::default(); 61 let mut shadowed = FxHashSet::default();
65 let ret = self 62 let ret = self
66 .scope_chain(name_ref.syntax()) 63 .scope_chain(name_ref.syntax())
@@ -138,10 +135,10 @@ impl ScopeEntry {
138 }; 135 };
139 Some(res) 136 Some(res)
140 } 137 }
141 pub(crate) fn name(&self) -> &SmolStr { 138 pub fn name(&self) -> &SmolStr {
142 &self.name 139 &self.name
143 } 140 }
144 pub(crate) fn ptr(&self) -> LocalSyntaxPtr { 141 pub fn ptr(&self) -> LocalSyntaxPtr {
145 self.ptr 142 self.ptr
146 } 143 }
147} 144}