init.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. local M = {}
  2. local u = require "utils"
  3. function M.config()
  4. vim.lsp.protocol.CompletionItemKind = lvim.lsp.completion.item_kind
  5. for _, sign in ipairs(lvim.lsp.diagnostics.signs.values) do
  6. vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name })
  7. end
  8. require("lsp.handlers").setup()
  9. end
  10. local function lsp_highlight_document(client)
  11. if lvim.lsp.document_highlight == false then
  12. return -- we don't need further
  13. end
  14. -- Set autocommands conditional on server_capabilities
  15. if client.resolved_capabilities.document_highlight then
  16. vim.api.nvim_exec(
  17. [[
  18. hi LspReferenceRead cterm=bold ctermbg=red guibg=#464646
  19. hi LspReferenceText cterm=bold ctermbg=red guibg=#464646
  20. hi LspReferenceWrite cterm=bold ctermbg=red guibg=#464646
  21. augroup lsp_document_highlight
  22. autocmd! * <buffer>
  23. autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
  24. autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
  25. augroup END
  26. ]],
  27. false
  28. )
  29. end
  30. end
  31. function M.common_capabilities()
  32. local capabilities = vim.lsp.protocol.make_client_capabilities()
  33. capabilities.textDocument.completion.completionItem.snippetSupport = true
  34. capabilities.textDocument.completion.completionItem.resolveSupport = {
  35. properties = {
  36. "documentation",
  37. "detail",
  38. "additionalTextEdits",
  39. },
  40. }
  41. return capabilities
  42. end
  43. function M.common_on_init(client, bufnr)
  44. if lvim.lsp.on_init_callback then
  45. lvim.lsp.on_init_callback(client, bufnr)
  46. return
  47. end
  48. local formatters = lvim.lang[vim.bo.filetype].formatters
  49. if not vim.tbl_isempty(formatters) then
  50. client.resolved_capabilities.document_formatting = false
  51. u.lvim_log(string.format("Overriding [%s] formatter with [%s]", client.name, formatters[1].exe))
  52. end
  53. end
  54. function M.common_on_attach(client, bufnr)
  55. if lvim.lsp.on_attach_callback then
  56. lvim.lsp.on_attach_callback(client, bufnr)
  57. end
  58. lsp_highlight_document(client)
  59. require("lsp.null-ls").setup(vim.bo.filetype)
  60. end
  61. function M.setup(lang)
  62. local lsp = lvim.lang[lang].lsp
  63. if require("utils").check_lsp_client_active(lsp.provider) then
  64. return
  65. end
  66. local overrides = lvim.lsp.override
  67. if type(overrides) == "table" then
  68. if u.has_value(overrides, lang) then
  69. return
  70. end
  71. end
  72. local lspconfig = require "lspconfig"
  73. lspconfig[lsp.provider].setup(lsp.setup)
  74. end
  75. return M