nvim: 調整 lsp_servers 結構將清單拉出來,並增加判斷是否有go執行環境
This commit is contained in:
parent
f451e0e0fa
commit
1d824b92c0
29
dot_config/nvim/exact_lua/lsp/exact_config/lsp_servers.lua
Normal file
29
dot_config/nvim/exact_lua/lsp/exact_config/lsp_servers.lua
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
-- 統一管理要啟用的語言伺服器
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
-- 依主機功能篩選條件(可選)
|
||||||
|
local has_go = vim.fn.executable("go") == 1
|
||||||
|
|
||||||
|
-- 程式語言所需要的與語言伺服器名稱對照表
|
||||||
|
-- <https://wiki.archlinux.org/title/Language_Server_Protocol>
|
||||||
|
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
|
@ -1,3 +1,5 @@
|
|||||||
|
local servers = require("lsp.config.lsp_servers").lsp_servers
|
||||||
|
|
||||||
local lspconfig = require("lspconfig")
|
local lspconfig = require("lspconfig")
|
||||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||||
|
|
||||||
@ -9,21 +11,6 @@ local on_attach = function(_, bufnr)
|
|||||||
map("n", "K", vim.lsp.buf.hover)
|
map("n", "K", vim.lsp.buf.hover)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 程式語言所需要的與語言伺服器名稱對照表
|
|
||||||
-- <https://wiki.archlinux.org/title/Language_Server_Protocol>
|
|
||||||
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 設定
|
-- 載入所有的對應的 LSP server 設定
|
||||||
--
|
--
|
||||||
-- 相關設定請看
|
-- 相關設定請看
|
||||||
|
@ -1,21 +1,11 @@
|
|||||||
|
local lsp = require("lsp.config.lsp_servers")
|
||||||
|
|
||||||
require("mason").setup()
|
require("mason").setup()
|
||||||
require("mason-lspconfig").setup {
|
require("mason-lspconfig").setup {
|
||||||
-- A list of servers to automatically install if they're not already installed. Example: { "rust_analyzer@nightly", "lua_ls" }
|
-- 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.
|
-- This setting has no relation with the `automatic_installation` setting.
|
||||||
---@type string[]
|
---@type string[]
|
||||||
ensure_installed = {
|
ensure_installed = lsp.lsp_servers,
|
||||||
-- "lua_ls", "rust_analyzer" -- 官方範例
|
|
||||||
"phpactor",
|
|
||||||
"sqls",
|
|
||||||
"pyright",
|
|
||||||
"gopls",
|
|
||||||
"html",
|
|
||||||
"cssls",
|
|
||||||
"volar",
|
|
||||||
-- "ts_ls",
|
|
||||||
"marksman",
|
|
||||||
"yamlls",
|
|
||||||
},
|
|
||||||
|
|
||||||
-- Whether servers that are set up (via lspconfig) should be automatically installed if they're not already installed.
|
-- 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.
|
-- This setting has no relation with the `ensure_installed` setting.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user