aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-20 17:13:50 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-20 17:13:50 +0100
commit4ad2e4ce4e88c809abc7a8006d306fb038eb2d18 (patch)
tree21cc19a5b4fd27b42e09fa12642254227275e88f /crates/ra_syntax/src/ast
parent526a6aba104a32eb9f0f5a65232783d5570c35d5 (diff)
parent8ac3d1f9aa892fc891b69c7d8d00d39b9371d246 (diff)
Merge #1154
1154: Initial support for lang items (and str completion) r=flodiebold a=marcogroppo This PR adds partial support for lang items. For now, the only supported lang items are the ones that target an impl block. Lang items are now resolved during type inference - this means that `str` completion now works. Fixes #1139. (thanks Florian Diebold for the help!) Co-authored-by: Marco Groppo <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs14
-rw-r--r--crates/ra_syntax/src/ast/generated.rs1
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
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)