clangd / clangd

clangd language server
https://clangd.llvm.org
Apache License 2.0
1.51k stars 63 forks source link

When I define a function with default arguments, it doesn't help me complete the default arguments automatically。 #753

Open JY1Lnz opened 3 years ago

JY1Lnz commented 3 years ago

Please describe the problem. when i define a function with default arguments,it will only complete non-default parameters。 Is there a way to set all parameters for completion? Logs

System information Output of clangd --version: v0.1.11 Editor/LSP plugin: clangd Operating system:windows 10

kadircet commented 3 years ago

I suppose you are talking about snippets for arguments in code completion. We don't include them deliberately, since deleting the defaulted parameters would be more work for the common case.

You should be seeing signature help when you want to modify defaulted parameters though. Is this not working for you or not enough in some cases?

JY1Lnz commented 3 years ago
// A.h
class A
{
    int f(int a, int b = 0);
};
// A.cpp
int A::f(int a); // This is the default

He might recognize my definition in another file as a function call. Is there any way to solve it?

kadircet commented 3 years ago

ah I see. That's an accidental use of code completion. we should check whether clang has enough context here to tell us that we are defining a symbol, and if so we can try to render completion strings differently (drop default args, use concrete text rather than snippets).

in the meantime, you can instead try defining the method inline and invoking define out-of-line code action afterwards, e.g:

class A {
  int f(int a, int b = 0) { return 0; } // once you invoke code actions here, you should get the define out-of-line, which will move the body into `A::f` in `A.cpp`.
};