linwaytin · 2022-10-18 18:39
I use `eglot` with `clang` to do c++ completion.
I noticed that there is no completion for an object. For example, if `A` is object and I type `A.`, I get nothing after the dot. Explicate executing `completion-at-point` returns nothing either.
This happens no matter if the class of `A` is defined in the project or defined in a library. I assume `lsp` should be able to find the member functions. Am I missing some config? If there is a better system, I would like to try. Thanks.
Galizur_HaMalakh · 2022-10-18 23:27
The easiest way to get completion is installing [clangd](https://clangd.llvm.org/installation) and following their simple instructions to get it running.
I personally have never used `eglot`, but as far as I understand, at least for C++, `lsp` and `eglot` are pretty much identical.
I'd also suggest using a more powerful completion backend, such as [company-mode](https://company-mode.github.io/) or [corfu](https://github.com/minad/corfu/) to provide a better experience.
jaafartrull · 2022-10-19 05:19
This *ought* to work. Certainly it does in LSP. I wonder how eglot is configured for you... I believe there is a way.
hangingpawns · 2022-10-19 05:30
Are you generating a compile_commands.json file? That's the first question.
yapfff · 2022-10-19 08:24
Yes. And this file must be in the project top level directory for clangd to see it and associate it with the project's source files.
When building with cmake for example, that won't be the case by default even if cmake generation of compile_commands.json is enabled. The file will be in the cmake build directory. You'll have to create a link to it in the project top level directory.
linwaytin · 2022-10-19 13:06
Thanks for all the replies. I'm using clangd. The problem should be the compile\_commands.json file. I'm gonna try it.
Galizur_HaMalakh · 2022-10-19 18:11
Are you using a build tool/generator? CMake needs a variable to be set for it to produce a compilation database, and Meson does it automatically. If you are using plain makefiles, you will need a tool like Build EAR (bear).
linwaytin · 2022-10-19 18:32
>compile\_commands.json
CMake is used for that project. Could you please tell me how to set up the variable?
linwaytin · 2022-10-19 19:05
I think it is `set(CMAKE_EXPORT_COMPILE_COMMANDS ON)`. Now I have the completion popping up. Thank you!
Galizur_HaMalakh · 2022-10-20 15:41
You can also set it on the command line with `cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1`
linwaytin · 2022-10-20 15:59
That's even better! Thanks a lot.
jamez5800 · 2022-10-22 17:31
It doesn't have to be in the top level folder, clangd searches `build` folders too: https://clangd.llvm.org/installation