Extensions for the built-in Language Server Protocol support in Neovim (>= 0.8.0) for sonarlint-language-server (>= 2.16.0.65434).
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',
},
-- All settings are optional
settings = {
-- The default for sonarlint is {}, this is just an example
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 } }
}
}
}
},
filetypes = {
-- Tested and working
'python',
'cpp',
-- Requires nvim-jdtls, otherwise an error message will be printed
'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"),
},
-- All settings are optional
settings = {
-- The default for sonarlint is {}, this is just an example
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 } }
}
}
}
},
filetypes = {
-- Tested and working
'python',
'cpp',
-- Requires nvim-jdtls, otherwise an error message will be printed
'java',
}
})