init.lua 1.5 KB

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