init.lua 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. local utils = require "utils"
  2. local service = require "lsp.service"
  3. local lspconfig = require "lspconfig"
  4. local null_ls = require "lsp.null-ls"
  5. local M = {}
  6. function M.config()
  7. require("lsp.kind").setup()
  8. require("lsp.handlers").setup()
  9. require("lsp.signs").setup()
  10. require("lsp.keybinds").setup()
  11. end
  12. function M.setup(lang)
  13. local lang_server = lvim.lang[lang].lsp
  14. local provider = lang_server.provider
  15. if utils.check_lsp_client_active(provider) then
  16. return
  17. end
  18. local overrides = lvim.lsp.override
  19. if utils.is_table(overrides) then
  20. if utils.has_value(overrides, lang) then
  21. return
  22. end
  23. end
  24. if utils.is_string(overrides) then
  25. if overrides == lang then
  26. return
  27. end
  28. end
  29. local sources = null_ls.setup(lang)
  30. for _, source in pairs(sources) do
  31. local method = source.method
  32. local format_method = "NULL_LS_FORMATTING"
  33. if utils.is_table(method) then
  34. if utils.has_value(method, format_method) then
  35. lang_server.setup.on_attach = service.no_formatter_on_attach
  36. end
  37. end
  38. if utils.is_string(method) then
  39. if method == format_method then
  40. lang_server.setup.on_attach = service.no_formatter_on_attach
  41. end
  42. end
  43. end
  44. if provider == "" or provider == nil then
  45. return
  46. end
  47. lspconfig[provider].setup(lang_server.setup)
  48. end
  49. return M