]> git.lizzy.rs Git - rust.git/commit
Rollup merge of #39820 - jonasbb:export-attributes, r=nrc
authorAlex Crichton <alex@alexcrichton.com>
Fri, 10 Mar 2017 22:51:13 +0000 (16:51 -0600)
committerGitHub <noreply@github.com>
Fri, 10 Mar 2017 22:51:13 +0000 (16:51 -0600)
commit3b7a534d85e6a07ff1a0db7b7e4cfdb02edc528a
tree8d4429abf76faed3777a903923ee4f4bd152642a
parentd335c0a09b099a8737e64b043609297457d91db6
parentdb35604792fb64efa0a3deaebc0ea0842e19c67a
Rollup merge of #39820 - jonasbb:export-attributes, r=nrc

Export attributes in save-analysis data

Since this is my first pull-request to rust, I would like to get some feedback about obvious errors in this implementation.

I would like to change the save-analysis data to include arbitrary attribute data.
A use-case I have in mind for this is identifying functions with `#[test]` annotations such that tools like rls can offer a test-runner feature. I described my idea here [rls#173](https://github.com/rust-lang-nursery/rls/issues/173).

My changes contain:

1. track a vector of attributes in the various `*Data` types in `data.rs` and `external_data.rs`
2. implement lowering for `Attribute` and `MetaItem`
3. adjust `JsonDumper` to print the attributes

In the lowering of `Attribute` I remove the distinction between `MetaItem` and `NestedMetaItem`. I did this because this distinction is somewhat confusing. For example, `NestedMetaItemKind::Literal` has two identical spans, because both `NestedMetaItem` and `Lit` are defined as `Spanned<_>`.
My model is strictly more general, as it allows an `LitKind` instead of a `Symbol` for `MetaItem` and `Symbol`s are converted into a cooked string. As a consumer of the save-analysis data this shouldn't affect you much.

Example json output of `#[test]` annotation:
```
"attributes": [
  {
    "value": {
      "name": {
        "variant": "Str",
        "fields": [
          "test",
          "Cooked"
        ]
      },
      "kind": "Literal",
      "span": {
        "file_name": "test.rs",
        "byte_start": 2,
        "byte_end": 6,
        "line_start": 1,
        "line_end": 1,
        "column_start": 3,
        "column_end": 7
      }
    },
    "span": {
      "file_name": "test.rs",
      "byte_start": 0,
      "byte_end": 7,
      "line_start": 1,
      "line_end": 1,
      "column_start": 1,
      "column_end": 8
    }
  }
]
```