fix(lsp): only run attach handler for related clients

This commit is contained in:
2026-06-24 20:23:48 +02:00
parent 79859807f1
commit 5630af0e8e
7 changed files with 58 additions and 2 deletions
+5
View File
@@ -2,6 +2,11 @@ local util = require("util")
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if not client or client.name ~= "bashls" then
return
end
vim.keymap.set("n", "<leader>lf", function()
util.format({
buf = ev.buf,
+30
View File
@@ -1,5 +1,35 @@
local Linter = require("linter")
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if not client or client.name ~= "clangd" then
return
end
Linter.add(ev.buf, {
cmd = {
"clang-tidy",
"-p=build/debug",
"--quiet",
"%file%",
},
events = { "BufWritePost" },
clear_events = { "TextChanged", "TextChangedI" },
stdin = false,
stdout = true,
pattern = "^.+:(%d+):(%d+): (%w+): (.*) %[(.*)%]$",
groups = { "lnum", "col", "severity", "message", "code" },
source = "clang-tidy",
severity_map = {
error = vim.diagnostic.severity.ERROR,
warning = vim.diagnostic.severity.WARN,
note = vim.diagnostic.severity.HINT,
},
zero_idx_col = true,
zero_idx_lnum = true,
ignore_stderr = true,
})
vim.keymap.set(
"n",
"gs",
+6 -1
View File
@@ -1,6 +1,11 @@
local util = require("util")
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(ev)
local util = require("util")
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if not client or client.name ~= "emmylua_ls" then
return
end
vim.keymap.set("n", "<leader>lf", function()
util.format({
+5
View File
@@ -2,6 +2,11 @@ local util = require("util")
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if not client or client.name ~= "gopls" then
return
end
vim.keymap.set("n", "<leader>lf", function()
util.format({
buf = ev.buf,
+5
View File
@@ -3,6 +3,11 @@ local util = require("util")
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if not client or client.name ~= "intelephense" then
return
end
Linter.add(ev.buf, {
cmd = {
"phpcs",
+2 -1
View File
@@ -62,9 +62,10 @@ end
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if not client then
if not client or client.name ~= "jdtls" then
return
end
vim.keymap.set("n", "<leader>lf", function()
format(client, ev.buf)
end, { buffer = ev.buf })
+5
View File
@@ -2,6 +2,11 @@ local util = require("util")
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if not client or client.name ~= "ruff" then
return
end
vim.keymap.set("n", "<leader>lf", function()
vim.lsp.buf.format()
util.format({