diff --git a/docs/src/content/docs/guides/fairmq-tidy.mdx b/docs/src/content/docs/guides/fairmq-tidy.mdx index 04289d79..81b4d2f5 100644 --- a/docs/src/content/docs/guides/fairmq-tidy.mdx +++ b/docs/src/content/docs/guides/fairmq-tidy.mdx @@ -164,6 +164,10 @@ With `fairmq_target_tidy()`, give the option in `EXTRA_ARGS`. A finding then sto fairmq_target_tidy(TARGET mydevice EXTRA_ARGS --warnings-as-errors=fairmq-*) ``` +## See the findings in your editor + +Use `fairmq-clangd` in place of `clangd`, and enable the checks in a `.clangd` file. See [Editor integration](/tools/fairmq-tidy/#editor-integration). + ## Problems that can occur | Message | Cause | Solution | @@ -171,6 +175,8 @@ fairmq_target_tidy(TARGET mydevice EXTRA_ARGS --warnings-as-errors=fairmq-*) | `CMAKE_EXPORT_COMPILE_COMMANDS is not enabled. Skipping.` | The variable is off when `fairmq_target_tidy()` runs. | Set `CMAKE_EXPORT_COMPILE_COMMANDS` to `ON` before the call. | | `Error while trying to load a compilation database` | The tool did not find `compile_commands.json`. | Give the build directory with `-p`. | | `fatal error: '
' file not found` | Clang does not find a header. | Add the include path with `--extra-arg=-I`. | +| `fairmq-clangd` shows no `fairmq-*` findings | `clangd` 18 or later skips checks that it does not know as fast. | Add `FastCheckFilter: Loose` to the `.clangd` file. | +| `clang-tidy --load` fails with `symbol lookup error`, or the plugin finds nothing | The `clang-tidy` has another LLVM major version than the plugin. | Use the `clang-tidy` of the same LLVM version, or `fairmq-tidy`. | | A warning of a check that you did not select, for example `clang-analyzer-*` | The command line has no `--checks`, and the tool runs the checks of the configuration. | Give `--checks='-*,fairmq-*'`. | ## Related pages diff --git a/docs/src/content/docs/reference/cmake.mdx b/docs/src/content/docs/reference/cmake.mdx index ea5453e8..74c97600 100644 --- a/docs/src/content/docs/reference/cmake.mdx +++ b/docs/src/content/docs/reference/cmake.mdx @@ -30,7 +30,8 @@ Some variables on this page are not declared as CMake options. `ccmake` and `cma | `BUILD_FAIRMQ` | `ON` | — | Build the library `libfairmq`, the [built-in devices](/tools/builtin-devices/), [`fairmq-shmmonitor`](/tools/shmmonitor/) and `fairmq-uuid-gen`. | | `BUILD_TESTING` | `OFF` | `BUILD_FAIRMQ` | Build the tests and add them to CTest. | | `BUILD_EXAMPLES` | `ON` | `BUILD_FAIRMQ` | Build the [examples](/examples/1-1/) and their start scripts. With `BUILD_TESTING=ON`, CTest also gets the tests of the examples. | -| `BUILD_TIDY_TOOL` | `OFF` | — | Build the static analyzer [`fairmq-tidy`](/tools/fairmq-tidy/). The configure summary marks it as experimental. | +| `BUILD_TIDY_TOOL` | `OFF` | — | Build the static analyzer [`fairmq-tidy`](/tools/fairmq-tidy/) and its clang-tidy plugin. The configure summary marks it as experimental. | +| `BUILD_TIDY_CLANGD` | `OFF` | `BUILD_TIDY_TOOL` | Build the language server [`fairmq-clangd`](/tools/fairmq-tidy/#editor-integration). | | `USE_EXTERNAL_GTEST` | `OFF` | — | Use an installed GoogleTest, not the bundled copy. The option text in the code says "Not recommended". | | `FAIRMQ_DEBUG_MODE` | `OFF` | — | Compile with the definition `FAIRMQ_DEBUG_MODE`. See [Compile definitions](#compile-definitions). | diff --git a/docs/src/content/docs/tools/fairmq-tidy.mdx b/docs/src/content/docs/tools/fairmq-tidy.mdx index ac7c024f..898d289e 100644 --- a/docs/src/content/docs/tools/fairmq-tidy.mdx +++ b/docs/src/content/docs/tools/fairmq-tidy.mdx @@ -1,15 +1,21 @@ --- title: 'fairmq-tidy' -description: 'clang-tidy with the fairmq-* checks built in. The checks, the build, the command line and the CMake function.' +description: 'clang-tidy with the fairmq-* checks built in. The checks, the build, the command line, the clang-tidy plugin, the editor integration and the CMake function.' sidebar: order: 3 -code: [fairmq/tidy/Module.cxx, fairmq/tidy/runTidy.cxx] +code: [fairmq/tidy/Module.cxx, fairmq/tidy/runTidy.cxx, fairmq/tidy/runClangd.cxx] --- import Snippet from '../../../components/Snippet.astro'; +import { Steps } from '@astrojs/starlight/components'; `fairmq-tidy` is a static analysis tool for code that uses FairMQ. It is `clang-tidy` with the `fairmq-*` checks built in. The checks find deprecated FairMQ names and APIs in your code, and most checks also give a fix that the tool can apply. +The same checks are also available in two other forms: + +- The plugin `libfairmq-tidy-checks.so` adds them to an installed `clang-tidy`. See [clang-tidy plugin](#clang-tidy-plugin). +- `fairmq-clangd` is the language server `clangd` with the checks built in. Your editor then shows the findings while you type. See [Editor integration](#editor-integration). + For a step-by-step procedure, see [Check code with fairmq-tidy](/guides/fairmq-tidy/). This page is the reference. ## How the tool works @@ -103,6 +109,8 @@ cmake -S FairMQ -B build -DBUILD_TIDY_TOOL=ON -DLLVM_DIR=/usr/lib/llvm-18/lib/cm With `BUILD_TIDY_TOOL=ON`, the installation also contains: - `bin/fairmq-tidy`, exported as the imported target `FairMQ::fairmq-tidy`. CMake installs the exported targets only with `BUILD_FAIRMQ=ON` (the default). +- `lib/libfairmq-tidy-checks.so`, the [clang-tidy plugin](#clang-tidy-plugin). +- `bin/fairmq-clangd`, if you also set `BUILD_TIDY_CLANGD=ON`. See [Editor integration](#editor-integration). - `share/fairmq/cmake/FairMQTidy.cmake`, the CMake module with [`fairmq_target_tidy()`](#the-cmake-function-fairmq_target_tidy). - The package component `tidy_tool`. @@ -128,6 +136,41 @@ The command line is the command line of [clang-tidy](https://clang.llvm.org/extr `run-clang-tidy` of LLVM runs `fairmq-tidy` in parallel on all files of a compilation database: `run-clang-tidy -clang-tidy-binary fairmq-tidy -p build`. +## clang-tidy plugin + +The plugin `libfairmq-tidy-checks.so` adds the `fairmq-*` checks to an installed `clang-tidy`. Load it with `--load`: + +```sh +clang-tidy --load=/lib/libfairmq-tidy-checks.so -p build --checks='-*,fairmq-*' src/mydevice.cxx +``` + +- The `clang-tidy` must have the same LLVM major version as the LLVM that FairMQ was built with. The plugin interface has no stable ABI. +- Some distributions build `clang-tidy` without plugin support. Use `fairmq-tidy` there. +- The plugin does not add `--checks=fairmq-*` and the resource directory. Give the checks in `--checks` or in a `.clang-tidy` file. + +## Editor integration + +`clangd` cannot load plugins. Thus FairMQ can build its own `clangd` with the `fairmq-*` checks built in: `fairmq-clangd` ([runClangd.cxx](/source/fairmq/tidy/runClangd.cxx/)). It is the `clangd` of the LLVM installation, and all other features of `clangd` stay the same. The checks run on the syntax tree that `clangd` builds anyway. The editor shows the findings while you type and offers the fixes as quick fixes. + + + +1. Configure FairMQ with `-DBUILD_TIDY_TOOL=ON -DBUILD_TIDY_CLANGD=ON`. The build needs the `clangd` libraries of the LLVM installation. On Debian and Ubuntu, also install `libgrpc++-dev`, `libprotobuf-dev` and `libabsl-dev`. + +2. Configure your editor to start `fairmq-clangd` in place of `clangd`. + +3. Enable the checks in a [`.clangd`](https://clangd.llvm.org/config) file in your project: + + ```yaml + Diagnostics: + ClangTidy: + Add: ["fairmq-*"] + FastCheckFilter: Loose + ``` + + + +Since version 18, `clangd` runs only the checks that it knows as fast. It does not know the `fairmq-*` checks, so they need `FastCheckFilter: Loose`. Without this line, `clangd` skips them and shows no message. + ## The CMake function fairmq_target_tidy The module [`cmake/FairMQTidy.cmake`](https://github.com/FairRootGroup/FairMQ/blob/dev/cmake/FairMQTidy.cmake) defines one function: