Skip to content

Commit

Permalink
Update .config/nvim/lua/plugins/none-ls.lua
Browse files Browse the repository at this point in the history
Update .config/nvim/lua/plugins/nvim-lspconfig.lua
  • Loading branch information
Hyuga-Tsukui committed Nov 29, 2024
1 parent b8a9bba commit 0d241ae
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
6 changes: 3 additions & 3 deletions dot_config/nvim/lua/plugins/none-ls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ return {
require("mason-null-ls").setup({
handlers = {
prettierd = function() end, -- prettierd の自動セットアップを無効化
biome = function() end, -- biome の自動セットアップを無効化
biome = function() end, -- biome の自動セットアップを無効化
},
})

Expand Down Expand Up @@ -49,9 +49,9 @@ return {
-- null-ls のセットアップ
null_ls.setup({
-- sources の結合
sources = vim.list_extend({
sources = {
null_ls.builtins.formatting.terraform_fmt, -- デフォルト
}, javascript_project()), -- JavaScript プロジェクト用のフォーマッター
}, -- JavaScript プロジェクト用のフォーマッター
on_attach = function(client, bufnr)
vim.keymap.set("n", "<space>f", function()
vim.lsp.buf.format({ async = true })
Expand Down
36 changes: 34 additions & 2 deletions dot_config/nvim/lua/plugins/nvim-lspconfig.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
local function my_format()
vim.lsp.buf.format({
timeout_ms = 2000,
filter = function(client)
return client.name ~= "tsserver"
end,
})
end
return {
{
"williamboman/mason.nvim",
Expand Down Expand Up @@ -69,6 +77,12 @@ return {
["biome"] = function()
lspconfig.biome.setup({
cmd = { "npx", "biome", "lsp-proxy" },
on_new_config = function(new_config, new_root_dir)
-- 環境変数で biome.json を指定
new_config.cmd_env = {
BIOME_CONFIG = new_root_dir .. "/biome.json",
}
end,
root_dir = function(fname)
local util = require("lspconfig.util")
-- biome.json を探すロジック
Expand All @@ -86,10 +100,10 @@ return {
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
local g = vim.api.nvim_create_augroup("UserLspConfig", {})
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
group = g,
callback = function(ev)
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"

Expand All @@ -99,6 +113,24 @@ return {
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)

local client = vim.lsp.get_client_by_id(ev.data.client_id)
if client == nil then
return
end

if client.supports_method("textDocument/formatting") then
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
group = g,
buffer = ev.bufnr,
callback = function()
my_format()
end,
})
vim.api.nvim_create_user_command("Format", function()
my_format()
end, {})
end
end,
})
end,
Expand Down

0 comments on commit 0d241ae

Please sign in to comment.