diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-12 15:08:34 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-12 15:08:34 +0000 |
commit | 5bf669860984a2c058b3bdc3e43b4993a0f25b31 (patch) | |
tree | b7811c88a671bc43bb35149f15e3ad7724e87214 /crates/ra_syntax/src | |
parent | 421609225a5e38eb48dd42a4394898c7ae74b7f3 (diff) | |
parent | 2a7d97d82911ad03c549fa3c8c014e4b74c9696d (diff) |
Merge #3121
3121: Do not add imports before inner attributes r=matklad a=SomeoneToIgnore
Current `insert_use_statement` function adds imports before inner attributes which results in compiler errors:
<img width="1440" alt="image" src="https://user-images.githubusercontent.com/2690773/74344019-a3749500-4db4-11ea-9d88-f71e903e795a.png">
Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 9 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 18 |
2 files changed, 21 insertions, 6 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index d3e8888bd..9cc7930f7 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -18,8 +18,8 @@ use crate::{ | |||
18 | pub use self::{ | 18 | pub use self::{ |
19 | expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp, RangeOp}, | 19 | expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp, RangeOp}, |
20 | extensions::{ | 20 | extensions::{ |
21 | FieldKind, PathSegmentKind, SelfParamKind, SlicePatComponents, StructKind, TypeBoundKind, | 21 | AttrKind, FieldKind, PathSegmentKind, SelfParamKind, SlicePatComponents, StructKind, |
22 | VisibilityKind, | 22 | TypeBoundKind, VisibilityKind, |
23 | }, | 23 | }, |
24 | generated::*, | 24 | generated::*, |
25 | tokens::*, | 25 | tokens::*, |
@@ -217,10 +217,7 @@ fn test_doc_comment_multi_line_block_strips_suffix() { | |||
217 | #[test] | 217 | #[test] |
218 | fn test_comments_preserve_trailing_whitespace() { | 218 | fn test_comments_preserve_trailing_whitespace() { |
219 | let file = SourceFile::parse( | 219 | let file = SourceFile::parse( |
220 | r#" | 220 | "\n/// Representation of a Realm. \n/// In the specification these are called Realm Records.\nstruct Realm {}", |
221 | /// Representation of a Realm. | ||
222 | /// In the specification these are called Realm Records. | ||
223 | struct Realm {}"#, | ||
224 | ) | 221 | ) |
225 | .ok() | 222 | .ok() |
226 | .unwrap(); | 223 | .unwrap(); |
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index 7dcf084de..44de4af89 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs | |||
@@ -37,6 +37,12 @@ fn text_of_first_token(node: &SyntaxNode) -> &SmolStr { | |||
37 | node.green().children().next().and_then(|it| it.into_token()).unwrap().text() | 37 | node.green().children().next().and_then(|it| it.into_token()).unwrap().text() |
38 | } | 38 | } |
39 | 39 | ||
40 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
41 | pub enum AttrKind { | ||
42 | Inner, | ||
43 | Outer, | ||
44 | } | ||
45 | |||
40 | impl ast::Attr { | 46 | impl ast::Attr { |
41 | pub fn as_simple_atom(&self) -> Option<SmolStr> { | 47 | pub fn as_simple_atom(&self) -> Option<SmolStr> { |
42 | match self.input() { | 48 | match self.input() { |
@@ -71,6 +77,18 @@ impl ast::Attr { | |||
71 | _ => None, | 77 | _ => None, |
72 | } | 78 | } |
73 | } | 79 | } |
80 | |||
81 | pub fn kind(&self) -> AttrKind { | ||
82 | let first_token = self.syntax().first_token(); | ||
83 | let first_token_kind = first_token.as_ref().map(SyntaxToken::kind); | ||
84 | let second_token_kind = | ||
85 | first_token.and_then(|token| token.next_token()).as_ref().map(SyntaxToken::kind); | ||
86 | |||
87 | match (first_token_kind, second_token_kind) { | ||
88 | (Some(SyntaxKind::POUND), Some(SyntaxKind::EXCL)) => AttrKind::Inner, | ||
89 | _ => AttrKind::Outer, | ||
90 | } | ||
91 | } | ||
74 | } | 92 | } |
75 | 93 | ||
76 | #[derive(Debug, Clone, PartialEq, Eq)] | 94 | #[derive(Debug, Clone, PartialEq, Eq)] |