I’m trying to make tailwind work in phoenix files (heex, ex, etc).
No matter what config I have, the cmp doesn’t help me with tailwind intelisense in phoenix files.
It works in other envs (HTML, React, etc).
I suspect it has something to do with the fact the config file is under ./assets/tailwind.config.js.
config = {
tailwindcss = {
settings = {
tailwindCSS = {
-- docs imply it should be html, js or css, but you can also specify
-- another "known" language so `heex = "phoenix-heex"` or
-- `heex = "HTML (EEx)"` also works. I think they just all get
-- treated as "html" by tailwind (effecting if it looks for class="" for completion triggers)
-- but could not say for certain.
includeLanguages = {heex = "html"}
}
}
}
}
My assets/tailwind.config.js should be pretty normal, I point my content like so:
You can verify your settings are correctly merged with :=require'lspconfig'.tailwindcss.manager.config.settings (probably only after opening a file).
Considering tailwind lists HTML (EEx), HTML (Eex) and html-eex in its htmlLanguages list, I think it’s just matching any free form string that the LSP client sends as the file/language type, so possibly adding heex would be a good PR. I guess vs-code reports it as phoenix-heex? I assume all those types behave the same. (Or maybe I have configured my neovim to call it heex at some point, you can check your own configs name with :set ft? with a file open).
Note there are two npm packages, @tailwindcss/language-server and tailwindcss-language-server (defunct). @tailwindcss/language-server is what I got working.
Hm, I just noticed you have heex = "html-eex" in your config, so I am not sure why yours is not working beyond maybe its not getting merged correctly. Maybe check it with :=require'lspconfig'.tailwindcss.manager.config.settings.
I can 100% confirm that mine did not function until I added that line. I only installed the LSP and set it up for this thread.
Does it function if you create a regular test.html file as a sibling to a layout heex file? eg: is it functioning in the project, but not for the file type or not functioning for the project at all?
Does :LspLog show anything interesting?
Try disabling all other LSP clients in case they’re some how conflicting?
What version of Neovim? I am using 0.10.2 and nvim-cmp#3403e2e, nvim-lspconfig#0ef6459.
If you run tailwindcss-language-server in a project dir, do you see any output? Mine logs “setting up” & “listening” json messages. I have mine installed via npm install -g @tailwindcss/language-server, in a mise controlled install of node@22.9.0, I wonder what mason installs.
For reference this is my output, perhaps try removing the experimental class regex?
Could it be that it something with the fact that the config is under assets/tailwind.config.js?
From what I’ve seen online, it shouldn’t be a problem.
I’ve added a new HTML file like you proposed, doesn’t work there.
I’ve opened another terminal with an astro (framework) project, there everything works as expected.
Which kinda answers the rest of the questions you asked regarding collisions and versions.
just opening a file with the cwd in project/assets
adjusting the tailwind content to include ./lib/... in addition to the normal ../lib/... paths
None of it had any (positive) effect.
The project I am testing with has tailwind installed via npm, so there is a package.json with tailwindcss in it. I wonder if you’re using the stand alone tailwind binary?
I think the LSP server has some “fall back to standalone mode” in it (judging by some issues I saw), but it may not function correctly if the project config is using npm packages (postcss?) that it cant load? Or maybe vice versa?
Since we last discussed it, I haven’t touched my config.
Suddenly, now, I’ve opened another phoenix project I got and tailwind works in an html.heex file.
Sooo weiiird…
I’ll look into it and will write back once I have some more info.
Interesting yes, mine is a CJS format with modules.exports = {...}.
The LSP server is supposed to support all formats, but perhaps you need to name it tailwind.config.mjs for it to load it correctly. The default created by tailwind init is a CJS file, so maybe it defaults to assuming that style.
I tried converting my config to ESM style (export default {...}), with the name tailwind.config.js and it still functions…
I’m a Neovim newb, but it seems to be working ok in AstroNvim. I think a poster on this forum actually recommend it to someone. I had run through LazyNvim, Kickstart, and NVChad, but I hadn’t tried AstroNvim for whatever reason and it looks like I’ll stick with it for a while as it was fairly easy to get it running with elixir and phoenix, and I haven’t had any issues with updating so far either.
The configs are in the community repo in case it helps.