setup.lua 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. local status, mason = pcall(require, "mason")
  2. if not status then
  3. vim.notify("没有找到 mason")
  4. return
  5. end
  6. local status_mason_lspconfig, mason_config = pcall(require, "mason-lspconfig")
  7. if not status_mason_lspconfig then
  8. vim.notify("没有找到 mason-lspconfig")
  9. return
  10. end
  11. local status_lspconfig, lspconfig = pcall(require, "lspconfig")
  12. if not status_lspconfig then
  13. vim.notify("没有找到 lspconfig")
  14. return
  15. end
  16. -- :h mason-default-settings
  17. -- ~/.local/share/nvim/mason
  18. mason.setup({
  19. ui = {
  20. icons = {
  21. package_installed = "✓",
  22. package_pending = "➜",
  23. package_uninstalled = "✗",
  24. },
  25. },
  26. })
  27. -- mason-lspconfig uses the `lspconfig` server names in the APIs it exposes - not `mason.nvim` package names
  28. -- https://github.com/williamboman/mason-lspconfig.nvim/blob/main/doc/server-mapping.md
  29. mason_config.setup({
  30. ensure_installed = {
  31. "lua_ls",
  32. "tsserver",
  33. "tailwindcss",
  34. "bashls",
  35. "cssls",
  36. "dockerls",
  37. "emmet_ls",
  38. "html",
  39. "jsonls",
  40. "pyright",
  41. "rust_analyzer",
  42. "taplo",
  43. "yamlls",
  44. "gopls",
  45. "clangd",
  46. "cmake",
  47. },
  48. })
  49. -- 安装列表
  50. -- { key: 服务器名, value: 配置文件 }
  51. -- key 必须为下列网址列出的 server name,不可以随便写
  52. -- https://github.com/williamboman/nvim-lsp-installer#available-lsps
  53. local servers = {
  54. lua_ls = require("lsp.config.lua"), -- lua/lsp/config/lua.lua
  55. bashls = require("lsp.config.bash"),
  56. pyright = require("lsp.config.pyright"),
  57. html = require("lsp.config.html"),
  58. cssls = require("lsp.config.css"),
  59. emmet_ls = require("lsp.config.emmet"),
  60. jsonls = require("lsp.config.json"),
  61. tsserver = require("lsp.config.typescript"),
  62. yamlls = require("lsp.config.yamlls"),
  63. dockerls = require("lsp.config.docker"),
  64. tailwindcss = require("lsp.config.tailwindcss"),
  65. -- rust_analyzer = require("lsp.config.rust"),
  66. taplo = require("lsp.config.taplo"), -- toml
  67. gopls = require("lsp.config.gopls"),
  68. remark_ls = require("lsp.config.markdown"),
  69. clangd = require("lsp.config.clangd"),
  70. cmake = require("lsp.config.cmake"),
  71. }
  72. for name, config in pairs(servers) do
  73. if config ~= nil and type(config) == "table" then
  74. -- 自定义初始化配置文件必须实现on_setup 方法
  75. config.on_setup(lspconfig[name])
  76. else
  77. -- 使用默认参数
  78. lspconfig[name].setup({})
  79. end
  80. end