init.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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("ls.keybindings").setup()
  7. end
  8. -- My font didn't like this :/
  9. -- vim.api.nvim_set_keymap(
  10. -- "n",
  11. -- "gl",
  12. -- '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics({ show_header = false, border = { { "🭽", "FloatBorder" }, { "▔", "FloatBorder" }, { "🭾", "FloatBorder" }, { "▕", "FloatBorder" }, { "🭿", "FloatBorder" }, { "▁", "FloatBorder" }, { "🭼", "FloatBorder" }, { "▏", "FloatBorder" }, } })<CR>',
  13. -- { noremap = true, silent = true }
  14. -- )
  15. local function no_formatter_on_attach(client, bufnr)
  16. if lvim.lsp.on_attach_callback then
  17. lvim.lsp.on_attach_callback(client, bufnr)
  18. end
  19. require("lsp.utils").lsp_highlight_document(client)
  20. client.resolved_capabilities.document_formatting = false
  21. end
  22. function lsp_config.common_capabilities()
  23. local capabilities = vim.lsp.protocol.make_client_capabilities()
  24. capabilities.textDocument.completion.completionItem.snippetSupport = true
  25. capabilities.textDocument.completion.completionItem.resolveSupport = {
  26. properties = {
  27. "documentation",
  28. "detail",
  29. "additionalTextEdits",
  30. },
  31. }
  32. return capabilities
  33. end
  34. require("core.autocmds").define_augroups {
  35. _general_lsp = {
  36. { "FileType", "lspinfo", "nnoremap <silent> <buffer> q :q<CR>" },
  37. },
  38. }
  39. local function is_table(t)
  40. return type(t) == "table"
  41. end
  42. local function is_string(t)
  43. return type(t) == "string"
  44. end
  45. local function has_value(tab, val)
  46. for _, value in ipairs(tab) do
  47. if value == val then
  48. return true
  49. end
  50. end
  51. return false
  52. end
  53. function lsp_config.setup(lang)
  54. local lang_server = lvim.lang[lang].lsp
  55. local provider = lang_server.provider
  56. if require("utils").check_lsp_client_active(provider) then
  57. return
  58. end
  59. local overrides = lvim.lsp.override
  60. if is_table(overrides) then
  61. if has_value(overrides, lang) then
  62. return
  63. end
  64. end
  65. if is_string(overrides) then
  66. if overrides == lang then
  67. return
  68. end
  69. end
  70. local sources = require("lsp.null-ls").setup(lang)
  71. for _, source in pairs(sources) do
  72. local method = source.method
  73. local format_method = "NULL_LS_FORMATTING"
  74. if is_table(method) then
  75. if has_value(method, format_method) then
  76. lang_server.setup.on_attach = no_formatter_on_attach
  77. end
  78. end
  79. if is_string(method) then
  80. if method == format_method then
  81. lang_server.setup.on_attach = no_formatter_on_attach
  82. end
  83. end
  84. end
  85. if provider == "" or provider == nil then
  86. return
  87. end
  88. require("lspconfig")[provider].setup(lang_server.setup)
  89. end
  90. return lsp_config