From e85ee60c42db57368e24ad9ac24840c2494d383c Mon Sep 17 00:00:00 2001 From: Marco Groppo Date: Mon, 15 Apr 2019 00:03:54 +0200 Subject: Initial support for lang items. --- crates/ra_syntax/src/ast/extensions.rs | 14 ++++++++++++++ crates/ra_syntax/src/ast/generated.rs | 1 + 2 files changed, 15 insertions(+) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index ca33b43e7..5c4c0ffc1 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs @@ -65,6 +65,20 @@ impl ast::Attr { None } } + + pub fn as_key_value(&self) -> Option<(SmolStr, SmolStr)> { + let tt = self.value()?; + let tt_node = tt.syntax(); + let attr = tt_node.children_with_tokens().nth(1)?; + if attr.kind() == IDENT { + let key = attr.as_token()?.text().clone(); + let val_node = tt_node.children_with_tokens().find(|t| t.kind() == STRING)?; + let val = val_node.as_token()?.text().trim_start_matches("\"").trim_end_matches("\""); + Some((key, SmolStr::new(val))) + } else { + None + } + } } #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 774d9bcc8..29a7ce166 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -1325,6 +1325,7 @@ impl ToOwned for ImplBlock { impl ast::TypeParamsOwner for ImplBlock {} +impl ast::AttrsOwner for ImplBlock {} impl ImplBlock { pub fn item_list(&self) -> Option<&ItemList> { super::child_opt(self) -- cgit v1.2.3