/sonarlint.nvim

GitHub clone of https://gitlab.com/schrieveslaach/sonarlint.nvim

Primary LanguageLuaGNU General Public License v3.0GPL-3.0

<script src="https://liberapay.com/schrieveslaach/widgets/button.js"></script>

Donate using Liberapay

sonarlint.nvim

Extensions for the built-in Language Server Protocol support in Neovim (>= 0.8.0) for sonarlint-language-server (>= 2.16.0.65434).

Demo of sonarlint.nvim on sonarlint-language-server it self

Warning ⚠️

This repository is work in progress and the API is likely to change.

Install sonarlint-ls

Manual installation

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.

mason.nvim

If you are using mason.nvim you can simply do :MasonInstall sonarlint-language-server. See below for setup instructions when using this method.

Setup

⚠️ Make sure that you configure sonarlint.nvim after lspconfig.

local lspconfig = require('lspconfig')

-- do stuff with lspconfig

require('sonarlint').setup({
   --
})

For manual installation

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',
   }
})

For installation via mason.nvim

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',
   }
})