Support VSCode cmake-tools plugin

  • Operating system: Win10
  • IDE name and flavor/env: VSCode + cmake-tools plugin
  • SonarLint plugin version: 3.4.1
  • Is connected mode used: Irrelevant

People use CMake to build C++ projects for different architectures/oses/modes. This results in different paths for the compile_command.json file.
SonarLint should take this into account and switch the referenced file based on the used CMake Kit or Preset used by cmake-tools.

This can be done by evaluating the cmake-tools command: ${command:cmake.buildDirectory}. See: Get path to Build dir / compile_commands.json for configuring other extensions · Issue #2528 · microsoft/vscode-cmake-tools · GitHub, vscode-cmake-tools/cmake-settings.md at main · microsoft/vscode-cmake-tools · GitHub

Sonarlint could also autodetect if this is a CMake project and when cmake-tools is installed, use this as the default search path.

Hi again @KUGA2,

I am not a user of cmake-tools so I want to understand your need first.

I gave a quick try and it appears to me that if you change the kit or variant, the compile_commands.json file is modified in place. In your use case do you have multiple compile_commands.json files in different directories ? Could you explain how you achieve that ?

Thanks

You can (and you should to avoid rebuilds!) specify different outputs directories. I can provide you a basic example if you want. Do you prefer Linux or Windows?

Hint: See binaryDir
PS: I think you should always prefer presets over Kits/Variants, because presets is supported by the CMake developers and the other thing was a solution by the plugin, before presets were implemented.

@Damien_Urruty Do you want a demo project or not? Windows or Linux?

Hi folks,

As we handled this feature request on Commercial Support, I was due to update this post to let the Community knows about the outcome, but I forgot back in May, so here I do now!

We discussed the use case internally and tracked it in our insights tool. It is a corner case for now, but interesting nonetheless. Indeed the most realistic solution appears to be able to evaluate the ${command:cmake.buildDirectory} in the path provided into sonarlint.pathToCompileCommands. Whatever CMake extension is used will populate this variable and SonarLint will read it. This is only limited to extensions that take care of ${command:cmake.buildDirectory} of course but it’s already an improvement.

This is not a priority for now but we have it recorded to track further similar requests.

Cheers
Antoine

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.