aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
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
parentf4d0cb64fc8b3010bdc4b168a2fa6d96a6cf90b1 (diff)
itroduce FunctionDescriptor
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/hir/function/mod.rs25
-rw-r--r--crates/ra_analysis/src/hir/mod.rs9
-rw-r--r--crates/ra_analysis/src/imp.rs11
3 files changed, 36 insertions, 9 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 {
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 6dadc059f..ad4b40c58 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -20,9 +20,10 @@ use crate::{
20 completion::{completions, CompletionItem}, 20 completion::{completions, CompletionItem},
21 db::{self, FileSyntaxQuery, SyntaxDatabase}, 21 db::{self, FileSyntaxQuery, SyntaxDatabase},
22 hir::{ 22 hir::{
23 function::{FnDescriptor, FnId}, 23 FunctionDescriptor, ModuleDescriptor,
24 module::{ModuleDescriptor, Problem}, 24 function::FnDescriptor,
25 DeclarationDescriptor, HirDatabase, 25 module::{Problem},
26 DeclarationDescriptor,
26 }, 27 },
27 input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE}, 28 input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE},
28 symbol_index::SymbolIndex, 29 symbol_index::SymbolIndex,
@@ -587,8 +588,8 @@ fn resolve_local_name(
587 name_ref: ast::NameRef, 588 name_ref: ast::NameRef,
588) -> Option<(SmolStr, TextRange)> { 589) -> Option<(SmolStr, TextRange)> {
589 let fn_def = name_ref.syntax().ancestors().find_map(ast::FnDef::cast)?; 590 let fn_def = name_ref.syntax().ancestors().find_map(ast::FnDef::cast)?;
590 let fn_id = FnId::get(db, file_id, fn_def); 591 let function = FunctionDescriptor::guess_from_source(db, file_id, fn_def);
591 let scopes = db.fn_scopes(fn_id); 592 let scopes = function.scope(db);
592 let scope_entry = crate::hir::function::resolve_local_name(name_ref, &scopes)?; 593 let scope_entry = crate::hir::function::resolve_local_name(name_ref, &scopes)?;
593 let syntax = db.resolve_syntax_ptr(scope_entry.ptr().into_global(file_id)); 594 let syntax = db.resolve_syntax_ptr(scope_entry.ptr().into_global(file_id));
594 Some((scope_entry.name().clone(), syntax.range())) 595 Some((scope_entry.name().clone(), syntax.range()))