linters.lua 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. local M = {}
  2. local Log = require "lvim.core.log"
  3. local null_ls = require "null-ls"
  4. local services = require "lvim.lsp.null-ls.services"
  5. local method = null_ls.methods.DIAGNOSTICS
  6. local alternative_methods = {
  7. null_ls.methods.DIAGNOSTICS,
  8. null_ls.methods.DIAGNOSTICS_ON_OPEN,
  9. null_ls.methods.DIAGNOSTICS_ON_SAVE,
  10. }
  11. function M.list_registered(filetype)
  12. local registered_providers = services.list_registered_providers_names(filetype)
  13. local providers_for_methods = vim.tbl_flatten(vim.tbl_map(function(m)
  14. return registered_providers[m] or {}
  15. end, alternative_methods))
  16. return providers_for_methods
  17. end
  18. function M.list_supported(filetype)
  19. local s = require "null-ls.sources"
  20. local supported_linters = s.get_supported(filetype, "diagnostics")
  21. table.sort(supported_linters)
  22. return supported_linters
  23. end
  24. function M.setup(linter_configs)
  25. if vim.tbl_isempty(linter_configs) then
  26. return
  27. end
  28. local registered = services.register_sources(linter_configs, method)
  29. if #registered > 0 then
  30. Log:debug("Registered the following linters: " .. unpack(registered))
  31. end
  32. end
  33. return M