Using "Open in IDE" with VS Code and WSL

Not sure if this should be posted somewhere else but I thought I’d share a hint that may be useful if, like me, you are using Windows 11, VS Code and developing in WSL.

If you use the “Open in IDE” button in SonarQube or SonarCloud, it tries to access http://localhost:<port> where port is 64120 to 64130. If you are developing in WSL then the SonarLint embedded server is running within WSL and not on Windows itself so the connection fails.

With WSL2, however, there is a new network mode: mirrored. This causes WSL to “share” the networ connections with Windows and, hey presto!, Open in IDE now works.

You need to have a file called “.wslconfig” in your Windows home directory and contents like the following:

[wsl2]
networkingMode=mirrored

You may need to restart any running distributions.

Further information about this setting and the configuration file can be found at Advanced settings configuration in WSL | Microsoft Learn

3 Likes

Hi,

Thanks for posting this; it’s truly a great contribution and we’re gong to update the docs with it!

 
Thx,
Ann

1 Like