diff options
| author | KhaNguyen <43724342+CaoKha@users.noreply.github.com> | 2026-03-31 23:20:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-31 17:20:42 -0400 |
| commit | 23bfb2a76b30d22b0768f97e26d4c39cc252483b (patch) | |
| tree | d607a5f79c8151cab9d9a2b8ef7bf229003b64fb /lsp/tailwindcss.lua | |
| parent | docs: update generated annotations (diff) | |
| download | nvim-lspconfig-23bfb2a76b30d22b0768f97e26d4c39cc252483b.tar nvim-lspconfig-23bfb2a76b30d22b0768f97e26d4c39cc252483b.tar.gz nvim-lspconfig-23bfb2a76b30d22b0768f97e26d4c39cc252483b.tar.bz2 nvim-lspconfig-23bfb2a76b30d22b0768f97e26d4c39cc252483b.tar.lz nvim-lspconfig-23bfb2a76b30d22b0768f97e26d4c39cc252483b.tar.xz nvim-lspconfig-23bfb2a76b30d22b0768f97e26d4c39cc252483b.tar.zst nvim-lspconfig-23bfb2a76b30d22b0768f97e26d4c39cc252483b.zip | |
fix(tailwindcss_ls): add experimental.configFile to support Tailwind v4 #4222
Diffstat (limited to 'lsp/tailwindcss.lua')
| -rw-r--r-- | lsp/tailwindcss.lua | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lsp/tailwindcss.lua b/lsp/tailwindcss.lua index 5c2d6423..67116286 100644 --- a/lsp/tailwindcss.lua +++ b/lsp/tailwindcss.lua @@ -6,6 +6,39 @@ --- npm install -g @tailwindcss/language-server local util = require 'lspconfig.util' +local function find_tailwind_global_css() + local target = "@import 'tailwindcss';" + + -- Find project root using `.git` + local buf = vim.api.nvim_get_current_buf() + local root = vim.fs.root(buf, function(name) + return name == '.git' + end) + + if not root then + return nil -- no project root found + end + + -- Find stylesheet files in the project root (recursively) + local files = vim.fs.find(function(name) + return name:match('%.css$') or name:match('%.scss$') or name:match('%.pcss$') + end, { + path = root, + type = 'file', + limit = math.huge, -- search full tree + }) + + for _, path in ipairs(files) do + local content = vim.fn.readblob(path) + + if content:find(target, 1, true) then + return path -- return first match + end + end + + return nil +end + ---@type vim.lsp.Config return { cmd = { 'tailwindcss-language-server', '--stdio' }, @@ -113,6 +146,10 @@ return { if not config.settings.editor.tabSize then config.settings.editor.tabSize = vim.lsp.util.get_effective_tabstop() end + config.settings.tailwindCSS = config.settings.tailwindCSS or {} + config.settings.tailwindCSS.experimental = config.settings.tailwindCSS.experimental or {} + config.settings.tailwindCSS.experimental.configFile = config.settings.tailwindCSS.experimental.configFile + or find_tailwind_global_css() end, workspace_required = true, root_dir = function(bufnr, on_dir) |
