Setting up connected mode in VS Code

[Update: I’ve come across the FAQ now, sorry for not checking those before :man_facepalming: I’ve enabled extended log output and am now indeed seeing some connection issues being reported. I will look into those. I would still expect the plugin to not respond with a success message in such cases, though.]

Apologies if this has been answered before. All of the topics I could find were older ones from early 2019 or even older and still reference settings that no longer seem to exist (specifically, sonarlint.connectedMode.project).

I am trying to set up the Sonarlint plugin (1.15.0) in VS Code (1.42.1 on MacOS 10.15.3) to connect to a remote SonarQube instance in order to set my local ruleset to the project’s rules defined on the server. I have my user and project settings in VS Code set up thus:

User settings:

"sonarlint.connectedMode.connections.sonarqube": [
    {
        "serverUrl": "<server url goes here>",
        "token": "<secret token goes here>"
    }
]

Project settings:

"sonarlint.connectedMode.project": {
    "projectKey": "<project key goes here>"
}

This is all in accordance with the help and documentation I could find, both on the Sonarlint plugin settings page in VS Code and on the Sonarlint website. If I then trigger the “SonarLint: Update all project bindings” option, I get back a success message. However, none of my local settings seem to have actually been updated. Moreover, I get the same success message even if I delete all of the settings I’ve described above, so I’m getting the feeling that no actual communication with the server ever takes place.

Accessing the server requires both a VPN connection and (in the browser, at least) an HTTP proxy. The VPN connection is active as I try this; however, I do not have a system-wide proxy configuration; just one in the browser. I would expect to receive an error message from the Sonarlint plugin however in case this was a problem that leads to connection failures.

Is it possible that the success message is a false positive and the connection actually fails silently in the background? How can I verify definitively that everything works as intended? Did I make any mistakes in my settings?

Any help is appreciated, thanks!

Hi @jpkempf

I’m interested to have more details about the connection issues you faced, to understand why there is a success message.

Sure, here’s a dump of the logs that I’m getting so far. Not sure if that helps, but my best bet right now is that the request fails due to the absence of a system-wide proxy configuration, so there would probably be a timeout at some point.

[Info  - 17:26:54.063] Starting SonarTS Server
[Info  - 17:26:57.490] Using typescript at [/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript], version 3.7.5
[Info  - 17:26:57.518] SonarTS Server is started
[Info  - 17:26:57.518] SonarTS Server connected to 50679
[Warn  - 17:27:03.782] No storage for server '<default>'. Please update.
[Warn  - 17:28:03.935] No storage for server '<default>'. Please update.
[Error - 17:28:03.937] Error updating storage of the connected SonarLint engine '<default>'
[Error - 17:28:03.938] java.lang.IllegalStateException: Fail to request https://sonarqube.<redacted>.de/api/system/status
	at org.sonarsource.sonarlint.core.util.ws.HttpConnector.doCall(HttpConnector.java:196)
	at org.sonarsource.sonarlint.core.util.ws.HttpConnector.get(HttpConnector.java:122)
	at org.sonarsource.sonarlint.core.util.ws.HttpConnector.call(HttpConnector.java:109)
	at org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient.rawGet(SonarLintWsClient.java:120)
	at org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient.get(SonarLintWsClient.java:85)
	at org.sonarsource.sonarlint.core.container.connected.validate.ServerVersionAndStatusChecker.lambda$fetchServerInfos$0(ServerVersionAndStatusChecker.java:97)
	at org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient.processTimed(SonarLintWsClient.java:226)
	at org.sonarsource.sonarlint.core.container.connected.validate.ServerVersionAndStatusChecker.fetchServerInfos(ServerVersionAndStatusChecker.java:96)
	at org.sonarsource.sonarlint.core.container.connected.validate.ServerVersionAndStatusChecker.checkVersionAndStatus(ServerVersionAndStatusChecker.java:60)
	at org.sonarsource.sonarlint.core.container.connected.validate.ServerVersionAndStatusChecker.checkVersionAndStatus(ServerVersionAndStatusChecker.java:50)
	at org.sonarsource.sonarlint.core.container.connected.update.perform.GlobalStorageUpdateExecutor.update(GlobalStorageUpdateExecutor.java:77)
	at org.sonarsource.sonarlint.core.container.connected.ConnectedContainer.update(ConnectedContainer.java:115)
	at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.lambda$update$1(ConnectedSonarLintEngineImpl.java:174)
	at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.runInConnectedContainer(ConnectedSonarLintEngineImpl.java:311)
	at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.lambda$update$2(ConnectedSonarLintEngineImpl.java:174)
	at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.withRwLock(ConnectedSonarLintEngineImpl.java:325)
	at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.update(ConnectedSonarLintEngineImpl.java:169)
	at org.sonarsource.sonarlint.ls.connected.ProjectBindingManager.updateGlobalStorageAndLogResults(ProjectBindingManager.java:344)
	at org.sonarsource.sonarlint.ls.connected.ProjectBindingManager.createConnectedEngineAndUpdateIfNeeded(ProjectBindingManager.java:173)
	at org.sonarsource.sonarlint.ls.connected.ProjectBindingManager.lambda$getOrCreateConnectedEngine$1(ProjectBindingManager.java:152)
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
	at org.sonarsource.sonarlint.ls.connected.ProjectBindingManager.getOrCreateConnectedEngine(ProjectBindingManager.java:152)
	at org.sonarsource.sonarlint.ls.connected.ProjectBindingManager.computeProjectBinding(ProjectBindingManager.java:122)
	at org.sonarsource.sonarlint.ls.connected.ProjectBindingManager.lambda$getBinding$0(ProjectBindingManager.java:109)
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
	at org.sonarsource.sonarlint.ls.connected.ProjectBindingManager.getBinding(ProjectBindingManager.java:102)
	at org.sonarsource.sonarlint.ls.AnalysisManager.analyze(AnalysisManager.java:229)
	at org.sonarsource.sonarlint.ls.AnalysisManager.lambda$analyzeAsync$0(AnalysisManager.java:205)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: java.net.SocketTimeoutException: Connect timed out
	at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:546)
	at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:597)
	at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:339)
	at java.base/java.net.Socket.connect(Socket.java:603)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.platform.Platform.connectSocket(Platform.java:130)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:263)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.connection.RealConnection.connect(RealConnection.java:183)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:224)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:108)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.java:88)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.connection.Transmitter.newExchange(Transmitter.java:169)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
	at org.sonarsource.sonarlint.shaded.okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
	at org.sonarsource.sonarlint.shaded.okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:221)
	at org.sonarsource.sonarlint.shaded.okhttp3.RealCall.execute(RealCall.java:81)
	at org.sonarsource.sonarlint.core.util.ws.HttpConnector.doCall(HttpConnector.java:194)
	... 30 more```

Proxy are indeed a concern in VSCode. If your proxy doesn’t require authentification, you should be able to pass -Dhttp.proxyHost=yourproxy.com -Dhttp.proxyPort=12345 to the SonarLint language server using the VM arguments setting:

That’s good to know! I’m afraid it does require authentication, though :sweat_smile: I might have to go the system-wide proxy way, or perhaps there are tools that proxy connection requests made by certain applications. Will have to research. Any idea why the connection errors never end up in the editor notification?

We tend to avoid being too annoying, especially when there is an issue during on the fly analysis, since it may lead to a lot of recurrent error message.

But when you manually trigger an update of the binding, there should be some feedback. I did some tests, and there is indeed no error message surfacing (but I don’t have a success message either).
I have created a ticket to improve that:
https://jira.sonarsource.com/browse/SLVSCODE-119

Thanks! Feel free to ping me in case I can provide any additional input on that. Once I figure out my particular problem, I’ll post the solution here.

I’m happy to report that my connection issues are resolved for the moment—I configured Proxifier to catch outbound connection requests from my IDEs to SonarQube and route them through my proxy server. I’ve also confirmed that everything does indeed work, so that’s great! I’m really happy now (apart from the fact that I wasn’t able to solve this issue without having to resort to additional software, but I can hardly blame anyone here for that).

While confirming everthing is working, however, I did come across another confusing thing that I thought I’d mention here. I’ve noticed that the rules that make up the actual quality profile in effect for a project are not reflected properly in the local IDE; instead you see what I think is the default “SonarQube way” list of rules.

WebStorm does include a hint above the list of rules pointing out that these settings might get overridden by a connected server, but VS Code gives no such information. The only way to make sure the correct rules are being enforced is to find a rule that is active on the server but marked as inactive in the IDE, breaking it somewhere deliberately and seeing whether or not the SonarLint plugin complains about it.

Wouldn’t it make sense to actually keep the local quality profiles in sync with the ones coming in from the server? Either as a read-only display or possibly even allowing two-way sync to save changes a user makes in their IDE? At the very least I think there should be a hint displayed in VS Code similar to the one in WebStorm, but it’d be far nicer if a user could actually see the profile that is in effect without having to open the SonarQube web interface.

Besides that, everything is fine now—thank you for your time so far and for providing a great service! :slight_smile:

Hi @jpkempf

Thanks for the update, this is much appreciated, and could be useful for others.

Regarding the confusion about rules configuration panel, your are not the first to report it, so I guess we’ll have to do something about it. The problem is the same in all IDEs (except maybe IntelliJ): you can have in your workspace multiple projects (or root folders), each one having a different binding (or no binding).
So a good UI is not easy to find.

For now our choice is to reserve the rules configuration UI to the configuration of the local quality profile (used by unbound projects). This is not used to visualize the quality profile fetched from the server (we assume you can use SonarQube/SonarCloud UI to do so).

1 Like

I completely understand there may be lots of cases making this more complicated than it seems to me in my current scenario :slight_smile: Thanks for the explanation and keep up the good work!

A post was split to a new topic: ConnectionClosedException in SonarLint VSCode when using a proxy