aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/descriptors/function/imp.rs
blob: 11fffeefcfa59184844994148b38c44f03b9fabe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use std::sync::Arc;

use ra_syntax::ast::{AstNode, FnDef, FnDefNode};

use crate::descriptors::{
    function::{FnId, FnScopes},
    DescriptorDatabase,
};

/// Resolve `FnId` to the corresponding `SyntaxNode`
/// TODO: this should return something more type-safe then `SyntaxNode`
pub(crate) fn fn_syntax(db: &impl DescriptorDatabase, fn_id: FnId) -> FnDefNode {
    let syntax = db.resolve_syntax_ptr(fn_id.0);
    let fn_def = FnDef::cast(syntax.borrowed()).unwrap();
    FnDefNode::new(fn_def)
}

pub(crate) fn fn_scopes(db: &impl DescriptorDatabase, fn_id: FnId) -> Arc<FnScopes> {
    let syntax = db.fn_syntax(fn_id);
    let res = FnScopes::new(syntax.ast());
    Arc::new(res)
}