[clang] [clang-tools-extra] [clangd] Autocomplete fixes for methods (PR #165916)
Nathan Ridge via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 28 00:17:38 PST 2025
https://github.com/HighCommander4 requested changes to this pull request.
Thanks for working on this, it's an important issue that has been bothering a lot of people!
Unfortunately, the current implementation approach regresses the current (intentional) behaviour that when you're taking the address of a function, function parameters are **not** inserted.
For example:
```c++
struct Test {
void fun(int a, int b, int c);
};
int main() {
Test t;
&Test::f^
}
```
The expected completion here is just `fun`, but with this patch it will be `fun(int a, int b, int c)`.
(This is reflected in the test case `CompletionTest.HeuristicsForMemberFunctionCompletion`. We want to keep this test case passing without changes to the expectations.)
I think the way this should be implemented is that in SemaCodeComplete, we determine whether we are completing the declaration/definition of a function, or a use of it.
Sam gave a hint for how to do this in [this comment](https://github.com/clangd/clangd/issues/880#issuecomment-961533830):
> It looks like ParseOptionalCXXScopeSpecifier also doesn't know, so maybe the right thing is to add yet another boolean parameter there and pass `true` if we're parsing a declarator.
(`ParseOptionalCXXScopeSpecifier` is the caller of `SemaCodeCompletion::CodeCompleteQualifiedId`, so the idea would be to pass this new boolean parameter into `CodeCompleteQualifiedId`.)
Once we have this piece of knowledge available in SemaCodeComplete, we can implement more of the "definition vs. use" logic there. For example, rather than doctoring the code completion string in clangd to remove the placehoders in the "definition" case, we can just not add placeholder chunks in the first place.
If you'd like to give implementing this approach a try and have some follow-up questions, please don't hesitate to ask, either here or in the clangd Discord channel.
https://github.com/llvm/llvm-project/pull/165916
More information about the cfe-commits
mailing list