You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of rust-lang#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](rust-lang/rls#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
}
}
]
```
0 commit comments