Files
LazyVim-mirror/lua/lazyvim/plugins/extras/lang/tailwind.lua
Torbjørn Vatn d2f9885d6b fix(tailwind): additional settings (#5266)
Make it possible to define your own tailwind settings in opts, and merge
them with the default, additional Phoenix settings in tailwind.lua

## Description

Add the possibility to add your own tailwind settings in opts and have
them deep merged into the default `opts.settings`

I needed this for configuring support for tailwind when coding on a
[htmgo](https://htmgo.dev/docs/misc/tailwind-intellisense) project in
Neovim.

E.g.
```lua
return {
  "neovim/nvim-lspconfig",
  opts = {
    servers = {
      tailwindcss = {
        filetypes_include = { "go" },
        settings = {
          tailwindCSS = {
            includeLanguages = {
              go = "html",
            },
            experimental = {
              classRegex = {
                { "Class\\(([^)]*)\\)", '["`]([^"`]*)["`]' },
                { "ClassX\\(([^)]*)\\)", '["`]([^"`]*)["`]' },
                { "ClassIf\\(([^)]*)\\)", '["`]([^"`]*)["`]' },
                { "Classes\\(([^)]*)\\)", '["`]([^"`]*)["`]' },
              },
            },
          },
        },
      },
    },
  },
}
```

## Checklist

- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
2025-10-20 11:07:12 +02:00

78 lines
2.2 KiB
Lua

return {
recommended = function()
return LazyVim.extras.wants({
root = {
"tailwind.config.js",
"tailwind.config.cjs",
"tailwind.config.mjs",
"tailwind.config.ts",
"postcss.config.js",
"postcss.config.cjs",
"postcss.config.mjs",
"postcss.config.ts",
},
})
end,
{
"neovim/nvim-lspconfig",
opts = {
servers = {
tailwindcss = {
-- exclude a filetype from the default_config
filetypes_exclude = { "markdown" },
-- add additional filetypes to the default_config
filetypes_include = {},
-- to fully override the default_config, change the below
-- filetypes = {}
-- additional settings for the server, e.g:
-- tailwindCSS = { includeLanguages = { someLang = "html" } }
-- can be addeded to the settings table and will be merged with
-- this defaults for Phoenix projects
settings = {
tailwindCSS = {
includeLanguages = {
elixir = "html-eex",
eelixir = "html-eex",
heex = "html-eex",
},
},
},
},
},
setup = {
tailwindcss = function(_, opts)
opts.filetypes = opts.filetypes or {}
-- Add default filetypes
vim.list_extend(opts.filetypes, vim.lsp.config.tailwindcss.filetypes)
-- Remove excluded filetypes
--- @param ft string
opts.filetypes = vim.tbl_filter(function(ft)
return not vim.tbl_contains(opts.filetypes_exclude or {}, ft)
end, opts.filetypes)
-- Add additional filetypes
vim.list_extend(opts.filetypes, opts.filetypes_include or {})
end,
},
},
},
{
"hrsh7th/nvim-cmp",
optional = true,
dependencies = {
{ "roobert/tailwindcss-colorizer-cmp.nvim", opts = {} },
},
opts = function(_, opts)
-- original LazyVim kind icon formatter
local format_kinds = opts.formatting.format
opts.formatting.format = function(entry, item)
format_kinds(entry, item) -- add icons
return require("tailwindcss-colorizer-cmp").formatter(entry, item)
end
end,
},
}