diff options
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 14 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 1 |
2 files changed, 15 insertions, 0 deletions
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 { | |||
65 | None | 65 | None |
66 | } | 66 | } |
67 | } | 67 | } |
68 | |||
69 | pub fn as_key_value(&self) -> Option<(SmolStr, SmolStr)> { | ||
70 | let tt = self.value()?; | ||
71 | let tt_node = tt.syntax(); | ||
72 | let attr = tt_node.children_with_tokens().nth(1)?; | ||
73 | if attr.kind() == IDENT { | ||
74 | let key = attr.as_token()?.text().clone(); | ||
75 | let val_node = tt_node.children_with_tokens().find(|t| t.kind() == STRING)?; | ||
76 | let val = val_node.as_token()?.text().trim_start_matches("\"").trim_end_matches("\""); | ||
77 | Some((key, SmolStr::new(val))) | ||
78 | } else { | ||
79 | None | ||
80 | } | ||
81 | } | ||
68 | } | 82 | } |
69 | 83 | ||
70 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 84 | #[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 17de4f058..fae371509 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 { | |||
1325 | 1325 | ||
1326 | 1326 | ||
1327 | impl ast::TypeParamsOwner for ImplBlock {} | 1327 | impl ast::TypeParamsOwner for ImplBlock {} |
1328 | impl ast::AttrsOwner for ImplBlock {} | ||
1328 | impl ImplBlock { | 1329 | impl ImplBlock { |
1329 | pub fn item_list(&self) -> Option<&ItemList> { | 1330 | pub fn item_list(&self) -> Option<&ItemList> { |
1330 | super::child_opt(self) | 1331 | super::child_opt(self) |