lsp.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. on_attach = function(client, bufnr)
  56. local opts = { buffer = bufnr, silent = true }
  57. nmap("K", vim.lsp.buf.hover, vim.tbl_extend("force", opts, { desc = "Hover Doc" }))
  58. nmap("<C-h>", vim.lsp.buf.signature_help, vim.tbl_extend("force", opts, { desc = "Signature Help" }))
  59. nmap("<leader>r", vim.lsp.buf.rename, vim.tbl_extend("force", opts, { desc = "Rename" }))
  60. nmap("<leader>ca", vim.lsp.buf.code_action, vim.tbl_extend("force", opts, { desc = "Code Action" }))
  61. nmap("vd", vim.diagnostic.open_float, vim.tbl_extend("force", opts, { desc = "View Diagnostics" }))
  62. nmap("<leader>lr", "<cmd>LspRestart<CR>", vim.tbl_extend("force", opts, { desc = "Restart LSP" }))
  63. if client.server_capabilities.documentHighlightProvider then
  64. vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
  65. buffer = bufnr,
  66. callback = vim.lsp.buf.document_highlight,
  67. })
  68. vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
  69. buffer = bufnr,
  70. callback = vim.lsp.buf.clear_references,
  71. })
  72. end
  73. end,
  74. })
  75. end
  76. end
  77. return M
  78. --