How to get VS Code SonarLint to work for projects with sub-projects?

sonarlint
vscode

(Kartik Gola) #1

Hi,

I have a project with the following directory structure -

|my-project
|	|app
|	    |Comps
|       |Utils
|       |Others
|   |OtherFolders

This project contains 2 project keys -

  1. ProjectRoot which contains files inside Utils folder and having paths like - my-project/app/Utils/* in SonarQube
  2. Comps which contains files inside Comps folder having paths like - app/Comps/* in SonarQube

I have the following workspace settings inside my-project -

"sonarlint.connectedMode.project": {
        "serverId": "my_sonarqube_server",
        "projectKey": "ProjectRoot"
 }

My problem is that whenever I open VS Code in my-project folder, SonarLint is unable to fetch batch issues present in Comps files.

Is there any way I can successfully fetch batch issues of the 2 projects in same VS Code window? Like any way to give multiple project keys? I tried placing another workspace setting in app folder with Comps as project key. It works fine if I open VS in app folder & view files in Comps folder but still doesn’t work if VS is opened in my-project.


(Janos Gyerik) #2

Hi,

Indeed, the current release (and the upcoming one) of SonarLint for VSCode doesn’t support binding to multiple projects in the same workspace. We understand this is an important limitation and we plan to add support sometime soon.

Here’s the ticket where you can track progress on this: https://jira.sonarsource.com/browse/SLVSCODE-47


(Alex Soh) #3

Hi i am new to SQ here. Just a question here to see if the same ticket also describes the following scenario that i had in my SQ server project.

__SQ Directory__
|my-project-root
|	|Project1
|	    |Sub-dir-of-project1
|       |WebAPI
|       |WebUI
|       |OthersFolder

Now i would like to attach my WebAPI and WebUI project which are standalone sub-projects contained within a bigger root project in my SQ server. Since i am not the server admin, i am wondering if it is still possible to configure SonarLint those sub-projects using the same projectKey “my-project-root” as follows from “WebAPI” and “WebUI” project

"sonarlint.connectedMode.project": {
        "serverId": "my_sonarqube_server",
        "projectKey": "my-project-root"
 }

Or is it possible to reference the sub-project this way instead

"sonarlint.connectedMode.project": {
        "serverId": "my_sonarqube_server",
        "projectKey": "my-project-root/WebUI"
 }

Do note that both WebAPI and WebUI are consider as different workspace projects so they will have different sonarlint configurations in my case.

I need some advice on what are the best practices for this scenario since all of the sub-projects mentioned here are belong to the same product.


(Janos Gyerik) #4

Hi Alex (@takato1314),

If I understand correctly, your case is different from the first one reported in this thread. In the first post there are multiple SQ projects involved (I think), in your case there seems to be just one.

Your case is supported if WebAPI and WebUI are not sub-modules inside the SQ project. If they are simply sub-directories, then you can open the root project in VSCode, and use the first configuration example you gave above to connect to the project in SonarQube.

If WebAPI and WebUI are sub-modules, then it’s not supported, yet. If you configure VSCode as above, the sub-modules will not be correctly connected. You could connect to the sub-modules directly instead of the project root, but you would need separate VSCode instances, to connect one sub-module per instance. That’s clearly not ideal, and it’s effectively a very similar problem as the one in the first message in this thread.

The good news is that sub-modules will become supported when we drop the concept of modules in SonarQube. That will require the new release of SonarQube that will have this new behavior. You can track the progress on this work here: https://jira.sonarsource.com/browse/MMF-365


(Alex Soh) #5

Yeah i think they are kind of sub-modules since they have different .vscode folder instances in those directories, but it is not a git-submodules (PS: I don’t think git-submodules are related here but i just mention it.). To ensure that we are on the same page, this is how my sample local project directory looks like

__Local Project Directory__
|my-project-root
|	|Project1
|	    |.sonarlint
|	    |.vscode
|	    |Sub-dir-of-project1
|   |WebAPI
|	    |.sonarlint
|	    |.vscode
|   |WebUI
|	    |.sonarlint
|	    |.vscode
|   |OthersFolder

Still, as i just retried and it failed, i saw the following log, is it possible for you to explain what does the following the following error link used for so that i can talk over to my server admin?

GET 404 https://{SQBaseUri}:{SQport}/api/rules/search.protobuf?f=repo,name,severity,lang,htmlDesc,htmlNote,internalKey,isTemplate,templateKey,actives&statuses=BETA,DEPRECATED,READY&organization=&p=1&ps=500 | time=570ms
Create : C:\{localDir}\.sonarlint\plugins
Plugin cache: C:\{localDir}\.sonarlint\plugins
Create : C:\{localDir}\.sonarlint\plugins\_tmp
Load plugins
Load plugins (done) | time=1ms
No plugins loaded
[Warn - 4:36:12 PM] No storage for server '{SQServerId}'. Please update.
[Warn - 4:36:12 PM] Please update server '{SQServerId}'

Btw, the SQ version i used is Version 6.7.4 (build 38452)