Null-ls.nvim

It is recommended that you install null-ls to manage formatting & linting. Here's a possible install configuration for null-ls:

{
  "neovim/nvim-lspconfig",

   dependencies = {
     "jose-elias-alvarez/null-ls.nvim",
     config = function()
       require "custom.configs.null-ls"
     end,
   },
 
   config = function()
      require "plugins.configs.lspconfig"
      require "custom.configs.lspconfig"
   end,
}

  • Dependencies are loaded after the original plugin (lspconfig in NvChad's case).
  • null-ls is loaded after lspconfig as lspconfig is lazy-loaded.

Configuration

Make sure to check null-ls builtins to get exact names for formatters, linters etc.

Here's an example configuration for null-ls, following the NvChad file directory structure:

-- custom/configs/null-ls.lua

local null_ls = require "null-ls"

local formatting = null_ls.builtins.formatting
local lint = null_ls.builtins.diagnostics

local sources = {
   formatting.prettier,
   formatting.stylua,

   lint.shellcheck,
}

null_ls.setup {
   debug = true,
   sources = sources,
}

  • Check null-ls docs for adding format on save. Other things to take into account when configuring null-ls for NvChad:

  • This shortcut is defined for code formatting: <leader> + fm.

  • The linter, formatter or debugger that you will use in null-ls configuration, has to be downloaded via mason (that ensure_installed opt) or system wide.

  • Make sure the LSP servers for the filetypes are active for the relevant null-ls formatter and/or linter to work.