-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update .config/nvim/lua/plugins/nvim-lspconfig.lua
- Loading branch information
1 parent
ec983d6
commit 786cdae
Showing
1 changed file
with
78 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,86 @@ | ||
return { | ||
"neovim/nvim-lspconfig", | ||
event = { "BufReadPre", "BufNewFile" }, | ||
dependencies = { | ||
"williamboman/mason.nvim", | ||
"williamboman/mason-lspconfig.nvim", | ||
}, | ||
config = function() | ||
local lspconfig = require("lspconfig") | ||
{ | ||
"williamboman/mason.nvim", | ||
config = function() | ||
require("mason").setup({}) | ||
end, | ||
cmd = { "Mason" }, | ||
}, | ||
{ | ||
"williamboman/mason-lspconfig.nvim", | ||
config = function() | ||
require("mason-lspconfig").setup({}) | ||
end, | ||
}, | ||
{ | ||
"neovim/nvim-lspconfig", | ||
event = { "BufReadPre", "BufNewFile" }, | ||
config = function() | ||
local lspconfig = require("lspconfig") | ||
require("mason-lspconfig").setup_handlers({ | ||
-- 1. デフォルトのハンドラー | ||
-- すべてのサーバーに対して共通の設定を適用 | ||
function(server_name) | ||
lspconfig[server_name].setup({}) | ||
end, | ||
|
||
if lspconfig.lua_ls then | ||
lspconfig.lua_ls.setup({ | ||
settings = { | ||
Lua = { | ||
diagnostics = { | ||
globals = { | ||
"vim", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
end | ||
-- 2. 特定のサーバーに対するカスタム設定 | ||
-- 例:rust_analyzer の場合、rust-tools を使用した設定 | ||
-- ["rust_analyzer"] = function() | ||
-- require("rust-tools").setup({}) | ||
-- end, | ||
["lua_ls"] = function() | ||
lspconfig.lua_ls.setup({ | ||
settings = { | ||
Lua = { | ||
diagnostics = { | ||
globals = { | ||
"vim", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
end, | ||
|
||
-- Python LSP. | ||
lspconfig.pylsp.setup({}) | ||
lspconfig.ruff.setup({}) | ||
-- ["terraformls"] = function() | ||
-- lspconfig.terraformls.setup({ | ||
-- on_attach = function(client, _) | ||
-- client.server_capabilities.semanticTokensProvider = nil | ||
-- end, | ||
-- }) | ||
-- end, | ||
|
||
if lspconfig.ts_ls then | ||
lspconfig.ts_ls.setup({}) | ||
end | ||
["typos_lsp"] = function() | ||
lspconfig.typos_lsp.setup({ | ||
init_options = { | ||
config = "~/.config/typos/.typos.toml", | ||
}, | ||
}) | ||
end, | ||
}) | ||
|
||
if lspconfig.ocamllsp then | ||
lspconfig.ocamllsp.setup({}) | ||
end | ||
-- Lsp Keymaps. | ||
-- global. | ||
-- vim.keymap.set("n", "<space>e", vim.diagnostic.open_float) | ||
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev) | ||
vim.keymap.set("n", "]d", vim.diagnostic.goto_next) | ||
vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist) | ||
|
||
if lspconfig.gopls then | ||
lspconfig.gopls.setup({}) | ||
end | ||
-- after the language server attaches to the current buffer | ||
vim.api.nvim_create_autocmd("LspAttach", { | ||
group = vim.api.nvim_create_augroup("UserLspConfig", {}), | ||
callback = function(ev) | ||
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc" | ||
|
||
if lspconfig.terraformls then | ||
lspconfig.terraformls.setup({ | ||
on_attach = function(client, _) | ||
client.server_capabilities.semanticTokensProvider = nil | ||
end, | ||
}) | ||
end | ||
|
||
if lspconfig.typos_lsp then | ||
lspconfig.typos_lsp.setup({ | ||
init_options = { | ||
config = "~/.config/typos/.typos.toml", | ||
}, | ||
}) | ||
end | ||
|
||
if lspconfig.nil_ls then | ||
lspconfig.nil_ls.setup({}) | ||
end | ||
|
||
-- Lsp Keymaps. | ||
-- global. | ||
-- vim.keymap.set("n", "<space>e", vim.diagnostic.open_float) | ||
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev) | ||
vim.keymap.set("n", "]d", vim.diagnostic.goto_next) | ||
vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist) | ||
|
||
-- after the language server attaches to the current buffer | ||
vim.api.nvim_create_autocmd("LspAttach", { | ||
group = vim.api.nvim_create_augroup("UserLspConfig", {}), | ||
callback = function(ev) | ||
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc" | ||
|
||
local opts = { buffer = ev.buf } | ||
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) | ||
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) | ||
vim.keymap.set("n", "<space>k", vim.lsp.buf.hover, opts) | ||
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, opts) | ||
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) | ||
end, | ||
}) | ||
end, | ||
local opts = { buffer = ev.buf } | ||
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) | ||
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) | ||
vim.keymap.set("n", "<space>k", vim.lsp.buf.hover, opts) | ||
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, opts) | ||
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) | ||
end, | ||
}) | ||
end, | ||
}, | ||
} |