Commit 5a3d241
feat: LSP signature help (#5725)
# Description
## Problem
Resolves #1585
## Summary
While working on autocompletion I was always checking what Rust Analyzer
did, or how it worked, and I noticed that in Rust Analyzer when it
autocompletes a function a little popup with the parameter names and
types would show up, which is really useful! But it turned out that's a
separate feature: signature help.
This PR implements that. I think it makes autocompletion much better.
Before:

After:

Note: in the latest version the popup text starts with "fn ", but I
didn't want to re-record all the gifs 😅 .
You basically don't have to remember what were the parameter types.
It also works with methods:

And if you have an `fn`:

And here it's working in an aztec project (I always check that it works
outside of small toy programs 😊):

## Additional Context
I promise this will be the last big LSP PR I send 🤞 . Now that we have
most of the LSP features registered, next PRs should be much smaller,
just adding on top of what there is.
These PRs are also relatively big because they traverse the AST and that
code is kind of boilerplatey. For that reason here I decided to put the
boilerplatey code in a `traversal.rs` file, so that it's clear there's
no extra logic there other than traversing the AST. I might send a
follow-up PR doing the same for autocompletion.
One more thing: you can trigger this functionality as a VSCode command
(Trigger Parameter Hints). But then when offering autocompletion you can
also tell VSCode to execute a command, and in this PR we tell it to
execute exactly that command (Rust Analyzer does the same, though they
have a custom command for it, not sure why).
UPDATE: I managed to implement the visitor pattern to reduce the
boilerplate. [Here's a PR](#5727)
with that. I think it will greatly simplify things, and make it easier
to keep the code updated as we add more nodes. It takes inspiration in
[how it's done in the Crystal
compiler](https://github.com/crystal-lang/crystal/blob/master/src/compiler/crystal/syntax/visitor.cr),
which in turn is inspired by how it was done in the Java editor support
for Eclipse 😄
## Documentation\*
Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.
# PR Checklist\*
- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
---------
Co-authored-by: jfecher <[email protected]>1 parent 5730e67 commit 5a3d241
File tree
8 files changed
+885
-37
lines changed- tooling/lsp/src
- requests
- completion
- signature_help
8 files changed
+885
-37
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| 146 | + | |
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
2 | 4 | | |
3 | 5 | | |
4 | 6 | | |
| |||
164 | 166 | | |
165 | 167 | | |
166 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
167 | 176 | | |
168 | 177 | | |
169 | 178 | | |
| |||
342 | 351 | | |
343 | 352 | | |
344 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
93 | 108 | | |
94 | 109 | | |
95 | 110 | | |
| |||
408 | 423 | | |
409 | 424 | | |
410 | 425 | | |
411 | | - | |
| 426 | + | |
412 | 427 | | |
413 | 428 | | |
414 | 429 | | |
415 | | - | |
| 430 | + | |
416 | 431 | | |
417 | 432 | | |
418 | 433 | | |
| |||
429 | 444 | | |
430 | 445 | | |
431 | 446 | | |
432 | | - | |
| 447 | + | |
433 | 448 | | |
434 | 449 | | |
435 | 450 | | |
436 | | - | |
| 451 | + | |
437 | 452 | | |
438 | 453 | | |
439 | 454 | | |
| |||
455 | 470 | | |
456 | 471 | | |
457 | 472 | | |
458 | | - | |
| 473 | + | |
459 | 474 | | |
460 | 475 | | |
461 | 476 | | |
462 | | - | |
| 477 | + | |
463 | 478 | | |
464 | 479 | | |
465 | 480 | | |
| |||
1063 | 1078 | | |
1064 | 1079 | | |
1065 | 1080 | | |
1066 | | - | |
| 1081 | + | |
1067 | 1082 | | |
1068 | 1083 | | |
1069 | 1084 | | |
1070 | | - | |
| 1085 | + | |
1071 | 1086 | | |
1072 | | - | |
| 1087 | + | |
1073 | 1088 | | |
1074 | 1089 | | |
1075 | 1090 | | |
1076 | | - | |
| 1091 | + | |
1077 | 1092 | | |
1078 | 1093 | | |
1079 | 1094 | | |
| |||
1102 | 1117 | | |
1103 | 1118 | | |
1104 | 1119 | | |
1105 | | - | |
| 1120 | + | |
1106 | 1121 | | |
1107 | 1122 | | |
1108 | 1123 | | |
1109 | | - | |
| 1124 | + | |
1110 | 1125 | | |
1111 | 1126 | | |
1112 | 1127 | | |
| |||
1131 | 1146 | | |
1132 | 1147 | | |
1133 | 1148 | | |
1134 | | - | |
| 1149 | + | |
1135 | 1150 | | |
1136 | 1151 | | |
1137 | 1152 | | |
1138 | | - | |
| 1153 | + | |
1139 | 1154 | | |
1140 | 1155 | | |
1141 | 1156 | | |
| |||
1161 | 1176 | | |
1162 | 1177 | | |
1163 | 1178 | | |
1164 | | - | |
| 1179 | + | |
1165 | 1180 | | |
1166 | 1181 | | |
1167 | 1182 | | |
1168 | | - | |
| 1183 | + | |
1169 | 1184 | | |
1170 | 1185 | | |
1171 | 1186 | | |
1172 | 1187 | | |
1173 | | - | |
| 1188 | + | |
1174 | 1189 | | |
1175 | 1190 | | |
1176 | 1191 | | |
1177 | | - | |
| 1192 | + | |
1178 | 1193 | | |
1179 | 1194 | | |
1180 | 1195 | | |
1181 | | - | |
| 1196 | + | |
1182 | 1197 | | |
1183 | 1198 | | |
1184 | 1199 | | |
1185 | | - | |
| 1200 | + | |
1186 | 1201 | | |
1187 | 1202 | | |
1188 | 1203 | | |
| |||
1207 | 1222 | | |
1208 | 1223 | | |
1209 | 1224 | | |
1210 | | - | |
| 1225 | + | |
1211 | 1226 | | |
1212 | 1227 | | |
1213 | 1228 | | |
1214 | | - | |
| 1229 | + | |
1215 | 1230 | | |
1216 | 1231 | | |
1217 | 1232 | | |
| |||
1239 | 1254 | | |
1240 | 1255 | | |
1241 | 1256 | | |
1242 | | - | |
| 1257 | + | |
1243 | 1258 | | |
1244 | 1259 | | |
1245 | 1260 | | |
1246 | | - | |
| 1261 | + | |
1247 | 1262 | | |
1248 | 1263 | | |
1249 | 1264 | | |
1250 | 1265 | | |
1251 | | - | |
| 1266 | + | |
1252 | 1267 | | |
1253 | 1268 | | |
1254 | 1269 | | |
1255 | | - | |
| 1270 | + | |
1256 | 1271 | | |
1257 | 1272 | | |
1258 | 1273 | | |
1259 | | - | |
| 1274 | + | |
1260 | 1275 | | |
1261 | 1276 | | |
1262 | 1277 | | |
1263 | | - | |
| 1278 | + | |
1264 | 1279 | | |
1265 | 1280 | | |
1266 | 1281 | | |
| |||
1317 | 1332 | | |
1318 | 1333 | | |
1319 | 1334 | | |
1320 | | - | |
| 1335 | + | |
1321 | 1336 | | |
1322 | 1337 | | |
1323 | 1338 | | |
1324 | | - | |
| 1339 | + | |
1325 | 1340 | | |
1326 | 1341 | | |
1327 | 1342 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
59 | | - | |
| 60 | + | |
| 61 | + | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| |||
241 | 243 | | |
242 | 244 | | |
243 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
244 | 255 | | |
245 | 256 | | |
246 | 257 | | |
| |||
0 commit comments