aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs14
-rw-r--r--crates/ra_syntax/src/ast/generated.rs1
-rw-r--r--crates/ra_syntax/src/grammar.ron2
3 files changed, 16 insertions, 1 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 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 {
1325 1325
1326 1326
1327impl ast::TypeParamsOwner for ImplBlock {} 1327impl ast::TypeParamsOwner for ImplBlock {}
1328impl ast::AttrsOwner for ImplBlock {}
1328impl ImplBlock { 1329impl 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)
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron
index b41241287..41fe35f08 100644
--- a/crates/ra_syntax/src/grammar.ron
+++ b/crates/ra_syntax/src/grammar.ron
@@ -341,7 +341,7 @@ Grammar(
341 ], 341 ],
342 options: ["TypeRef"] 342 options: ["TypeRef"]
343 ), 343 ),
344 "ImplBlock": (options: ["ItemList"], traits: ["TypeParamsOwner"]), 344 "ImplBlock": (options: ["ItemList"], traits: ["TypeParamsOwner", "AttrsOwner"]),
345 345
346 "ParenType": (options: ["TypeRef"]), 346 "ParenType": (options: ["TypeRef"]),
347 "TupleType": ( collections: [["fields", "TypeRef"]] ), 347 "TupleType": ( collections: [["fields", "TypeRef"]] ),