diff options
Diffstat (limited to 'crates/ra_hir_def/src/attr.rs')
-rw-r--r-- | crates/ra_hir_def/src/attr.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index e228e2145..050832ce0 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs | |||
@@ -5,7 +5,7 @@ use std::{ops, sync::Arc}; | |||
5 | use either::Either; | 5 | use either::Either; |
6 | use hir_expand::{hygiene::Hygiene, AstId, InFile}; | 6 | use hir_expand::{hygiene::Hygiene, AstId, InFile}; |
7 | use mbe::ast_to_token_tree; | 7 | use mbe::ast_to_token_tree; |
8 | use ra_cfg::CfgOptions; | 8 | use ra_cfg::{CfgExpr, CfgOptions}; |
9 | use ra_syntax::{ | 9 | use ra_syntax::{ |
10 | ast::{self, AstNode, AttrsOwner}, | 10 | ast::{self, AstNode, AttrsOwner}, |
11 | SmolStr, | 11 | SmolStr, |
@@ -125,9 +125,12 @@ impl Attrs { | |||
125 | AttrQuery { attrs: self, key } | 125 | AttrQuery { attrs: self, key } |
126 | } | 126 | } |
127 | 127 | ||
128 | pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> bool { | 128 | pub fn cfg(&self) -> impl Iterator<Item = CfgExpr> + '_ { |
129 | // FIXME: handle cfg_attr :-) | 129 | // FIXME: handle cfg_attr :-) |
130 | self.by_key("cfg").tt_values().all(|tt| cfg_options.is_cfg_enabled(tt) != Some(false)) | 130 | self.by_key("cfg").tt_values().map(CfgExpr::parse) |
131 | } | ||
132 | pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> bool { | ||
133 | self.cfg().all(|cfg| cfg_options.check(&cfg) != Some(false)) | ||
131 | } | 134 | } |
132 | } | 135 | } |
133 | 136 | ||
@@ -148,18 +151,15 @@ pub enum AttrInput { | |||
148 | impl Attr { | 151 | impl Attr { |
149 | fn from_src(ast: ast::Attr, hygiene: &Hygiene) -> Option<Attr> { | 152 | fn from_src(ast: ast::Attr, hygiene: &Hygiene) -> Option<Attr> { |
150 | let path = ModPath::from_src(ast.path()?, hygiene)?; | 153 | let path = ModPath::from_src(ast.path()?, hygiene)?; |
151 | let input = match ast.input() { | 154 | let input = if let Some(lit) = ast.literal() { |
152 | None => None, | 155 | // FIXME: escape? raw string? |
153 | Some(ast::AttrInput::Literal(lit)) => { | 156 | let value = lit.syntax().first_token()?.text().trim_matches('"').into(); |
154 | // FIXME: escape? raw string? | 157 | Some(AttrInput::Literal(value)) |
155 | let value = lit.syntax().first_token()?.text().trim_matches('"').into(); | 158 | } else if let Some(tt) = ast.token_tree() { |
156 | Some(AttrInput::Literal(value)) | 159 | Some(AttrInput::TokenTree(ast_to_token_tree(&tt)?.0)) |
157 | } | 160 | } else { |
158 | Some(ast::AttrInput::TokenTree(tt)) => { | 161 | None |
159 | Some(AttrInput::TokenTree(ast_to_token_tree(&tt)?.0)) | ||
160 | } | ||
161 | }; | 162 | }; |
162 | |||
163 | Some(Attr { path, input }) | 163 | Some(Attr { path, input }) |
164 | } | 164 | } |
165 | } | 165 | } |