Add a & prefix to all parameter inlay hints that refer to a non-const l-value reference. That makes it easier to identify them even if semantic highlighting is not used (where this is already available)
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks for working on this!
Could you add some test cases to InlayHintTests.cpp to illustrate the new hint please?
As in the other patch, uploading the patch with context would also be helpful for review.
clang-tools-extra/clangd/InlayHints.cpp | ||
---|---|---|
444–446 | It probably doesn't make too much sense to highlight r-value references here, since it should be much clearer from context that they are either temporaries or explicitly std::move'd |
Apologies for the slow response here. This generally looks good to me, but I have a couple of suggestions regarding the formatting of the hints and handling type aliases.
clang-tools-extra/clangd/InlayHints.cpp | ||
---|---|---|
444 | We should make sure we handle the case where a parameter is a typedef to a reference type, e.g.: using IntRef = int&; void foo(IntRef); int main() { int arg; foo(arg); // should show `&: ` hint } Let's add the testcase for this, and if necessary adjust the code to handle it (it's not immediately obvious to me whether it already handles it as written). | |
450 | nit: shouldHintName would make more sense to me as a revised method name | |
clang-tools-extra/clangd/unittests/InlayHintTests.cpp | ||
217 | I prefer for the hint to continue to end with a space, to create visual separation between the hint and the actual code. Especially in a case like this where a hint ends in &, it may be difficult to visually distinguish this from the & occurring in the actual code. To that end, I think the hint would make more sense as param&: or ¶m: . | |
408 | Similarly, and for consistency with other parameter hints, &: would make sense to me here. |
Thanks, the changes here look good.
Something is strange about the diff though, it's not letting me see the complete changes relative to the baseline, only the incremental changes relative to a previous version (I think this is also why Phabricator's build status says patch application failed)
clang-tools-extra/clangd/unittests/InlayHintTests.cpp | ||
---|---|---|
202 | For good measure, let's add an alias = const int& case (expecting no &) as well |
right, arcanist doesn't entirely match my git mental model. Here's the (hopefully) complete patch
Thanks!
Final nit: please update the commit message as it's a bit out of date, and then I'll go ahead and merge
clang-tools-extra/clangd/unittests/InlayHintTests.cpp | ||
---|---|---|
168 | nit: the annotation can be removed |
We should make sure we handle the case where a parameter is a typedef to a reference type, e.g.:
Let's add the testcase for this, and if necessary adjust the code to handle it (it's not immediately obvious to me whether it already handles it as written).