Dumb-Ptr · 2022-02-20 13:36
Hi, I'm following the system crafters' guide "emacs from scratch", and in the video on LSP, I wrote down the three things he says are needed:
1. a backend (lsp-mode in his case)
2. a frontend (typescript-mode in his case)
3. a language server (ts-ls in his case)
So I was wondering if this scheme holds true even for c/c++, if so, what packages for these three "categories" do I need?
coolstuff39 · 2022-02-20 13:56
1. lsp-mode
2. c++-mode/c-mode/java-mode/etc are built-in
3. clangd or ccls
Check this: https://emacs-lsp.github.io/lsp-mode/tutorials/CPP-guide/
0x1bee · 2022-02-20 13:57
1. You need a lsp-client i.e. lsp-mode (or eglot) package for emacs, which provides emacs the ability to communicate with a language-server.
2. A language server for C/C++. I use clangd.
Dumb-Ptr · 2022-02-20 14:47
ok thanks
Soupeeee · 2022-02-20 18:13
In order for clangd (and maybe ccls?) to work properly, you need to build the compilation database with clang rather than gcc: clangd will choke on the gcc headers due to them using nonstandard things.
keyeh1 · 2022-02-20 20:47
If you are using cmake in your project you can set the property `CMAKE_EXPORT_COMPILE_COMMANDS` to `TRUE`. CMake will create `compile_commands.json` file in the project directory and Clangd will automatically detect this file and work as intended (you may need to make a symlink for it). This works independently of the compiler used to compile the project.
topiolli · 2022-02-21 06:49
Prepare for trouble. I've been trying to set up a C++ IDE with Emacs for a few years and gone through different tags (e.g. `ctags`, `rtags`) systems, auto-completion back-ends (such as `ycmd`) and lsp implementations (`lsp-mode` and `eglot` with `cquery`, `ccls` and `clangd`). I even experimented with Microsoft's non-free Intellisense that comes with vscode, but it didn't fare any better than the others. I'm currently using `lsp-mode` with `clangd`, which is the best combo so far, but still quite unreliable.
The problem, AFAIK, is in `libclang` which is used by both `clangd` and `ccls` for indexing the source code. It works fine for small projects, but allocates (leaks?) enormous amounts of memory when applied on a bigger code base. I have had to create a wrapper script for `clangd` that ulimits its memory usage to avoid freezing my desktop. This sometimes causes a crash loop that forces me to close the lsp session, but it is better than rendering the whole system unusable.
Another annoying thing is the compilation database (`compile_commands.json`), which needs to contain the compile flags for every file in the project. In my big repository, the file is huge and very slow to update. Furthermore, I'm mostly not using `cmake` which could create the file automatically, and using tools such as `bear` require actually compiling the C++ files to get the build flags. I ended up writing a script that parses Makefiles and writes per-directory `.clangd` files instead.
J-ky · 2022-02-21 08:17
I don’t know how big your code base is. I had troubles with clangd with lsp-mode, it often freeze Emacs when jumping around definition.
I managed to fix it by using eglot and clangd. It is so much better in memory usage and performance.
Dumb-Ptr · 2022-02-21 10:49
Damn, i don't i'll be able to make all of this lol. For now c++ is not as important for me... I think i'll use vscode for c/c++
topiolli · 2022-02-21 12:34
I kind of hope it wasn't that important to me either. :) Vscode is actually worse in my code base. Microsoft's C++ language server crashes within seconds if I try to open any file in the repository. I believe the problem is rooted at C++, which has become such a complex beast that no tool can handle it properly. I have never had problems with C code, any of the solutions I listed would just work.
theMachine0094 · 2022-02-21 21:13
This guide is awesome. I set this up almost 6 months ago and never used another ide for cpp since.