lsp.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. local M = {
  2. "neovim/nvim-lspconfig",
  3. dependencies = {
  4. {
  5. "folke/lazydev.nvim",
  6. ft = "lua",
  7. opts = {
  8. library = {
  9. { path = "${3rd}/luv/library", words = { "vim%.uv" } },
  10. },
  11. },
  12. },
  13. {
  14. "j-hui/fidget.nvim",
  15. opts = {},
  16. },
  17. {
  18. "ray-x/go.nvim",
  19. ft = "go",
  20. config = function(_, opts)
  21. require("go").setup(opts)
  22. vim.keymap.set("n", "<leader>gmt", ":GoModTidy<cr>", {
  23. desc = "[Go] Tidy",
  24. })
  25. end,
  26. build = function()
  27. vim.cmd([[silent! GoModTidy]])
  28. end,
  29. },
  30. },
  31. }
  32. function M.config()
  33. local lspconfig = require("lspconfig")
  34. vim.lsp.enable({ "tsgo" })
  35. local servers = {
  36. "gopls",
  37. "jsonls",
  38. "clangd",
  39. "lua_ls",
  40. "yamlls",
  41. "graphql",
  42. "html",
  43. "cssls",
  44. "omnisharp",
  45. "svelte",
  46. "templ",
  47. "tinymist",
  48. "jdtls",
  49. "nixd",
  50. "qmlls",
  51. "zls",
  52. }
  53. for _, server in ipairs(servers) do
  54. lspconfig[server].setup({})
  55. end
  56. vim.api.nvim_create_autocmd("LspAttach", {
  57. group = vim.api.nvim_create_augroup("lsp", { clear = true }),
  58. callback = function(ev)
  59. local opts = { buffer = ev.buf, silent = true }
  60. local client = vim.lsp.get_client_by_id(ev.data.client_id)
  61. nmap("K", vim.lsp.buf.hover, vim.tbl_extend("force", opts, { desc = "Hover Doc" }))
  62. nmap("<C-h>", vim.lsp.buf.signature_help, vim.tbl_extend("force", opts, { desc = "Signature Help" }))
  63. nmap("<leader>r", vim.lsp.buf.rename, vim.tbl_extend("force", opts, { desc = "Rename" }))
  64. nmap("<leader>ca", vim.lsp.buf.code_action, vim.tbl_extend("force", opts, { desc = "Code Action" }))
  65. nmap("vd", vim.diagnostic.open_float, vim.tbl_extend("force", opts, { desc = "View Diagnostics" }))
  66. nmap("<leader>lr", "<cmd>LspRestart<CR>", vim.tbl_extend("force", opts, { desc = "Restart LSP" }))
  67. if client and client.server_capabilities.documentHighlightProvider then
  68. local hl_group = vim.api.nvim_create_augroup("lsp_document_highlight_" .. ev.buf, { clear = true })
  69. vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
  70. group = hl_group,
  71. buffer = ev.buf,
  72. callback = vim.lsp.buf.document_highlight,
  73. })
  74. vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
  75. group = hl_group,
  76. buffer = ev.buf,
  77. callback = vim.lsp.buf.clear_references,
  78. })
  79. end
  80. end,
  81. })
  82. end
  83. return M
  84. --