aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/descriptors/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/descriptors/mod.rs')
-rw-r--r--crates/ra_analysis/src/descriptors/mod.rs88
1 files changed, 36 insertions, 52 deletions
diff --git a/crates/ra_analysis/src/descriptors/mod.rs b/crates/ra_analysis/src/descriptors/mod.rs
index 0220f7d5d..0c4991757 100644
--- a/crates/ra_analysis/src/descriptors/mod.rs
+++ b/crates/ra_analysis/src/descriptors/mod.rs
@@ -1,62 +1,46 @@
1pub(crate) mod module; 1pub(crate) mod module;
2pub(crate) mod function;
3
4use std::sync::Arc;
2 5
3use ra_syntax::{ 6use ra_syntax::{
4 ast::{self, AstNode, NameOwner}, 7 SmolStr,
8 ast::{FnDefNode},
5}; 9};
6 10
7#[derive(Debug, Clone)] 11use crate::{
8pub struct FnDescriptor { 12 FileId, Cancelable,
9 pub name: String, 13 db::SyntaxDatabase,
10 pub label: String, 14 descriptors::module::{ModuleTree, ModuleId, ModuleScope},
11 pub ret_type: Option<String>, 15 descriptors::function::{FnId, FnScopes},
12 pub params: Vec<String>, 16 input::SourceRootId,
13} 17 syntax_ptr::SyntaxPtrDatabase,
14 18};
15impl FnDescriptor {
16 pub fn new(node: ast::FnDef) -> Option<Self> {
17 let name = node.name()?.text().to_string();
18
19 // Strip the body out for the label.
20 let label: String = if let Some(body) = node.body() {
21 let body_range = body.syntax().range();
22 let label: String = node
23 .syntax()
24 .children()
25 .filter(|child| !child.range().is_subrange(&body_range))
26 .map(|node| node.text().to_string())
27 .collect();
28 label
29 } else {
30 node.syntax().text().to_string()
31 };
32
33 let params = FnDescriptor::param_list(node);
34 let ret_type = node.ret_type().map(|r| r.syntax().text().to_string());
35
36 Some(FnDescriptor {
37 name,
38 ret_type,
39 params,
40 label,
41 })
42 }
43 19
44 fn param_list(node: ast::FnDef) -> Vec<String> {
45 let mut res = vec![];
46 if let Some(param_list) = node.param_list() {
47 if let Some(self_param) = param_list.self_param() {
48 res.push(self_param.syntax().text().to_string())
49 }
50 20
51 // Maybe use param.pat here? See if we can just extract the name? 21salsa::query_group! {
52 //res.extend(param_list.params().map(|p| p.syntax().text().to_string())); 22 pub(crate) trait DescriptorDatabase: SyntaxDatabase + SyntaxPtrDatabase {
53 res.extend( 23 fn module_tree(source_root_id: SourceRootId) -> Cancelable<Arc<ModuleTree>> {
54 param_list 24 type ModuleTreeQuery;
55 .params() 25 use fn module::imp::module_tree;
56 .filter_map(|p| p.pat()) 26 }
57 .map(|pat| pat.syntax().text().to_string()), 27 fn submodules(file_id: FileId) -> Cancelable<Arc<Vec<SmolStr>>> {
58 ); 28 type SubmodulesQuery;
29 use fn module::imp::submodules;
30 }
31 fn module_scope(source_root_id: SourceRootId, module_id: ModuleId) -> Cancelable<Arc<ModuleScope>> {
32 type ModuleScopeQuery;
33 use fn module::imp::module_scope;
34 }
35 fn fn_syntax(fn_id: FnId) -> FnDefNode {
36 type FnSyntaxQuery;
37 // Don't retain syntax trees in memory
38 storage volatile;
39 use fn function::imp::fn_syntax;
40 }
41 fn fn_scopes(fn_id: FnId) -> Arc<FnScopes> {
42 type FnScopesQuery;
43 use fn function::imp::fn_scopes;
59 } 44 }
60 res
61 } 45 }
62} 46}