init.lua 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. require("core.autocmds").define_augroups {
  12. _general_lsp = {
  13. { "FileType", "lspinfo", "nnoremap <silent> <buffer> q :q<CR>" },
  14. },
  15. }
  16. end
  17. function M.setup(lang)
  18. local lang_server = lvim.lang[lang].lsp
  19. local provider = lang_server.provider
  20. if utils.check_lsp_client_active(provider) then
  21. return
  22. end
  23. local overrides = lvim.lsp.override
  24. if utils.is_table(overrides) then
  25. if utils.has_value(overrides, lang) then
  26. return
  27. end
  28. end
  29. if utils.is_string(overrides) then
  30. if overrides == lang then
  31. return
  32. end
  33. end
  34. local sources = null_ls.setup(lang)
  35. for _, source in pairs(sources) do
  36. local method = source.method
  37. local format_method = "NULL_LS_FORMATTING"
  38. if utils.is_table(method) then
  39. if utils.has_value(method, format_method) then
  40. lang_server.setup.on_attach = service.no_formatter_on_attach
  41. end
  42. end
  43. if utils.is_string(method) then
  44. if method == format_method then
  45. lang_server.setup.on_attach = service.no_formatter_on_attach
  46. end
  47. end
  48. end
  49. if provider == "" or provider == nil then
  50. return
  51. end
  52. lspconfig[provider].setup(lang_server.setup)
  53. end
  54. return M