Skip to content

Commit

Permalink
Update Configuring-clangd-lsp.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Freaxed authored Nov 2, 2023
1 parent 3280f56 commit 23c833e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions Configuring-clangd-lsp.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Configuring Clangd / LSP
For more advanced IDE feateures, Genio implements the LSP protocol. (https://microsoft.github.io/language-server-protocol/)
One of the most advanged C and C++ lsp server is 'clangd' included in the clang compiler suite. (more info https://clangd.llvm.org/)

For more advanced IDE feateures, Genio implements the LSP protocol. (<https://microsoft.github.io/language-server-protocol/>)
One of the most advanged C and C++ lsp server is 'clangd' included in the clang compiler suite. (more info <https://clangd.llvm.org/>)

First pre-requisite is to install these packages:

* latest LLVM (clang) (at the time of writing is version 17)
* gcc_syslibs_devel package

Expand All @@ -16,34 +18,38 @@ Keep in mind that clangd tries to compile and index a set of files to provide th
Two main configuration point:

## The project

To let understand clangd how you want each file to be compiled, you should provide a compile database file (compile_commands.json).
The file contains, for each file of the project, the list of all the flags and include paths your compiler needs.
There are usefull tools to let you create the compile_commands.json file automatically from a building tool like make, jam or cmake.
Usually this is enough to let clangd work correctly in most cases.

### For make

The best tool so far tested is the python program called 'compiledb'. Run it as "compiledb make -Bnwk" to produce the database.

compiledb: https://github.com/nickdiego/compiledb (pip3 install compiledb)
compiledb: <https://github.com/nickdiego/compiledb> (pip3 install compiledb)

Another tool available on HaikuDepot is 'bear' (https://github.com/rizsotto/Bear)
Another tool available on HaikuDepot is 'bear' (<https://github.com/rizsotto/Bear>)

### For cmake
>
> cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ...
or, in CMakeLists.txt

> add set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

### For Jam (haiku version)
>
> jam -c
More info: https://www.freelists.org/post/haiku-development/linting-and-autocomplete-How-to-generate-compile-commandsjson-alternatives
More info: <https://www.freelists.org/post/haiku-development/linting-and-autocomplete-How-to-generate-compile-commandsjson-alternatives>

More info https://clang.llvm.org/docs/JSONCompilationDatabase.html
More info <https://clang.llvm.org/docs/JSONCompilationDatabase.html>

## The compiler itself

With the default configuration, clangd should already recognize system include paths. If you want to add more includes or finetune some settings you need to add a configuration file.
The best place to create the file is at "/boot/home/config/settings/clangd/config.yaml".
More info with all the configuration flags can be found here: https://clangd.llvm.org/config
More info with all the configuration flags can be found here: <https://clangd.llvm.org/config>

0 comments on commit 23c833e

Please sign in to comment.