init.lua 1.7 KB

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