Skip to content

Commit cb2d04d

Browse files
committed
[clangd] Hide inlay hints when using a macro as a calling argument that with a param comment
We don't want to produce inlay hints for arguments for which user has left param name comments. But we're not decomposing location of the parameter correctly at the moment because the location we've passed into `SM.getDecomposedLoc` is not always FileID. Fixes clangd/clangd#1495 Reviewed By: nridge Differential Revision: https://reviews.llvm.org/D144074
1 parent d9f6077 commit cb2d04d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

clang-tools-extra/clangd/InlayHints.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,8 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
516516
// at the end.
517517
bool isPrecededByParamNameComment(const Expr *E, StringRef ParamName) {
518518
auto &SM = AST.getSourceManager();
519-
auto ExprStartLoc = SM.getTopMacroCallerLoc(E->getBeginLoc());
520-
auto Decomposed = SM.getDecomposedLoc(ExprStartLoc);
519+
auto FileLoc = SM.getFileLoc(E->getBeginLoc());
520+
auto Decomposed = SM.getDecomposedLoc(FileLoc);
521521
if (Decomposed.first != MainFileID)
522522
return false;
523523

clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,9 +1050,15 @@ TEST(ParameterHints, ParamNameComment) {
10501050
void bar() {
10511051
foo(/*param*/42);
10521052
foo( /* param = */ 42);
1053+
#define X 42
1054+
#define Y X
1055+
#define Z(...) Y
1056+
foo(/*param=*/Z(a));
1057+
foo($macro[[Z(a)]]);
10531058
foo(/* the answer */$param[[42]]);
10541059
}
10551060
)cpp",
1061+
ExpectedHint{"param: ", "macro"},
10561062
ExpectedHint{"param: ", "param"});
10571063
}
10581064

0 commit comments

Comments
 (0)