From a49ad47e5afa5950f92b77badc6679295101328a Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Mon, 30 Sep 2019 17:47:17 +0800 Subject: Support cfg attribute on impl blocks --- crates/ra_hir/src/attr.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir/src/attr.rs') diff --git a/crates/ra_hir/src/attr.rs b/crates/ra_hir/src/attr.rs index 19be6de32..84c36b8da 100644 --- a/crates/ra_hir/src/attr.rs +++ b/crates/ra_hir/src/attr.rs @@ -1,11 +1,14 @@ +use std::sync::Arc; + use mbe::ast_to_token_tree; +use ra_cfg::CfgOptions; use ra_syntax::{ - ast::{self, AstNode}, + ast::{self, AstNode, AttrsOwner}, SmolStr, }; use tt::Subtree; -use crate::{db::AstDatabase, path::Path, Source}; +use crate::{db::AstDatabase, path::Path, HirFileId, Source}; #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) struct Attr { @@ -40,6 +43,14 @@ impl Attr { Some(Attr { path, input }) } + pub(crate) fn from_attrs_owner( + file_id: HirFileId, + owner: &impl AttrsOwner, + db: &impl AstDatabase, + ) -> Arc<[Attr]> { + owner.attrs().flat_map(|ast| Attr::from_src(Source { file_id, ast }, db)).collect() + } + pub(crate) fn is_simple_atom(&self, name: &str) -> bool { // FIXME: Avoid cloning self.path.as_ident().map_or(false, |s| s.to_string() == name) @@ -55,4 +66,8 @@ impl Attr { None } } + + pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> Option { + cfg_options.is_cfg_enabled(self.as_cfg()?) + } } -- cgit v1.2.3