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.rs101
1 files changed, 0 insertions, 101 deletions
diff --git a/crates/ra_analysis/src/descriptors/mod.rs b/crates/ra_analysis/src/descriptors/mod.rs
deleted file mode 100644
index 97750ea64..000000000
--- a/crates/ra_analysis/src/descriptors/mod.rs
+++ /dev/null
@@ -1,101 +0,0 @@
1pub(crate) mod function;
2pub(crate) mod module;
3mod path;
4
5use std::sync::Arc;
6
7use ra_syntax::{
8 ast::{self, FnDefNode, AstNode},
9 TextRange,
10};
11
12use crate::{
13 db::SyntaxDatabase,
14 descriptors::function::{resolve_local_name, FnId, FnScopes},
15 descriptors::module::{ModuleId, ModuleTree, ModuleSource, nameres::{ItemMap, InputModuleItems}},
16 input::SourceRootId,
17 loc2id::IdDatabase,
18 syntax_ptr::LocalSyntaxPtr,
19 Cancelable,
20};
21
22pub(crate) use self::path::{Path, PathKind};
23
24salsa::query_group! {
25 pub(crate) trait DescriptorDatabase: SyntaxDatabase + IdDatabase {
26 fn fn_scopes(fn_id: FnId) -> Arc<FnScopes> {
27 type FnScopesQuery;
28 use fn function::imp::fn_scopes;
29 }
30
31 fn _input_module_items(source_root_id: SourceRootId, module_id: ModuleId) -> Cancelable<Arc<InputModuleItems>> {
32 type InputModuleItemsQuery;
33 use fn module::nameres::input_module_items;
34 }
35 fn _item_map(source_root_id: SourceRootId) -> Cancelable<Arc<ItemMap>> {
36 type ItemMapQuery;
37 use fn module::nameres::item_map;
38 }
39 fn _module_tree(source_root_id: SourceRootId) -> Cancelable<Arc<ModuleTree>> {
40 type ModuleTreeQuery;
41 use fn module::imp::module_tree;
42 }
43 fn _fn_syntax(fn_id: FnId) -> FnDefNode {
44 type FnSyntaxQuery;
45 // Don't retain syntax trees in memory
46 storage volatile;
47 use fn function::imp::fn_syntax;
48 }
49 fn _submodules(source: ModuleSource) -> Cancelable<Arc<Vec<module::imp::Submodule>>> {
50 type SubmodulesQuery;
51 use fn module::imp::submodules;
52 }
53 }
54}
55
56#[derive(Debug)]
57pub struct ReferenceDescriptor {
58 pub range: TextRange,
59 pub name: String,
60}
61
62#[derive(Debug)]
63pub struct DeclarationDescriptor<'a> {
64 pat: ast::BindPat<'a>,
65 pub range: TextRange,
66}
67
68impl<'a> DeclarationDescriptor<'a> {
69 pub fn new(pat: ast::BindPat) -> DeclarationDescriptor {
70 let range = pat.syntax().range();
71
72 DeclarationDescriptor { pat, range }
73 }
74
75 pub fn find_all_refs(&self) -> Vec<ReferenceDescriptor> {
76 let name_ptr = LocalSyntaxPtr::new(self.pat.syntax());
77
78 let fn_def = match self.pat.syntax().ancestors().find_map(ast::FnDef::cast) {
79 Some(def) => def,
80 None => return Default::default(),
81 };
82
83 let fn_scopes = FnScopes::new(fn_def);
84
85 let refs: Vec<_> = fn_def
86 .syntax()
87 .descendants()
88 .filter_map(ast::NameRef::cast)
89 .filter(|name_ref| match resolve_local_name(*name_ref, &fn_scopes) {
90 None => false,
91 Some(entry) => entry.ptr() == name_ptr,
92 })
93 .map(|name_ref| ReferenceDescriptor {
94 name: name_ref.syntax().text().to_string(),
95 range: name_ref.syntax().range(),
96 })
97 .collect();
98
99 refs
100 }
101}