diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-01-16 15:49:23 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-01-16 15:49:23 +0000 |
commit | e614356de10256c64e02f5d0f82cfa39e27b0f07 (patch) | |
tree | 1ad38d73f8cac5a82e1cb9493016b645a335074a /crates/ra_parser/src/grammar/attributes.rs | |
parent | f4eeff2c82e7d8b95706c2bcb0388eeeb3ddd24e (diff) | |
parent | a766883a751096e5b912b59a14d7b6fc3372c791 (diff) |
Merge #2827
2827: Fix array element attribute position r=matklad a=edwin0cheng
This PR fixed a bug which an ATTR node insert in the wrong place in array element. ~~And introduce `precede_next` for allow outer attributes to insert into a parsed `expr`.~~
related #2783
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_parser/src/grammar/attributes.rs')
-rw-r--r-- | crates/ra_parser/src/grammar/attributes.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/crates/ra_parser/src/grammar/attributes.rs b/crates/ra_parser/src/grammar/attributes.rs index f3158ade3..eeae37aef 100644 --- a/crates/ra_parser/src/grammar/attributes.rs +++ b/crates/ra_parser/src/grammar/attributes.rs | |||
@@ -8,6 +8,28 @@ pub(super) fn inner_attributes(p: &mut Parser) { | |||
8 | } | 8 | } |
9 | } | 9 | } |
10 | 10 | ||
11 | pub(super) fn with_outer_attributes( | ||
12 | p: &mut Parser, | ||
13 | f: impl Fn(&mut Parser) -> Option<CompletedMarker>, | ||
14 | ) -> bool { | ||
15 | let am = p.start(); | ||
16 | let has_attrs = p.at(T![#]); | ||
17 | attributes::outer_attributes(p); | ||
18 | let cm = f(p); | ||
19 | let success = cm.is_some(); | ||
20 | |||
21 | match (has_attrs, cm) { | ||
22 | (true, Some(cm)) => { | ||
23 | let kind = cm.kind(); | ||
24 | cm.undo_completion(p).abandon(p); | ||
25 | am.complete(p, kind); | ||
26 | } | ||
27 | _ => am.abandon(p), | ||
28 | } | ||
29 | |||
30 | success | ||
31 | } | ||
32 | |||
11 | pub(super) fn outer_attributes(p: &mut Parser) { | 33 | pub(super) fn outer_attributes(p: &mut Parser) { |
12 | while p.at(T![#]) { | 34 | while p.at(T![#]) { |
13 | attribute(p, false) | 35 | attribute(p, false) |