I'm using Neovim with NvChad as a base config.
I've tried installing Tailwind CSS autocompletion with no luck. It sort of works:
The problem is it only shows class names that have been previously added, and that were there when you first opened the file. Which is obviously barely useful.
I've been debugging this for a long time and I'm not sure why it's doing this.
Here are my relevant configs:
~/.config/nvim/lua/custom/configs/lspconfig.lua
-- ...
lspconfig.tailwindcss.setup {
cmd = { "tailwindcss-language-server", "--stdio" },
filetypes = { "html", "css", "scss", "javascript", "javascriptreact", "typescript", "typescriptreact", "vue" },
root_dir = lspconfig.util.root_pattern("tailwind.config.js", "package.json"),
settings = {},
}
-- ...
~/.config/nvim/lua/plugins/configs/cmp.lua
-- ...
local options = {
-- ...
sources = {
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "nvim_lua" },
{ name = "path" },
{ name = "tailwindcss" },
},
}
-- ...
Here's a list of all my custom plugins. Other than that, they're the same as the default NvChad plugins: https://github.com/NvChad/NvChad/blob/v2.0/lua/plugins/init.lua
-- Custom plugins
{
"jose-elias-alvarez/null-ls.nvim",
config = function(_, opts)
local null_ls = require "null-ls"
local group = vim.api.nvim_create_augroup("lsp_format_on_save", { clear = false })
local event = "BufWritePre" -- or "BufWritePost"
local async = event == "BufWritePost"
null_ls.setup {
on_attach = function(client, bufnr)
if client.supports_method "textDocument/formatting" then
vim.keymap.set("n", "<Leader>f", function()
vim.lsp.buf.format { bufnr = vim.api.nvim_get_current_buf() }
end, { buffer = bufnr, desc = "[lsp] format" })
-- format on save
vim.api.nvim_clear_autocmds { buffer = bufnr, group = group }
vim.api.nvim_create_autocmd(event, {
buffer = bufnr,
group = group,
callback = function()
-- Fix ESLint errors:
vim.cmd "EslintFixAll"
-- Format with Prettier:
vim.lsp.buf.format { bufnr = bufnr, async = async }
end,
desc = "[lsp] format on save",
})
end
if client.supports_method "textDocument/rangeFormatting" then
vim.keymap.set("x", "<Leader>f", function()
vim.lsp.buf.format { bufnr = vim.api.nvim_get_current_buf() }
end, { buffer = bufnr, desc = "[lsp] format" })
end
end,
}
end,
},
{
"MunifTanjim/prettier.nvim",
lazy = false,
config = function()
local prettier = require "prettier"
prettier.setup {
bin = "prettierd",
cli_options = {
config_precedence = "prefer-file",
},
filetypes = {
"css",
"graphql",
"html",
"javascript",
"javascriptreact",
"json",
"less",
"markdown",
"scss",
"typescript",
"typescriptreact",
"yaml",
},
}
vim.cmd [[
augroup FormatAutogroup
autocmd!
autocmd BufWritePre *.js,*.jsx,*.json,*.md,*.html,*.css,*.scss,*.ts,*.tsx,*.yaml,*.yml,*.yaml,*.graphql :Prettier
augroup END
]]
end,
},
{
"github/copilot.vim",
lazy = false,
},
{
"rmagatti/auto-session",
lazy = false,
config = function()
require("auto-session").setup {
log_level = "error",
auto_session_suppress_dirs = { "~/", "~/Projects", "~/Downloads", "/" },
}
end,
}
-- Automatically close HTML and other tags:
{
"windwp/nvim-ts-autotag",
ft = {
"astro",
"glimmer",
"handlebars",
"html",
"javascript",
"javascriptreact",
"markdown",
"php",
"rescript",
"svelte",
"typescriptreact",
"typescript",
"vue",
"xml",
},
config = function()
require("nvim-ts-autotag").setup()
end,
},
If you need more details, you can see my full config on GitHub.
