[PATCH] D124359: [clangd] Add inlay hints for mutable reference parameters

2022-05-02 Thread Nathan Ridge via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG043e96502408: [clangd] Add inlay hints for mutable reference 
parameters (authored by upsj, committed by nridge).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124359/new/

https://reviews.llvm.org/D124359

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -138,6 +138,38 @@
   )cpp");
 }
 
+TEST(ParameterHints, NoNameConstReference) {
+  // No hint for anonymous const l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(const int&);
+void bar() {
+  foo(42);
+}
+  )cpp");
+}
+
+TEST(ParameterHints, NoNameReference) {
+  // Reference hint for anonymous l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{"&: ", "param"});
+}
+
+TEST(ParameterHints, NoNameRValueReference) {
+  // No reference hint for anonymous r-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&&);
+void bar() {
+  foo(42);
+}
+  )cpp");
+}
+
 TEST(ParameterHints, NameInDefinition) {
   // Parameter name picked up from definition if necessary.
   assertParameterHints(R"cpp(
@@ -162,6 +194,66 @@
ExpectedHint{"good: ", "good"});
 }
 
+TEST(ParameterHints, NameConstReference) {
+  // Only name hint for const l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(const int& param);
+void bar() {
+  foo($param[[42]]);
+}
+  )cpp",
+   ExpectedHint{"param: ", "param"});
+}
+
+TEST(ParameterHints, NameTypeAliasConstReference) {
+  // Only name hint for const l-value ref parameter via type alias.
+  assertParameterHints(R"cpp(
+using alias = const int&;
+void foo(alias param);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{"param: ", "param"});
+}
+
+TEST(ParameterHints, NameReference) {
+  // Reference and name hint for l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int& param);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{": ", "param"});
+}
+
+TEST(ParameterHints, NameTypeAliasReference) {
+  // Reference and name hint for l-value ref parameter via type alias.
+  assertParameterHints(R"cpp(
+using alias = int&;
+void foo(alias param);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{": ", "param"});
+}
+
+TEST(ParameterHints, NameRValueReference) {
+  // Only name hint for r-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&& param);
+void bar() {
+  foo($param[[42]]);
+}
+  )cpp",
+   ExpectedHint{"param: ", "param"});
+}
+
 TEST(ParameterHints, Operator) {
   // No hint for operator call with operator syntax.
   assertParameterHints(R"cpp(
@@ -301,6 +393,21 @@
ExpectedHint{"param: ", "param"});
 }
 
+TEST(ParameterHints, ArgMatchesParamReference) {
+  assertParameterHints(R"cpp(
+void foo(int& param);
+void foo2(const int& param);
+void bar() {
+  int param;
+  // show reference hint on mutable reference
+  foo($param[[param]]);
+  // but not on const reference
+  foo2(param);
+}
+  )cpp",
+   ExpectedHint{"&: ", "param"});
+}
+
 TEST(ParameterHints, LeadingUnderscore) {
   assertParameterHints(R"cpp(
 void foo(int p1, int _p2, int __p3);
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -10,6 +10,7 @@
 #include "Config.h"
 #include "HeuristicResolver.h"
 #include "ParsedAST.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
@@ -392,6 +393,7 @@
 // Don't show hints for variadic parameters.
 size_t FixedParamCount = getFixedParamCount(Callee);
 size_t ArgCount = std::min(FixedParamCount, Args.size());
+auto Params = Callee->parameters();
 
 NameVec ParameterNames = chooseParameterNames(Callee, ArgCount);
 
@@ -402,12 +404,14 @@
 
 for (size_t I = 0; I < ArgCount; ++I) {
   StringRef Name = ParameterNames[I];
-  if (!shouldHint(Args[I], Name))
-continue;
+  bool NameHint = shouldHintName(Args[I], Name);
+  bool ReferenceHint = shouldHintReference(Params[I]);
 
-  

[PATCH] D124359: [clangd] Add inlay hints for mutable reference parameters

2022-05-02 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj updated this revision to Diff 426372.
upsj marked an inline comment as done.
upsj added a comment.

remove unnecessary annotation


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124359/new/

https://reviews.llvm.org/D124359

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -138,6 +138,38 @@
   )cpp");
 }
 
+TEST(ParameterHints, NoNameConstReference) {
+  // No hint for anonymous const l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(const int&);
+void bar() {
+  foo(42);
+}
+  )cpp");
+}
+
+TEST(ParameterHints, NoNameReference) {
+  // Reference hint for anonymous l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{"&: ", "param"});
+}
+
+TEST(ParameterHints, NoNameRValueReference) {
+  // No reference hint for anonymous r-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&&);
+void bar() {
+  foo(42);
+}
+  )cpp");
+}
+
 TEST(ParameterHints, NameInDefinition) {
   // Parameter name picked up from definition if necessary.
   assertParameterHints(R"cpp(
@@ -162,6 +194,66 @@
ExpectedHint{"good: ", "good"});
 }
 
+TEST(ParameterHints, NameConstReference) {
+  // Only name hint for const l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(const int& param);
+void bar() {
+  foo($param[[42]]);
+}
+  )cpp",
+   ExpectedHint{"param: ", "param"});
+}
+
+TEST(ParameterHints, NameTypeAliasConstReference) {
+  // Only name hint for const l-value ref parameter via type alias.
+  assertParameterHints(R"cpp(
+using alias = const int&;
+void foo(alias param);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{"param: ", "param"});
+}
+
+TEST(ParameterHints, NameReference) {
+  // Reference and name hint for l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int& param);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{": ", "param"});
+}
+
+TEST(ParameterHints, NameTypeAliasReference) {
+  // Reference and name hint for l-value ref parameter via type alias.
+  assertParameterHints(R"cpp(
+using alias = int&;
+void foo(alias param);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{": ", "param"});
+}
+
+TEST(ParameterHints, NameRValueReference) {
+  // Only name hint for r-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&& param);
+void bar() {
+  foo($param[[42]]);
+}
+  )cpp",
+   ExpectedHint{"param: ", "param"});
+}
+
 TEST(ParameterHints, Operator) {
   // No hint for operator call with operator syntax.
   assertParameterHints(R"cpp(
@@ -301,6 +393,21 @@
ExpectedHint{"param: ", "param"});
 }
 
+TEST(ParameterHints, ArgMatchesParamReference) {
+  assertParameterHints(R"cpp(
+void foo(int& param);
+void foo2(const int& param);
+void bar() {
+  int param;
+  // show reference hint on mutable reference
+  foo($param[[param]]);
+  // but not on const reference
+  foo2(param);
+}
+  )cpp",
+   ExpectedHint{"&: ", "param"});
+}
+
 TEST(ParameterHints, LeadingUnderscore) {
   assertParameterHints(R"cpp(
 void foo(int p1, int _p2, int __p3);
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -10,6 +10,7 @@
 #include "Config.h"
 #include "HeuristicResolver.h"
 #include "ParsedAST.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
@@ -392,6 +393,7 @@
 // Don't show hints for variadic parameters.
 size_t FixedParamCount = getFixedParamCount(Callee);
 size_t ArgCount = std::min(FixedParamCount, Args.size());
+auto Params = Callee->parameters();
 
 NameVec ParameterNames = chooseParameterNames(Callee, ArgCount);
 
@@ -402,12 +404,14 @@
 
 for (size_t I = 0; I < ArgCount; ++I) {
   StringRef Name = ParameterNames[I];
-  if (!shouldHint(Args[I], Name))
-continue;
+  bool NameHint = shouldHintName(Args[I], Name);
+  bool ReferenceHint = shouldHintReference(Params[I]);
 
-  addInlayHint(Args[I]->getSourceRange(), HintSide::Left,
-   

[PATCH] D124359: [clangd] Add inlay hints for mutable reference parameters

2022-05-02 Thread Nathan Ridge via Phabricator via cfe-commits
nridge accepted this revision.
nridge added a comment.
This revision is now accepted and ready to land.

Thanks!

Final nit: please update the commit message as it's a bit out of date, and then 
I'll go ahead and merge




Comment at: clang-tools-extra/clangd/unittests/InlayHintTests.cpp:168
+void bar() {
+  foo($param[[42]]);
+}

nit: the annotation can be removed


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124359/new/

https://reviews.llvm.org/D124359

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124359: [clangd] Add inlay hints for mutable reference parameters

2022-05-02 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj updated this revision to Diff 426346.
upsj marked an inline comment as done.
upsj added a comment.

add test for const ref inlay hint via type alias


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124359/new/

https://reviews.llvm.org/D124359

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -138,6 +138,38 @@
   )cpp");
 }
 
+TEST(ParameterHints, NoNameConstReference) {
+  // No hint for anonymous const l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(const int&);
+void bar() {
+  foo(42);
+}
+  )cpp");
+}
+
+TEST(ParameterHints, NoNameReference) {
+  // Reference hint for anonymous l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{"&: ", "param"});
+}
+
+TEST(ParameterHints, NoNameRValueReference) {
+  // No reference hint for anonymous r-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&&);
+void bar() {
+  foo($param[[42]]);
+}
+  )cpp");
+}
+
 TEST(ParameterHints, NameInDefinition) {
   // Parameter name picked up from definition if necessary.
   assertParameterHints(R"cpp(
@@ -162,6 +194,66 @@
ExpectedHint{"good: ", "good"});
 }
 
+TEST(ParameterHints, NameConstReference) {
+  // Only name hint for const l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(const int& param);
+void bar() {
+  foo($param[[42]]);
+}
+  )cpp",
+   ExpectedHint{"param: ", "param"});
+}
+
+TEST(ParameterHints, NameTypeAliasConstReference) {
+  // Only name hint for const l-value ref parameter via type alias.
+  assertParameterHints(R"cpp(
+using alias = const int&;
+void foo(alias param);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{"param: ", "param"});
+}
+
+TEST(ParameterHints, NameReference) {
+  // Reference and name hint for l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int& param);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{": ", "param"});
+}
+
+TEST(ParameterHints, NameTypeAliasReference) {
+  // Reference and name hint for l-value ref parameter via type alias.
+  assertParameterHints(R"cpp(
+using alias = int&;
+void foo(alias param);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{": ", "param"});
+}
+
+TEST(ParameterHints, NameRValueReference) {
+  // Only name hint for r-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&& param);
+void bar() {
+  foo($param[[42]]);
+}
+  )cpp",
+   ExpectedHint{"param: ", "param"});
+}
+
 TEST(ParameterHints, Operator) {
   // No hint for operator call with operator syntax.
   assertParameterHints(R"cpp(
@@ -301,6 +393,21 @@
ExpectedHint{"param: ", "param"});
 }
 
+TEST(ParameterHints, ArgMatchesParamReference) {
+  assertParameterHints(R"cpp(
+void foo(int& param);
+void foo2(const int& param);
+void bar() {
+  int param;
+  // show reference hint on mutable reference
+  foo($param[[param]]);
+  // but not on const reference
+  foo2(param);
+}
+  )cpp",
+   ExpectedHint{"&: ", "param"});
+}
+
 TEST(ParameterHints, LeadingUnderscore) {
   assertParameterHints(R"cpp(
 void foo(int p1, int _p2, int __p3);
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -10,6 +10,7 @@
 #include "Config.h"
 #include "HeuristicResolver.h"
 #include "ParsedAST.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
@@ -392,6 +393,7 @@
 // Don't show hints for variadic parameters.
 size_t FixedParamCount = getFixedParamCount(Callee);
 size_t ArgCount = std::min(FixedParamCount, Args.size());
+auto Params = Callee->parameters();
 
 NameVec ParameterNames = chooseParameterNames(Callee, ArgCount);
 
@@ -402,12 +404,14 @@
 
 for (size_t I = 0; I < ArgCount; ++I) {
   StringRef Name = ParameterNames[I];
-  if (!shouldHint(Args[I], Name))
-continue;
+  bool NameHint = shouldHintName(Args[I], Name);
+  bool ReferenceHint = shouldHintReference(Params[I]);
 
-  addInlayHint(Args[I]->getSourceRange(), HintSide::Left,
-  

[PATCH] D124359: [clangd] Add inlay hints for mutable reference parameters

2022-05-02 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj updated this revision to Diff 426344.
upsj added a comment.

right, arcanist doesn't entirely match my git mental model. Here's the 
(hopefully) complete patch


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124359/new/

https://reviews.llvm.org/D124359

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -138,6 +138,38 @@
   )cpp");
 }
 
+TEST(ParameterHints, NoNameConstReference) {
+  // No hint for anonymous const l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(const int&);
+void bar() {
+  foo(42);
+}
+  )cpp");
+}
+
+TEST(ParameterHints, NoNameReference) {
+  // Reference hint for anonymous l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{"&: ", "param"});
+}
+
+TEST(ParameterHints, NoNameRValueReference) {
+  // No reference hint for anonymous r-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&&);
+void bar() {
+  foo($param[[42]]);
+}
+  )cpp");
+}
+
 TEST(ParameterHints, NameInDefinition) {
   // Parameter name picked up from definition if necessary.
   assertParameterHints(R"cpp(
@@ -162,6 +194,53 @@
ExpectedHint{"good: ", "good"});
 }
 
+TEST(ParameterHints, NameConstReference) {
+  // Only name hint for const l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(const int& param);
+void bar() {
+  foo($param[[42]]);
+}
+  )cpp",
+   ExpectedHint{"param: ", "param"});
+}
+
+TEST(ParameterHints, NameReference) {
+  // Reference and name hint for l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int& param);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{": ", "param"});
+}
+
+TEST(ParameterHints, NameTypeAliasReference) {
+  // Reference and name hint for l-value ref parameter via type alias.
+  assertParameterHints(R"cpp(
+using alias = int&;
+void foo(alias param);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{": ", "param"});
+}
+
+TEST(ParameterHints, NameRValueReference) {
+  // Only name hint for r-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&& param);
+void bar() {
+  foo($param[[42]]);
+}
+  )cpp",
+   ExpectedHint{"param: ", "param"});
+}
+
 TEST(ParameterHints, Operator) {
   // No hint for operator call with operator syntax.
   assertParameterHints(R"cpp(
@@ -301,6 +380,21 @@
ExpectedHint{"param: ", "param"});
 }
 
+TEST(ParameterHints, ArgMatchesParamReference) {
+  assertParameterHints(R"cpp(
+void foo(int& param);
+void foo2(const int& param);
+void bar() {
+  int param;
+  // show reference hint on mutable reference
+  foo($param[[param]]);
+  // but not on const reference
+  foo2(param);
+}
+  )cpp",
+   ExpectedHint{"&: ", "param"});
+}
+
 TEST(ParameterHints, LeadingUnderscore) {
   assertParameterHints(R"cpp(
 void foo(int p1, int _p2, int __p3);
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -10,6 +10,7 @@
 #include "Config.h"
 #include "HeuristicResolver.h"
 #include "ParsedAST.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
@@ -392,6 +393,7 @@
 // Don't show hints for variadic parameters.
 size_t FixedParamCount = getFixedParamCount(Callee);
 size_t ArgCount = std::min(FixedParamCount, Args.size());
+auto Params = Callee->parameters();
 
 NameVec ParameterNames = chooseParameterNames(Callee, ArgCount);
 
@@ -402,12 +404,14 @@
 
 for (size_t I = 0; I < ArgCount; ++I) {
   StringRef Name = ParameterNames[I];
-  if (!shouldHint(Args[I], Name))
-continue;
+  bool NameHint = shouldHintName(Args[I], Name);
+  bool ReferenceHint = shouldHintReference(Params[I]);
 
-  addInlayHint(Args[I]->getSourceRange(), HintSide::Left,
-   InlayHintKind::ParameterHint, /*Prefix=*/"", Name,
-   /*Suffix=*/": ");
+  if (NameHint || ReferenceHint) {
+addInlayHint(Args[I]->getSourceRange(), HintSide::Left,
+ InlayHintKind::ParameterHint, ReferenceHint ? "&" : "",
+ NameHint ? Name : "", ": ");
+  }
 

[PATCH] D124359: [clangd] Add inlay hints for mutable reference parameters

2022-05-02 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

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 
)




Comment at: clang-tools-extra/clangd/unittests/InlayHintTests.cpp:223
+  assertParameterHints(R"cpp(
+using alias = int&;
+void foo(alias param);

For good measure, let's add an `alias = const int&` case (expecting no `&`) as 
well


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124359/new/

https://reviews.llvm.org/D124359

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124359: [clangd] Add inlay hints for mutable reference parameters

2022-05-02 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj added a comment.

Thanks, on second thought moving the hint to the prefix also makes more sense 
to me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124359/new/

https://reviews.llvm.org/D124359

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124359: [clangd] Add inlay hints for mutable reference parameters

2022-05-02 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj updated this revision to Diff 426343.
upsj marked 4 inline comments as done.
upsj added a comment.

address review comments: Move reference hint to the prefix, test type aliases


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124359/new/

https://reviews.llvm.org/D124359

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -157,18 +157,17 @@
   foo($param[[i]]);
 }
   )cpp",
-   ExpectedHint{"&", "param"});
+   ExpectedHint{"&: ", "param"});
 }
 
 TEST(ParameterHints, NoNameRValueReference) {
-  // Reference hint for anonymous r-value ref parameter.
+  // No reference hint for anonymous r-value ref parameter.
   assertParameterHints(R"cpp(
 void foo(int&&);
 void bar() {
   foo($param[[42]]);
 }
-  )cpp",
-   ExpectedHint{"&&", "param"});
+  )cpp");
 }
 
 TEST(ParameterHints, NameInDefinition) {
@@ -215,18 +214,31 @@
   foo($param[[i]]);
 }
   )cpp",
-   ExpectedHint{"param: &", "param"});
+   ExpectedHint{": ", "param"});
+}
+
+TEST(ParameterHints, NameTypeAliasReference) {
+  // Reference and name hint for l-value ref parameter via type alias.
+  assertParameterHints(R"cpp(
+using alias = int&;
+void foo(alias param);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{": ", "param"});
 }
 
 TEST(ParameterHints, NameRValueReference) {
-  // Reference and name hint for r-value ref parameter.
+  // Only name hint for r-value ref parameter.
   assertParameterHints(R"cpp(
 void foo(int&& param);
 void bar() {
   foo($param[[42]]);
 }
   )cpp",
-   ExpectedHint{"param: &&", "param"});
+   ExpectedHint{"param: ", "param"});
 }
 
 TEST(ParameterHints, Operator) {
@@ -380,7 +392,7 @@
   foo2(param);
 }
   )cpp",
-   ExpectedHint{"&", "param"});
+   ExpectedHint{"&: ", "param"});
 }
 
 TEST(ParameterHints, LeadingUnderscore) {
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -404,17 +404,13 @@
 
 for (size_t I = 0; I < ArgCount; ++I) {
   StringRef Name = ParameterNames[I];
-  bool NameHint = shouldNameHint(Args[I], Name);
-  std::string Suffix = ": ";
-  if (!NameHint) {
-Name = "";
-Suffix = "";
-  }
-  Suffix += getRefSuffix(Params[I]);
+  bool NameHint = shouldHintName(Args[I], Name);
+  bool ReferenceHint = shouldHintReference(Params[I]);
 
-  if (!Name.empty() || !Suffix.empty()) {
+  if (NameHint || ReferenceHint) {
 addInlayHint(Args[I]->getSourceRange(), HintSide::Left,
- InlayHintKind::ParameterHint, /*Prefix=*/"", Name, Suffix);
+ InlayHintKind::ParameterHint, ReferenceHint ? "&" : "",
+ NameHint ? Name : "", ": ");
   }
 }
   }
@@ -442,16 +438,7 @@
 return WhatItIsSetting.equals_insensitive(ParamNames[0]);
   }
 
-  StringRef getRefSuffix(const ParmVarDecl *Param) {
-// If the parameter is a non-const reference type, print an inlay hint
-auto Type = Param->getType();
-return Type->isReferenceType() &&
-   !Type.getNonReferenceType().isConstQualified()
-   ? (Type->isLValueReferenceType() ? "&" : "&&")
-   : "";
-  }
-
-  bool shouldNameHint(const Expr *Arg, StringRef ParamName) {
+  bool shouldHintName(const Expr *Arg, StringRef ParamName) {
 if (ParamName.empty())
   return false;
 
@@ -467,6 +454,13 @@
 return true;
   }
 
+  bool shouldHintReference(const ParmVarDecl *Param) {
+// If the parameter is a non-const reference type, print an inlay hint
+auto Type = Param->getType();
+return Type->isLValueReferenceType() &&
+   !Type.getNonReferenceType().isConstQualified();
+  }
+
   // Checks if "E" is spelled in the main file and preceded by a C-style comment
   // whose contents match ParamName (allowing for whitespace and an optional "="
   // at the end.
@@ -580,7 +574,7 @@
 return Result;
   }
 
-  // We pass HintSide rather than SourceLocation because we want to ensure 
+  // We pass HintSide rather than SourceLocation because we want to ensure
   // it is in the same file as the common file range.
   void addInlayHint(SourceRange R, HintSide Side, InlayHintKind Kind,
 llvm::StringRef Prefix, llvm::StringRef Label,

[PATCH] D124359: [clangd] Add inlay hints for mutable reference parameters

2022-05-02 Thread Nathan Ridge via Phabricator via cfe-commits
nridge requested changes to this revision.
nridge added a comment.
This revision now requires changes to proceed.

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.




Comment at: clang-tools-extra/clangd/InlayHints.cpp:448
+auto Type = Param->getType();
+return Type->isLValueReferenceType() &&
+   !Type.getNonReferenceType().isConstQualified()

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).



Comment at: clang-tools-extra/clangd/InlayHints.cpp:454
+
+  bool shouldNameHint(const Expr *Arg, StringRef ParamName) {
 if (ParamName.empty())

nit: `shouldHintName` would make more sense to me as a revised method name



Comment at: clang-tools-extra/clangd/unittests/InlayHintTests.cpp:217
+  )cpp",
+   ExpectedHint{"param: &", "param"});
+}

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 `: `.



Comment at: clang-tools-extra/clangd/unittests/InlayHintTests.cpp:382
+  )cpp",
+   ExpectedHint{"&", "param"});
+}

Similarly, and for consistency with other parameter hints, `&: ` would make 
sense to me here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124359/new/

https://reviews.llvm.org/D124359

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124359: [clangd] Add inlay hints for mutable reference parameters

2022-04-30 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj updated this revision to Diff 426217.
upsj added a comment.

don't add reference inlay hints for r-value refs


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124359/new/

https://reviews.llvm.org/D124359

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -138,6 +138,38 @@
   )cpp");
 }
 
+TEST(ParameterHints, NoNameConstReference) {
+  // No hint for anonymous const l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(const int&);
+void bar() {
+  foo(42);
+}
+  )cpp");
+}
+
+TEST(ParameterHints, NoNameReference) {
+  // Reference hint for anonymous l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{"&", "param"});
+}
+
+TEST(ParameterHints, NoNameRValueReference) {
+  // No reference hint for anonymous r-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&&);
+void bar() {
+  foo($param[[42]]);
+}
+  )cpp");
+}
+
 TEST(ParameterHints, NameInDefinition) {
   // Parameter name picked up from definition if necessary.
   assertParameterHints(R"cpp(
@@ -162,6 +194,40 @@
ExpectedHint{"good: ", "good"});
 }
 
+TEST(ParameterHints, NameConstReference) {
+  // Only name hint for const l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(const int& param);
+void bar() {
+  foo($param[[42]]);
+}
+  )cpp",
+   ExpectedHint{"param: ", "param"});
+}
+
+TEST(ParameterHints, NameReference) {
+  // Reference and name hint for l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int& param);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{"param: &", "param"});
+}
+
+TEST(ParameterHints, NameRValueReference) {
+  // Only name hint for r-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&& param);
+void bar() {
+  foo($param[[42]]);
+}
+  )cpp",
+   ExpectedHint{"param: ", "param"});
+}
+
 TEST(ParameterHints, Operator) {
   // No hint for operator call with operator syntax.
   assertParameterHints(R"cpp(
@@ -301,6 +367,21 @@
ExpectedHint{"param: ", "param"});
 }
 
+TEST(ParameterHints, ArgMatchesParamReference) {
+  assertParameterHints(R"cpp(
+void foo(int& param);
+void foo2(const int& param);
+void bar() {
+  int param;
+  // show reference hint on mutable reference
+  foo($param[[param]]);
+  // but not on const reference
+  foo2(param);
+}
+  )cpp",
+   ExpectedHint{"&", "param"});
+}
+
 TEST(ParameterHints, LeadingUnderscore) {
   assertParameterHints(R"cpp(
 void foo(int p1, int _p2, int __p3);
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -10,6 +10,7 @@
 #include "Config.h"
 #include "HeuristicResolver.h"
 #include "ParsedAST.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
@@ -392,6 +393,7 @@
 // Don't show hints for variadic parameters.
 size_t FixedParamCount = getFixedParamCount(Callee);
 size_t ArgCount = std::min(FixedParamCount, Args.size());
+auto Params = Callee->parameters();
 
 NameVec ParameterNames = chooseParameterNames(Callee, ArgCount);
 
@@ -402,12 +404,18 @@
 
 for (size_t I = 0; I < ArgCount; ++I) {
   StringRef Name = ParameterNames[I];
-  if (!shouldHint(Args[I], Name))
-continue;
+  bool NameHint = shouldNameHint(Args[I], Name);
+  std::string Suffix = ": ";
+  if (!NameHint) {
+Name = "";
+Suffix = "";
+  }
+  Suffix += getRefSuffix(Params[I]);
 
-  addInlayHint(Args[I]->getSourceRange(), HintSide::Left,
-   InlayHintKind::ParameterHint, /*Prefix=*/"", Name,
-   /*Suffix=*/": ");
+  if (!Name.empty() || !Suffix.empty()) {
+addInlayHint(Args[I]->getSourceRange(), HintSide::Left,
+ InlayHintKind::ParameterHint, /*Prefix=*/"", Name, Suffix);
+  }
 }
   }
 
@@ -434,12 +442,21 @@
 return WhatItIsSetting.equals_insensitive(ParamNames[0]);
   }
 
-  bool shouldHint(const Expr *Arg, StringRef ParamName) {
+  StringRef getRefSuffix(const ParmVarDecl *Param) {
+// If the parameter is a non-const reference type, print an inlay hint
+auto Type = Param->getType();
+

[PATCH] D124359: [clangd] Add inlay hints for mutable reference parameters

2022-04-29 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj added inline comments.



Comment at: clang-tools-extra/clangd/InlayHints.cpp:448-450
+return Type->isReferenceType() &&
+   !Type.getNonReferenceType().isConstQualified()
+   ? (Type->isLValueReferenceType() ? "&" : "&&")

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


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124359/new/

https://reviews.llvm.org/D124359

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124359: [clangd] Add inlay hints for mutable reference parameters

2022-04-27 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj updated this revision to Diff 425432.
upsj added a comment.

add tests for reference inlay hints


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124359/new/

https://reviews.llvm.org/D124359

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -138,6 +138,39 @@
   )cpp");
 }
 
+TEST(ParameterHints, NoNameConstReference) {
+  // No hint for anonymous const l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(const int&);
+void bar() {
+  foo(42);
+}
+  )cpp");
+}
+
+TEST(ParameterHints, NoNameReference) {
+  // Reference hint for anonymous l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{"&", "param"});
+}
+
+TEST(ParameterHints, NoNameRValueReference) {
+  // Reference hint for anonymous r-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&&);
+void bar() {
+  foo($param[[42]]);
+}
+  )cpp",
+   ExpectedHint{"&&", "param"});
+}
+
 TEST(ParameterHints, NameInDefinition) {
   // Parameter name picked up from definition if necessary.
   assertParameterHints(R"cpp(
@@ -162,6 +195,40 @@
ExpectedHint{"good: ", "good"});
 }
 
+TEST(ParameterHints, NameConstReference) {
+  // Only name hint for const l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(const int& param);
+void bar() {
+  foo($param[[42]]);
+}
+  )cpp",
+   ExpectedHint{"param: ", "param"});
+}
+
+TEST(ParameterHints, NameReference) {
+  // Reference and name hint for l-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int& param);
+void bar() {
+  int i;
+  foo($param[[i]]);
+}
+  )cpp",
+   ExpectedHint{"param: &", "param"});
+}
+
+TEST(ParameterHints, NameRValueReference) {
+  // Reference and name hint for r-value ref parameter.
+  assertParameterHints(R"cpp(
+void foo(int&& param);
+void bar() {
+  foo($param[[42]]);
+}
+  )cpp",
+   ExpectedHint{"param: &&", "param"});
+}
+
 TEST(ParameterHints, Operator) {
   // No hint for operator call with operator syntax.
   assertParameterHints(R"cpp(
@@ -301,6 +368,21 @@
ExpectedHint{"param: ", "param"});
 }
 
+TEST(ParameterHints, ArgMatchesParamReference) {
+  assertParameterHints(R"cpp(
+void foo(int& param);
+void foo2(const int& param);
+void bar() {
+  int param;
+  // show reference hint on mutable reference
+  foo($param[[param]]);
+  // but not on const reference
+  foo2(param);
+}
+  )cpp",
+   ExpectedHint{"&", "param"});
+}
+
 TEST(ParameterHints, LeadingUnderscore) {
   assertParameterHints(R"cpp(
 void foo(int p1, int _p2, int __p3);
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -10,6 +10,7 @@
 #include "Config.h"
 #include "HeuristicResolver.h"
 #include "ParsedAST.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
@@ -392,6 +393,7 @@
 // Don't show hints for variadic parameters.
 size_t FixedParamCount = getFixedParamCount(Callee);
 size_t ArgCount = std::min(FixedParamCount, Args.size());
+auto Params = Callee->parameters();
 
 NameVec ParameterNames = chooseParameterNames(Callee, ArgCount);
 
@@ -402,12 +404,18 @@
 
 for (size_t I = 0; I < ArgCount; ++I) {
   StringRef Name = ParameterNames[I];
-  if (!shouldHint(Args[I], Name))
-continue;
+  bool NameHint = shouldNameHint(Args[I], Name);
+  std::string Suffix = ": ";
+  if (!NameHint) {
+Name = "";
+Suffix = "";
+  }
+  Suffix += getRefSuffix(Params[I]);
 
-  addInlayHint(Args[I]->getSourceRange(), HintSide::Left,
-   InlayHintKind::ParameterHint, /*Prefix=*/"", Name,
-   /*Suffix=*/": ");
+  if (!Name.empty() || !Suffix.empty()) {
+addInlayHint(Args[I]->getSourceRange(), HintSide::Left,
+ InlayHintKind::ParameterHint, /*Prefix=*/"", Name, Suffix);
+  }
 }
   }
 
@@ -434,12 +442,21 @@
 return WhatItIsSetting.equals_insensitive(ParamNames[0]);
   }
 
-  bool shouldHint(const Expr *Arg, StringRef ParamName) {
+  StringRef getRefSuffix(const ParmVarDecl *Param) {
+// If the parameter is a non-const reference type, print an inlay 

[PATCH] D124359: [clangd] Add inlay hints for mutable reference parameters

2022-04-27 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

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.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124359/new/

https://reviews.llvm.org/D124359

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124359: [clangd] Add inlay hints for mutable reference parameters

2022-04-25 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj created this revision.
upsj added a reviewer: nridge.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: All.
upsj requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Add a & or && annotation to all parameter inlay hints that refer to a non-const 
reference. That makes it easier to identify them even if semantic highlighting 
is not used (where this is already available)


https://reviews.llvm.org/D124359

Files:
  clang-tools-extra/clangd/InlayHints.cpp


Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -10,6 +10,7 @@
 #include "Config.h"
 #include "HeuristicResolver.h"
 #include "ParsedAST.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
@@ -392,6 +393,7 @@
 // Don't show hints for variadic parameters.
 size_t FixedParamCount = getFixedParamCount(Callee);
 size_t ArgCount = std::min(FixedParamCount, Args.size());
+auto Params = Callee->parameters();
 
 NameVec ParameterNames = chooseParameterNames(Callee, ArgCount);
 
@@ -402,12 +404,18 @@
 
 for (size_t I = 0; I < ArgCount; ++I) {
   StringRef Name = ParameterNames[I];
-  if (!shouldHint(Args[I], Name))
-continue;
+  bool NameHint = shouldNameHint(Args[I], Name);
+  std::string Suffix = ": ";
+  if (!NameHint) {
+Name = "";
+Suffix = "";
+  }
+  Suffix += getRefSuffix(Params[I]);
 
-  addInlayHint(Args[I]->getSourceRange(), HintSide::Left,
-   InlayHintKind::ParameterHint, /*Prefix=*/"", Name,
-   /*Suffix=*/": ");
+  if (!Name.empty() || !Suffix.empty()) {
+addInlayHint(Args[I]->getSourceRange(), HintSide::Left,
+ InlayHintKind::ParameterHint, /*Prefix=*/"", Name, 
Suffix);
+  }
 }
   }
 
@@ -434,12 +442,21 @@
 return WhatItIsSetting.equals_insensitive(ParamNames[0]);
   }
 
-  bool shouldHint(const Expr *Arg, StringRef ParamName) {
+  StringRef getRefSuffix(const ParmVarDecl *Param) {
+// If the parameter is a non-const reference type, print an inlay hint
+auto Type = Param->getType();
+return Type->isReferenceType() &&
+   !Type.getNonReferenceType().isConstQualified()
+   ? (Type->isLValueReferenceType() ? "&" : "&&")
+   : "";
+  }
+
+  bool shouldNameHint(const Expr *Arg, StringRef ParamName) {
 if (ParamName.empty())
   return false;
 
 // If the argument expression is a single name and it matches the
-// parameter name exactly, omit the hint.
+// parameter name exactly, omit the name hint.
 if (ParamName == getSpelledIdentifier(Arg))
   return false;
 


Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -10,6 +10,7 @@
 #include "Config.h"
 #include "HeuristicResolver.h"
 #include "ParsedAST.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
@@ -392,6 +393,7 @@
 // Don't show hints for variadic parameters.
 size_t FixedParamCount = getFixedParamCount(Callee);
 size_t ArgCount = std::min(FixedParamCount, Args.size());
+auto Params = Callee->parameters();
 
 NameVec ParameterNames = chooseParameterNames(Callee, ArgCount);
 
@@ -402,12 +404,18 @@
 
 for (size_t I = 0; I < ArgCount; ++I) {
   StringRef Name = ParameterNames[I];
-  if (!shouldHint(Args[I], Name))
-continue;
+  bool NameHint = shouldNameHint(Args[I], Name);
+  std::string Suffix = ": ";
+  if (!NameHint) {
+Name = "";
+Suffix = "";
+  }
+  Suffix += getRefSuffix(Params[I]);
 
-  addInlayHint(Args[I]->getSourceRange(), HintSide::Left,
-   InlayHintKind::ParameterHint, /*Prefix=*/"", Name,
-   /*Suffix=*/": ");
+  if (!Name.empty() || !Suffix.empty()) {
+addInlayHint(Args[I]->getSourceRange(), HintSide::Left,
+ InlayHintKind::ParameterHint, /*Prefix=*/"", Name, Suffix);
+  }
 }
   }
 
@@ -434,12 +442,21 @@
 return WhatItIsSetting.equals_insensitive(ParamNames[0]);
   }
 
-  bool shouldHint(const Expr *Arg, StringRef ParamName) {
+  StringRef getRefSuffix(const ParmVarDecl *Param) {
+// If the parameter is a non-const reference type, print an inlay hint
+auto Type = Param->getType();
+return Type->isReferenceType() &&
+   !Type.getNonReferenceType().isConstQualified()
+   ? (Type->isLValueReferenceType() ? "&" : "&&")
+   : "";
+