SonarLint for VSCode: C/C++ support

Hello,

Are there plans to add C/C++ language support the SonarLint plugin in VSCode ?

Thanks

Hello,

We don’t plan to add C/C++ support in VSCode this year. Can’t tell yet about the next one.

Hello,

Is there any update?

Thanks

Hi @n-mm,

not yet, sorry about that, what is clear is that its demand is increasing.

(I moved the thread to feature suggestion category so that interested people can vote for it)

Just to make everybody aware, the difficulty on our side is that our C/C++ analyzer needs to collect compilation properties (compiler flags/arguments/includes locations) to work properly.
When analyzing a project using the SonarQube scanner, we ask users to collect those informations using a build wrapper command line tool. This is not practical in SonarLint.

In SonarLint for Visual Studio, we are dynamically getting those information using Visual Studio APIs.

We haven’t started any investigation for now, but to achieve the same in VSCode, it is likely we will need to hook into the C/C++ VSCode extension. We might even depends on a collaboration with the C/C++ VSCode extension maintainers, so that they expose the informations to our extension.

1 Like

I see. I think you may look into the Intellisense support (specifically the C/C++ intellisense extension), that’s the location of “semantic” data of your program.

The intellisense is populated by various extensions that provide support for code editing. For example, if you use the CMake extension, it will tell Intellisense about various compilation flags (after the code has been built) so code navigation/completion is correct. You can reuse this information in SonarLint.

How about the C++ Eclipse integration? That has no Visual Studio APIs either. So could that not be a starting point?
Personally I do not mind adding them manually in a special setting/property. I have multiple tasks each having different build options.
This could be a good start, and at a later stage this could be automated (optionally). In my opinion and experience automated systems always make the wrong decision ;-).

Hi @Juno,

what do you mean with this question? FYI, C++ for SonarLint on Eclipse CDT is already available.

In Eclipse, we are relying on Eclipse CDT APIs to collect the information we need:

I gave a quick look at the vscode-cpp extension, and I couldn’t find an API to read the effective project configuration. There is an API but only to provide the configuration:

I initiated a feature request on VSCode Cpptools side to have an API usable by our C/C++ analyzer. If you are waiting for SonarLint C/C++ support in VSCode, feel free to vote for it:

2 Likes

Sorry for my late reply.

Personally it is fine if I have to enter the values using a project setting/configuration. A colleague does for Eclipse.
Or rely on the “C/C++ IntelliSense, debugging, and code browsing.” extension. It also analyses the source files for coloring and jumping to definitions.
But probably this is already considered…

Thanx.

Hi,

Does it mean that Sonarlint for C/C++ will rely on cpptools extension? What about developers using clangd or other language servers instead of cpptools? Will SonarLint work for them?

Thanks

Hello, thank you for raising this point.

Our assumption here is that most C and C++ developers in VSCode use the cpptools extension, which looks like a kind of “standard”.

In a perfect world, we would have infinite bandwidth and we would strive to support all possible use cases - and in this reality, we have to choose which use cases to support first :slight_smile: especially when the landscape is fragmented.

In this case and according to marketplace numbers, cpptools has 12 million downloads, to the 72k of clangd; so from an adoption point of view, it looks fairly straightforward to target the cpptools user base first, and to eventually address other demographics.