Assistance integrating SonarLint into Vim LSP

I am a Vim user and would like to use Sonarlint with the new vim9 LSP plugin.

The coc-sonarlint plugin for CoC works quite well. I am trying to use the same arguments here to run it with the Vim9 LSP, but am getting the following output

https://0x0.st/XZlC.txt

It seems like the workspace is not set up correctly and the compile_command.json is not provided. Unfortunately I can’t find proper documentation on sonarlint-ls.

Here is the issue I’ve created in the Vim9 LSP repo, where you can see which arguments I am using. Maybe something is missing.

Hi there @jclsn, thanks for your interest in SonarLint

Disclaimer: I have zero experience with CoC or Vim9

Line from SonarLint Language Server output Failed to initialize workspace folders could mean a range of things, and TBH I don’t think it would be related to not having a path to compile commands :thinking:

We are currently improving the log messages to include the actual stacktrace of what failed. You should be able to see more complete logs once we merge this PR.

Hope that helps,
Sophio from :sonarlint_vscode:

Yes, I expected that, since Vim is more of a niche IDE. Nonetheless there are plugins that support the Language Server Protocol also used by VSCode. So yes it would be great if the logging and documentation on how to talk to the Sonarlint server improved. I also have to admit that the Vim9 LSP plugin hasn’t fully matured yet. So it might not send the right commands to the server.

FYI the PR is now merged.

For inspiration, here is the initialization options passed from VSCode client to the SonarLint Language Server. And here is where sonarlint.pathToCompileCommands is first read, but it is not required until analysis of related language file is triggered.

The general behavior is the following: on startup, the client sends an initialize request to the Language Server, which includes the initializationOptions linked above. Once everything is initialized, the client sends a didChangeConfiguration notification to the Language Server, providing all settings on the client side, including the pathToCompileCommands.

All the best,
Sophio

Thanks, but I think I do lack the skills to get this working. The CoC or Neovim plugins which exist are heavily based on the VSCode plugin and I have literally zero skills in Typescript nor am I motivated to learn it. I was hoping I could provide a workspaceConfig and initializationOptions and be done, but it seems I would have to write code to get this to work.

1 Like

So I have had some help from another Vimmer. He got the server to start properly

'/usr/bin/sonarlint-ls' Language Server Messages
================================================
06/05/24 17:49:38: [Log]: [Info  - 17:49:38.880] SonarLint backend started, instance=org.sonarsource.sonarlint.core.rpc.impl.SonarLintRpcServerImpl@6bd61f98
06/05/24 17:49:38: [Log]: [Debug - 17:49:38.970] Folder WorkspaceFolder[name=constexpr,uri=file:///home/jan/Workspace/C%2b%2b/constexpr/] added
06/05/24 17:49:38: [Log]: [Debug - 17:49:39.004] Fetching global configuration
06/05/24 17:49:39: [Log]: [Warn  - 17:49:39.016] Using ${workspaceFolder} variable in sonarlint.pathToCompileCommands is only supported for files in the workspace
06/05/24 17:49:40: [Log]: [Info  - 17:49:40.429] Started embedded server on port 64120
06/05/24 17:49:40: [Log]: [Debug - 17:49:40.447] Starting local-only issue database from /home/jan/.sonarlint/xodus-local-only-issue-store18335401968696097033
06/05/24 17:49:40: [Log]: [Debug - 17:49:40.928] Fetching configuration for folder 'file:///home/jan/Workspace/C%2b%2b/constexpr/'
06/05/24 17:49:40: [Log]: [Debug - 17:49:40.934] Workspace folder 'WorkspaceFolder[name=constexpr,uri=file:///home/jan/Workspace/C%2b%2b/constexpr/]' configuration updated: WorkspaceFolderSettings[analyzerProperties={sonar.cs.file.suffixes=.cs, sonar.cs.internal.loadProjectsTimeout=60, sonar.cs.internal.useNet6=true, sonar.cs.internal.loadProjectOnDemand=false},connectionId=<null>,pathToCompileCommands=/home/jan/Workspace/C++/constexpr/build/compile_commands.json,projectKey=<null>,testFilePattern=<null>]
06/05/24 17:49:40: [Log]: [Debug - 17:49:40.935] Global settings updated: WorkspaceSettings[connections={},disableTelemetry=false,excludedRules=[],focusOnNewCode=false,includedRules=[],pathToNodeExecutable=<null>,ruleParameters={},showAnalyzerLogs=false,showVerboseLogs=false]

Sonarlint is not analyzing the file though. I guess I would have to send it a command to do that?

By default, we trigger analysis on file open, so whenever the client sends a textDocument/didOpen notification to the language server.

In VSCode, there is a "sonarlint.trace.server": "verbose" user setting you can use to trace all LSP communication between the client and the language server. Maybe you can give it a go in your environment as well.