diff --git a/dot_config/nvim/exact_lua/lsp/exact_config/lsp_servers.lua b/dot_config/nvim/exact_lua/lsp/exact_config/lsp_servers.lua new file mode 100644 index 0000000..bc63985 --- /dev/null +++ b/dot_config/nvim/exact_lua/lsp/exact_config/lsp_servers.lua @@ -0,0 +1,29 @@ +-- 統一管理要啟用的語言伺服器 +local M = {} + +-- 依主機功能篩選條件(可選) +local has_go = vim.fn.executable("go") == 1 + +-- 程式語言所需要的與語言伺服器名稱對照表 +-- +M.lsp_servers = { + -- "lua_ls", "rust_analyzer" -- 官方範例 + + "phpactor", -- PHP + has_go and "sqls" or nil, -- SQL + "pyright", -- Python + has_go and "gopls" or nil, -- Go + "html", -- HTML + "cssls", -- CSS + "volar", -- Vue3 + -- "ts_ls", -- TypeScript,目前暫時不需要,先註解掉 + "marksman", -- Markdown + "yamlls", -- YAML +} + +-- 過濾 nil 值 +M.lsp_servers = vim.tbl_filter(function(item) + return item ~= nil +end, M.lsp_servers) + +return M diff --git a/dot_config/nvim/exact_lua/lsp/exact_config/lspconfig.lua b/dot_config/nvim/exact_lua/lsp/exact_config/lspconfig.lua index ec7f3f3..5c04e33 100644 --- a/dot_config/nvim/exact_lua/lsp/exact_config/lspconfig.lua +++ b/dot_config/nvim/exact_lua/lsp/exact_config/lspconfig.lua @@ -1,3 +1,5 @@ +local servers = require("lsp.config.lsp_servers").lsp_servers + local lspconfig = require("lspconfig") local capabilities = require("cmp_nvim_lsp").default_capabilities() @@ -9,21 +11,6 @@ local on_attach = function(_, bufnr) map("n", "K", vim.lsp.buf.hover) end --- 程式語言所需要的與語言伺服器名稱對照表 --- -local servers = { - "phpactor", -- PHP - "sqls", -- SQL - "pyright", -- Python - "gopls", -- Go - "html", -- HTML - "cssls", -- CSS - "volar", -- Vue3 - -- "ts_ls", -- TypeScript,目前暫時不需要,先註解掉 - "marksman", -- Markdown - "yamlls", -- YAML -} - -- 載入所有的對應的 LSP server 設定 -- -- 相關設定請看 diff --git a/dot_config/nvim/exact_lua/lsp/exact_config/mason.lua b/dot_config/nvim/exact_lua/lsp/exact_config/mason.lua index b507995..d3085a6 100644 --- a/dot_config/nvim/exact_lua/lsp/exact_config/mason.lua +++ b/dot_config/nvim/exact_lua/lsp/exact_config/mason.lua @@ -1,21 +1,11 @@ +local lsp = require("lsp.config.lsp_servers") + require("mason").setup() require("mason-lspconfig").setup { -- A list of servers to automatically install if they're not already installed. Example: { "rust_analyzer@nightly", "lua_ls" } -- This setting has no relation with the `automatic_installation` setting. ---@type string[] - ensure_installed = { - -- "lua_ls", "rust_analyzer" -- 官方範例 - "phpactor", - "sqls", - "pyright", - "gopls", - "html", - "cssls", - "volar", - -- "ts_ls", - "marksman", - "yamlls", - }, + ensure_installed = lsp.lsp_servers, -- Whether servers that are set up (via lspconfig) should be automatically installed if they're not already installed. -- This setting has no relation with the `ensure_installed` setting.