forked from OSchip/llvm-project
[clangd] Don't add inlay hints on std::move/forward
This removes parameter inlay hints from a few builtin functions like std::move/std::forward Reviewed By: nridge Differential Revision: https://reviews.llvm.org/D127859
This commit is contained in:
parent
5cfbfa035f
commit
e984e1cd61
|
@ -14,6 +14,7 @@
|
||||||
#include "clang/AST/DeclarationName.h"
|
#include "clang/AST/DeclarationName.h"
|
||||||
#include "clang/AST/ExprCXX.h"
|
#include "clang/AST/ExprCXX.h"
|
||||||
#include "clang/AST/RecursiveASTVisitor.h"
|
#include "clang/AST/RecursiveASTVisitor.h"
|
||||||
|
#include "clang/Basic/Builtins.h"
|
||||||
#include "clang/Basic/SourceManager.h"
|
#include "clang/Basic/SourceManager.h"
|
||||||
#include "llvm/ADT/ScopeExit.h"
|
#include "llvm/ADT/ScopeExit.h"
|
||||||
|
|
||||||
|
@ -400,8 +401,9 @@ private:
|
||||||
NameVec ParameterNames = chooseParameterNames(Callee, ArgCount);
|
NameVec ParameterNames = chooseParameterNames(Callee, ArgCount);
|
||||||
|
|
||||||
// Exclude setters (i.e. functions with one argument whose name begins with
|
// Exclude setters (i.e. functions with one argument whose name begins with
|
||||||
// "set"), as their parameter name is also not likely to be interesting.
|
// "set"), and builtins like std::move/forward/... as their parameter name
|
||||||
if (isSetter(Callee, ParameterNames))
|
// is also not likely to be interesting.
|
||||||
|
if (isSetter(Callee, ParameterNames) || isSimpleBuiltin(Callee))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (size_t I = 0; I < ArgCount; ++I) {
|
for (size_t I = 0; I < ArgCount; ++I) {
|
||||||
|
@ -440,6 +442,21 @@ private:
|
||||||
return WhatItIsSetting.equals_insensitive(ParamNames[0]);
|
return WhatItIsSetting.equals_insensitive(ParamNames[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks if the callee is one of the builtins
|
||||||
|
// addressof, as_const, forward, move(_if_noexcept)
|
||||||
|
static bool isSimpleBuiltin(const FunctionDecl *Callee) {
|
||||||
|
switch (Callee->getBuiltinID()) {
|
||||||
|
case Builtin::BIaddressof:
|
||||||
|
case Builtin::BIas_const:
|
||||||
|
case Builtin::BIforward:
|
||||||
|
case Builtin::BImove:
|
||||||
|
case Builtin::BImove_if_noexcept:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool shouldHintName(const Expr *Arg, StringRef ParamName) {
|
bool shouldHintName(const Expr *Arg, StringRef ParamName) {
|
||||||
if (ParamName.empty())
|
if (ParamName.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -555,6 +555,17 @@ TEST(ParameterHints, SetterFunctions) {
|
||||||
ExpectedHint{"timeout_millis: ", "timeout_millis"});
|
ExpectedHint{"timeout_millis: ", "timeout_millis"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(ParameterHints, BuiltinFunctions) {
|
||||||
|
// This prototype of std::forward is sufficient for clang to recognize it
|
||||||
|
assertParameterHints(R"cpp(
|
||||||
|
namespace std { template <typename T> T&& forward(T&); }
|
||||||
|
void foo() {
|
||||||
|
int i;
|
||||||
|
std::forward(i);
|
||||||
|
}
|
||||||
|
)cpp");
|
||||||
|
}
|
||||||
|
|
||||||
TEST(ParameterHints, IncludeAtNonGlobalScope) {
|
TEST(ParameterHints, IncludeAtNonGlobalScope) {
|
||||||
Annotations FooInc(R"cpp(
|
Annotations FooInc(R"cpp(
|
||||||
void bar() { foo(42); }
|
void bar() { foo(42); }
|
||||||
|
|
Loading…
Reference in New Issue