diff options
author | Aleksey Kladov <[email protected]> | 2018-10-31 07:56:31 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-10-31 07:56:31 +0000 |
commit | b67295134bf5c518b39bc88abbe1bc5b9d7d3baf (patch) | |
tree | a507432668deef7b216cb7c6360620619e904060 /crates/ra_analysis/src/descriptors/function/imp.rs | |
parent | 3068af79ffd23656ff2d46ac92d9192ce6c813fb (diff) |
Move FnDescriptors to analyzer
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 | } | ||