Author: Younan Zhang Date: 2023-02-26T19:06:44+08:00 New Revision: cb2d04d41e47e65812434f775215247bfe19b3dd
URL: https://github.com/llvm/llvm-project/commit/cb2d04d41e47e65812434f775215247bfe19b3dd DIFF: https://github.com/llvm/llvm-project/commit/cb2d04d41e47e65812434f775215247bfe19b3dd.diff LOG: [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 Added: Modified: clang-tools-extra/clangd/InlayHints.cpp clang-tools-extra/clangd/unittests/InlayHintTests.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/InlayHints.cpp b/clang-tools-extra/clangd/InlayHints.cpp index a009f84d448ae..aa85551b1cedb 100644 --- a/clang-tools-extra/clangd/InlayHints.cpp +++ b/clang-tools-extra/clangd/InlayHints.cpp @@ -516,8 +516,8 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> { // at the end. bool isPrecededByParamNameComment(const Expr *E, StringRef ParamName) { auto &SM = AST.getSourceManager(); - auto ExprStartLoc = SM.getTopMacroCallerLoc(E->getBeginLoc()); - auto Decomposed = SM.getDecomposedLoc(ExprStartLoc); + auto FileLoc = SM.getFileLoc(E->getBeginLoc()); + auto Decomposed = SM.getDecomposedLoc(FileLoc); if (Decomposed.first != MainFileID) return false; diff --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp index da9073c77f7c9..cda86f30c3da6 100644 --- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp +++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp @@ -1050,9 +1050,15 @@ TEST(ParameterHints, ParamNameComment) { void bar() { foo(/*param*/42); foo( /* param = */ 42); +#define X 42 +#define Y X +#define Z(...) Y + foo(/*param=*/Z(a)); + foo($macro[[Z(a)]]); foo(/* the answer */$param[[42]]); } )cpp", + ExpectedHint{"param: ", "macro"}, ExpectedHint{"param: ", "param"}); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits