Add on_attach Method to avoid vim notifications on non tailwindcss-lsp files
Overview
This pull request introduces a new on_attach(client, bufnr) method to the plugin. The primary goal of this update is to integrate Tailwind CSS LSP client, that our buf_attach method is only invoked when the Tailwind CSS LSP is attached to a buffer.
Motivation
Avoids tailwindcss-colors notifications on non tailwindcss-lsp buffers. I would frequently get the tailwindcss-colors: current buffer is not attached to tailwindcss lsp client notification on non tailwindcss-lsp filetypes. It got very distracting so I went ahead and updated it to work on my end.
I choose to make it a new method instead of updating the buf_attach method for 2 reasons.
Not to introduce breaking changes to the plugin for those who use it.
To allow people to configure it more easily with nvim-lsp and mason. Avoiding doing the client check in their config.
---This function attaches to a buffer, updating highlights on change
---It filters for tailwindcss lsp client
---@param client table A |vim.lsp.client| object
---@param bufnr number
function M.on_attach(client, bufnr)
if not client then
vim.notify_once "tailwindcss-colors: on_attach client tried to attach to a nil client"
return
end
if client.name == "tailwindcss" then
M.buf_attach(bufnr)
end
end
Add on_attach Method to avoid vim notifications on non tailwindcss-lsp files
Overview
This pull request introduces a new
on_attach(client, bufnr)
method to the plugin. The primary goal of this update is to integrate Tailwind CSS LSP client, that ourbuf_attach
method is only invoked when the Tailwind CSS LSP is attached to a buffer.Motivation
Avoids
tailwindcss-colors
notifications on nontailwindcss-lsp
buffers. I would frequently get thetailwindcss-colors: current buffer is not attached to tailwindcss lsp client
notification on nontailwindcss-lsp
filetypes. It got very distracting so I went ahead and updated it to work on my end.I choose to make it a new method instead of updating the
buf_attach
method for 2 reasons.I also updated the public facing methods to more closely follow Lua Documentation Guidlines