[clang] [clang-tools-extra] [clang] skip explicit obj param in code complete (PR #146258)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 29 09:04:41 PDT 2025


https://github.com/HighCommander4 commented:

Thanks! This is a nice and simple fix.

 * It fixes the main issue as originally reported.
 * It fixes the additional issue discussed in [this comment](https://github.com/clangd/clangd/issues/2339#issuecomment-2709036107), taking the second approach (rendering the signature as `f(int arg)`), which I think is perfectly fine as that's what falls out naturally from this implementation.
 * It does not fix https://github.com/clangd/clangd/issues/2284, which is fine, it was just speculation on my part that https://github.com/clangd/clangd/issues/2339 and https://github.com/clangd/clangd/issues/2284 may have the same cause. (That said, if you're interested, https://github.com/clangd/clangd/issues/2284 would make a good follow-up issue to investigate next.)

The clangd test looks great, thanks for writing it! That said, based on my experience contributing changes to SemaCodeComplete.cpp, people like to **also** ask for a test to be added to libSema's own test suite. These tests work a bit differently: they're found at `clang/test/CodeCompletion` (see for example [this file](https://searchfox.org/llvm/source/clang/test/CodeCompletion/ordinary-name.cpp)), and they operate by running clang with the special `-code-complete-at` flag which invokes code completion at a point in the input file and prints the results in some format.

So for example, given `test.cpp` containing:

```c++
struct A
{
    void f(this A self, int arg);
};

int main() {
  A a;
  a.f
}
```

The command `clang -cc1 -fsyntax-only -code-completion-at=test.cpp:8:5 -std=c++23 test.cpp` would previously print:

```c++
COMPLETION: A : A::
COMPLETION: f : [#void#]f(<#A self#>, <#int arg#>)
COMPLETION: operator= : [#A &#]operator=(<#const A &#>)
COMPLETION: operator= : [#A &#]operator=(<#A &&#>)
COMPLETION: ~A : [#void#]~A()
```

and with this patch it prints:

```
COMPLETION: A : A::
COMPLETION: f : [#void#]f(<#int arg#>)
COMPLETION: operator= : [#A &#]operator=(<#const A &#>)
COMPLETION: operator= : [#A &#]operator=(<#A &&#>)
COMPLETION: ~A : [#void#]~A()
```

allowing us to write a test that asserts that the output is the latter.

Would you mind writing a test of this form as well?

https://github.com/llvm/llvm-project/pull/146258


More information about the cfe-commits mailing list