Commit 7a3ad03
committed
Auto merge of rust-lang#17115 - leviska:json_is_not_rust_better_names, r=Veykril
Try to generate more meaningful names in json converter
I just found out about rust-analyzer json converter, but I think it would be more convenient, if names were more useful, like using the names of the keys.
Let's look at some realistic arbitrary json:
```json
{
"user": {
"address": {
"street": "Main St",
"house": 3
},
"email": "example@example.com"
}
}
```
I think, new generated code is much easier to read and to edit, than the old:
```rust
// Old
struct Struct1{ house: i64, street: String }
struct Struct2{ address: Struct1, email: String }
struct Struct3{ user: Struct2 }
// New
struct Address1{ house: i64, street: String }
struct User1{ address: Address1, email: String }
struct Root1{ user: User1 }
```
Ideally, if we drop the numbers, I can see it being usable just as is (may be rename root)
```rust
struct Address{ house: i64, street: String }
struct User{ address: Address, email: String }
struct Root{ user: User }
```
Sadly, we can't just drop them, because there can be multiple fields (recursive) with the same name, and we can't just easily retroactively add numbers if the name has 2 instances due to parsing being single pass.
We could ignore the `1` and add number only if it's > 1, but I will leave this open to discussion and right now made it the simpler way
In sum, even with numbers, I think this PR still helps in readabilityFile tree
1 file changed
+66
-18
lines changed- src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers
1 file changed
+66
-18
lines changedLines changed: 66 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | 25 | | |
27 | 26 | | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
33 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
34 | 41 | | |
35 | 42 | | |
36 | 43 | | |
| |||
52 | 59 | | |
53 | 60 | | |
54 | 61 | | |
55 | | - | |
56 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
57 | 68 | | |
58 | 69 | | |
59 | 70 | | |
60 | 71 | | |
61 | 72 | | |
62 | 73 | | |
63 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
64 | 77 | | |
65 | 78 | | |
66 | 79 | | |
67 | 80 | | |
68 | 81 | | |
69 | 82 | | |
70 | 83 | | |
71 | | - | |
| 84 | + | |
72 | 85 | | |
73 | 86 | | |
74 | 87 | | |
75 | 88 | | |
76 | 89 | | |
77 | 90 | | |
78 | 91 | | |
79 | | - | |
| 92 | + | |
80 | 93 | | |
81 | 94 | | |
82 | 95 | | |
83 | 96 | | |
84 | | - | |
| 97 | + | |
85 | 98 | | |
86 | 99 | | |
87 | 100 | | |
| |||
113 | 126 | | |
114 | 127 | | |
115 | 128 | | |
116 | | - | |
| 129 | + | |
117 | 130 | | |
118 | 131 | | |
119 | 132 | | |
| |||
218 | 231 | | |
219 | 232 | | |
220 | 233 | | |
221 | | - | |
| 234 | + | |
222 | 235 | | |
223 | 236 | | |
224 | 237 | | |
| |||
237 | 250 | | |
238 | 251 | | |
239 | 252 | | |
240 | | - | |
241 | | - | |
242 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
243 | 291 | | |
244 | 292 | | |
245 | 293 | | |
| |||
276 | 324 | | |
277 | 325 | | |
278 | 326 | | |
279 | | - | |
| 327 | + | |
280 | 328 | | |
281 | | - | |
| 329 | + | |
282 | 330 | | |
283 | 331 | | |
284 | 332 | | |
| |||
0 commit comments