Extensions for the built-in Language Server Protocol support in Neovim (>= 0.8.0) for sonarlint-language-server (>= 2.16.0.65434).
For Java projects nvim-jdtls
is required to resolve classpath
configurations that is then required to configure sonarlint-language-server as
expected.
For certain features, e.g. Connected Mode, sonarlint-language-server needs to gather information about source code management (SCM). Therefore, sonarlint.nvim gathers these information via [gitsgins][gitsigns] plugin. If there is no gitsigns installed, sonarlint.nvim assumes that there is no SCM provider.
This repository is work in progress and the API is likely to change.
You can install the sonarlint-ls by extracting it from the sonarlint-vscode plugin. Head over to the releases and download the latest *.vsix
file. As it is a ZIP file, it contains the sonarlint-ls.jar
and all available analyzers. Extract these JAR files from the extension/server/
and extension/analyzers/
, and configure sonarlint.nvim
according to the setup section.
If you are using mason.nvim
you can simply do :MasonInstall sonarlint-language-server
. See below for setup instructions when using this method.
local lspconfig = require('lspconfig')
-- do stuff with lspconfig
require('sonarlint').setup({
-- …
})
require('sonarlint').setup({
server = {
cmd = {
'java', '-jar', 'sonarlint-language-server-VERSION.jar',
-- Ensure that sonarlint-language-server uses stdio channel
'-stdio',
'-analyzers', 'path/to/analyzer1.jar', 'path/to/analyzer2.jar', 'path/to/analyzer3.jar',
},
},
filetypes = {
-- Tested and working
'python',
'cpp',
'java',
}
})
require('sonarlint').setup({
server = {
cmd = {
'sonarlint-language-server',
-- Ensure that sonarlint-language-server uses stdio channel
'-stdio',
'-analyzers',
-- paths to the analyzers you need, using those for python and java in this example
vim.fn.expand("$MASON/share/sonarlint-analyzers/sonarpython.jar"),
vim.fn.expand("$MASON/share/sonarlint-analyzers/sonarcfamily.jar"),
vim.fn.expand("$MASON/share/sonarlint-analyzers/sonarjava.jar"),
}
},
filetypes = {
-- Tested and working
'python',
'cpp',
'java',
}
})
Analyzing C/C++ projects it is required to provide a Compilation Database file (see alse here. Therefore, sonarlint.nvim tries to find the Compilation Database automatically within your workspace. If that doesn't work, you can provide it manually.
require('sonarlint').setup({
server = {
cmd = {
-- …
},
settings = {
sonarlint = {
pathToCompileCommands = "insert your path here"
}
}
},
})
Rules can be configured, e.g. by turning them on or off, with following configuration.
require('sonarlint').setup({
server = {
cmd = {
-- …
},
settings = {
sonarlint = {
rules = {
['typescript:S101'] = { level = 'on', parameters = { format = '^[A-Z][a-zA-Z0-9]*$' } },
['typescript:S103'] = { level = 'on', parameters = { maximumLineLength = 180 } },
['typescript:S106'] = { level = 'on' },
['typescript:S107'] = { level = 'on', parameters = { maximumFunctionParameters = 7 } }
}
}
}
},
})