init.lua 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. local lsp_config = {}
  2. function lsp_config.config()
  3. require("lsp.kind").setup()
  4. require("lsp.handlers").setup()
  5. require("lsp.signs").setup()
  6. require("lsp.keybinds").setup()
  7. end
  8. local function no_formatter_on_attach(client, bufnr)
  9. if lvim.lsp.on_attach_callback then
  10. lvim.lsp.on_attach_callback(client, bufnr)
  11. end
  12. require("lsp.utils").lsp_highlight_document(client)
  13. client.resolved_capabilities.document_formatting = false
  14. end
  15. function lsp_config.common_capabilities()
  16. local capabilities = vim.lsp.protocol.make_client_capabilities()
  17. capabilities.textDocument.completion.completionItem.snippetSupport = true
  18. capabilities.textDocument.completion.completionItem.resolveSupport = {
  19. properties = {
  20. "documentation",
  21. "detail",
  22. "additionalTextEdits",
  23. },
  24. }
  25. return capabilities
  26. end
  27. require("core.autocmds").define_augroups {
  28. _general_lsp = {
  29. { "FileType", "lspinfo", "nnoremap <silent> <buffer> q :q<CR>" },
  30. },
  31. }
  32. local function is_table(t)
  33. return type(t) == "table"
  34. end
  35. local function is_string(t)
  36. return type(t) == "string"
  37. end
  38. local function has_value(tab, val)
  39. for _, value in ipairs(tab) do
  40. if value == val then
  41. return true
  42. end
  43. end
  44. return false
  45. end
  46. function lsp_config.setup(lang)
  47. local lang_server = lvim.lang[lang].lsp
  48. local provider = lang_server.provider
  49. if require("utils").check_lsp_client_active(provider) then
  50. return
  51. end
  52. local overrides = lvim.lsp.override
  53. if is_table(overrides) then
  54. if has_value(overrides, lang) then
  55. return
  56. end
  57. end
  58. if is_string(overrides) then
  59. if overrides == lang then
  60. return
  61. end
  62. end
  63. local sources = require("lsp.null-ls").setup(lang)
  64. for _, source in pairs(sources) do
  65. local method = source.method
  66. local format_method = "NULL_LS_FORMATTING"
  67. if is_table(method) then
  68. if has_value(method, format_method) then
  69. lang_server.setup.on_attach = no_formatter_on_attach
  70. end
  71. end
  72. if is_string(method) then
  73. if method == format_method then
  74. lang_server.setup.on_attach = no_formatter_on_attach
  75. end
  76. end
  77. end
  78. if provider == "" or provider == nil then
  79. return
  80. end
  81. require("lspconfig")[provider].setup(lang_server.setup)
  82. end
  83. return lsp_config