-
Notifications
You must be signed in to change notification settings - Fork 13.6k
clangd: Show argument names for function pointer struct fields #69011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clangd Author: None (Qwinci) ChangesShow argument names in signature help when calling a function pointer struct field. Full diff: https://github.com/llvm/llvm-project/pull/69011.diff 2 Files Affected:
diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 766998eb4f3c719..bd88a0912b537d1 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 adb82d3f6d176ab..5e3aed53fd8e218 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -6133,7 +6133,17 @@ 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>()) {
+
+ if (const auto *ME = dyn_cast<MemberExpr>(Fn)) {
+ const auto *MD = ME->getMemberDecl();
+ if (const auto *FD = dyn_cast<FieldDecl>(MD)) {
+ if (const auto *T = FD->getType().getTypePtr()->getAs<TypedefType>()) {
+ Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
+ } else {
+ Target = FD->getTypeSourceInfo()->getTypeLoc();
+ }
+ }
+ } else if (const auto *T = Fn->getType().getTypePtr()->getAs<TypedefType>()) {
Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
} else if (const auto *DR = dyn_cast<DeclRefExpr>(Fn)) {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch!
1e4b524
to
e7380b0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update! Looks good with a final nit.
e7380b0
to
a7e8d6c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Show argument names in signature help when calling a function pointer struct field.