[clang-tools-extra] 7bad74e - [clangd] Show argument names for function pointer struct fields (#69011)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 5 20:33:59 PST 2024
Author: Qwinci
Date: 2024-03-05T23:33:55-05:00
New Revision: 7bad74e66756ca2fd1fe4f5864e7123fb4553d78
URL: https://github.com/llvm/llvm-project/commit/7bad74e66756ca2fd1fe4f5864e7123fb4553d78
DIFF: https://github.com/llvm/llvm-project/commit/7bad74e66756ca2fd1fe4f5864e7123fb4553d78.diff
LOG: [clangd] Show argument names for function pointer struct fields (#69011)
Show argument names in signature help when calling a function pointer
struct field.
Added:
Modified:
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang/lib/Sema/SemaCodeComplete.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 6d387fec9b3851..5721feecd58ea8 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1462,6 +1462,23 @@ TEST(SignatureHelpTest, FunctionPointers) {
typedef void (__stdcall *fn)(int x, int y);
fn foo;
int main() { foo(^); }
+ )cpp",
+ // Field of function pointer type
+ R"cpp(
+ struct S {
+ void (*foo)(int x, int y);
+ };
+ S s;
+ int main() { s.foo(^); }
+ )cpp",
+ // Field of function pointer typedef type
+ R"cpp(
+ typedef void (*fn)(int x, int y);
+ struct S {
+ fn foo;
+ };
+ S s;
+ int main() { s.foo(^); }
)cpp"};
for (auto Test : Tests)
EXPECT_THAT(signatures(Test).signatures,
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index c44be0df9b0a85..8d75239009401e 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -6137,6 +6137,7 @@ ProduceSignatureHelp(Sema &SemaRef, MutableArrayRef<ResultCandidate> Candidates,
// so that we can recover argument names from it.
static FunctionProtoTypeLoc GetPrototypeLoc(Expr *Fn) {
TypeLoc Target;
+
if (const auto *T = Fn->getType().getTypePtr()->getAs<TypedefType>()) {
Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
@@ -6145,6 +6146,11 @@ static FunctionProtoTypeLoc GetPrototypeLoc(Expr *Fn) {
if (const auto *const VD = dyn_cast<VarDecl>(D)) {
Target = VD->getTypeSourceInfo()->getTypeLoc();
}
+ } else if (const auto *ME = dyn_cast<MemberExpr>(Fn)) {
+ const auto *MD = ME->getMemberDecl();
+ if (const auto *FD = dyn_cast<FieldDecl>(MD)) {
+ Target = FD->getTypeSourceInfo()->getTypeLoc();
+ }
}
if (!Target)
More information about the cfe-commits
mailing list