From b67295134bf5c518b39bc88abbe1bc5b9d7d3baf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 31 Oct 2018 10:56:31 +0300 Subject: Move FnDescriptors to analyzer --- crates/ra_analysis/src/descriptors/function/imp.rs | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 crates/ra_analysis/src/descriptors/function/imp.rs (limited to 'crates/ra_analysis/src/descriptors/function/imp.rs') 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 @@ +use std::sync::Arc; + +use ra_syntax::{ + ast::{AstNode, FnDef, FnDefNode}, +}; + +use crate::{ + descriptors::{ + DescriptorDatabase, + function::{FnId, FnScopes}, + }, +}; + +/// 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 { + let syntax = db.fn_syntax(fn_id); + let res = FnScopes::new(syntax.ast()); + Arc::new(res) +} -- cgit v1.2.3