diff options
Diffstat (limited to 'crates/ra_analysis/src/descriptors/function/imp.rs')
-rw-r--r-- | crates/ra_analysis/src/descriptors/function/imp.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/crates/ra_analysis/src/descriptors/function/imp.rs b/crates/ra_analysis/src/descriptors/function/imp.rs new file mode 100644 index 000000000..0a006f733 --- /dev/null +++ b/crates/ra_analysis/src/descriptors/function/imp.rs | |||
@@ -0,0 +1,26 @@ | |||
1 | use std::sync::Arc; | ||
2 | |||
3 | use ra_syntax::{ | ||
4 | ast::{AstNode, FnDef, FnDefNode}, | ||
5 | }; | ||
6 | |||
7 | use crate::{ | ||
8 | descriptors::{ | ||
9 | DescriptorDatabase, | ||
10 | function::{FnId, FnScopes}, | ||
11 | }, | ||
12 | }; | ||
13 | |||
14 | /// Resolve `FnId` to the corresponding `SyntaxNode` | ||
15 | /// TODO: this should return something more type-safe then `SyntaxNode` | ||
16 | pub(crate) fn fn_syntax(db: &impl DescriptorDatabase, fn_id: FnId) -> FnDefNode { | ||
17 | let syntax = db.resolve_syntax_ptr(fn_id.0); | ||
18 | let fn_def = FnDef::cast(syntax.borrowed()).unwrap(); | ||
19 | FnDefNode::new(fn_def) | ||
20 | } | ||
21 | |||
22 | pub(crate) fn fn_scopes(db: &impl DescriptorDatabase, fn_id: FnId) -> Arc<FnScopes> { | ||
23 | let syntax = db.fn_syntax(fn_id); | ||
24 | let res = FnScopes::new(syntax.ast()); | ||
25 | Arc::new(res) | ||
26 | } | ||