Repository: rust-analyzer/rust-analyzer
Pull request #507 (2019-01-12 15:44:15)

Fix handling of attributes in positional field lists
First reported by @max-frai. This allows us to properly handle crates using e.g. `#[Derive(fail)]` with `#[fail(cause)]`, among other cases.


Patch:
diff --git a/crates/ra_syntax/src/grammar/items/nominal.rs b/crates/ra_syntax/src/grammar/items/nominal.rs
index 495462ca7a..0784fb7b1c 100644
--- a/crates/ra_syntax/src/grammar/items/nominal.rs
+++ b/crates/ra_syntax/src/grammar/items/nominal.rs
@@ -140,6 +140,16 @@ fn pos_field_list(p: &mut Parser) {
     }
     while !p.at(R_PAREN) && !p.at(EOF) {
         let m = p.start();
+        // test pos_field_attrs
+        // struct S (
+        //     #[serde(with = "url_serde")]
+        //     pub Uri,
+        // );
+        //
+        // enum S {
+        //     Uri(#[serde(with = "url_serde")] Uri),
+        // }
+        attributes::outer_attributes(p);
         opt_visibility(p);
         if !p.at_ts(types::TYPE_FIRST) {
             p.error("expected a type");
diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs
index 5597aae5a6..9d73d57c4a 100644
--- a/crates/tools/src/main.rs
+++ b/crates/tools/src/main.rs
@@ -158,12 +158,12 @@ fn install_code_extension() -> Result<()> {
     }
     if cfg!(windows) {
         run(
-            r"cmd.exe /c code.cmd --install-extension ./ra-lsp-0.0.1.vsix --force",
+            r"cmd.exe /c code.cmd --install-extension ./ra-lsp-0.0.1.vsix",
             "./editors/code",
         )?;
     } else {
         run(
-            r"code --install-extension ./ra-lsp-0.0.1.vsix --force",
+            r"code --install-extension ./ra-lsp-0.0.1.vsix",
             "./editors/code",
         )?;
     }


Test patch:
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0115_pos_field_attrs.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0115_pos_field_attrs.rs
new file mode 100644
index 0000000000..635b9ac21a
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0115_pos_field_attrs.rs
@@ -0,0 +1,4 @@
+struct S (
+    #[serde(with = "url_serde")]
+    pub Uri,
+);
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0115_pos_field_attrs.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0115_pos_field_attrs.txt
new file mode 100644
index 0000000000..99ec0755bf
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0115_pos_field_attrs.txt
@@ -0,0 +1,39 @@
+SOURCE_FILE@[0; 60)
+  STRUCT_DEF@[0; 59)
+    STRUCT_KW@[0; 6)
+    WHITESPACE@[6; 7)
+    NAME@[7; 8)
+      IDENT@[7; 8) "S"
+    WHITESPACE@[8; 9)
+    POS_FIELD_LIST@[9; 58)
+      L_PAREN@[9; 10)
+      WHITESPACE@[10; 15)
+      POS_FIELD@[15; 55)
+        ATTR@[15; 43)
+          POUND@[15; 16)
+          TOKEN_TREE@[16; 43)
+            L_BRACK@[16; 17)
+            IDENT@[17; 22) "serde"
+            TOKEN_TREE@[22; 42)
+              L_PAREN@[22; 23)
+              IDENT@[23; 27) "with"
+              WHITESPACE@[27; 28)
+              EQ@[28; 29)
+              WHITESPACE@[29; 30)
+              STRING@[30; 41)
+              R_PAREN@[41; 42)
+            R_BRACK@[42; 43)
+        WHITESPACE@[43; 48)
+        VISIBILITY@[48; 51)
+          PUB_KW@[48; 51)
+        WHITESPACE@[51; 52)
+        PATH_TYPE@[52; 55)
+          PATH@[52; 55)
+            PATH_SEGMENT@[52; 55)
+              NAME_REF@[52; 55)
+                IDENT@[52; 55) "Uri"
+      COMMA@[55; 56)
+      WHITESPACE@[56; 57)
+      R_PAREN@[57; 58)
+    SEMI@[58; 59)
+  WHITESPACE@[59; 60)