helix: Tailwind language server shows errors
Helix showing me this:
Async job failed: protocol error: Method not found: Unhandled method textDocument/completion
And there is my languages.toml
[[language]]
name = "tailwind"
scope = "source.svelte"
roots = [".npmrc"]
file-types = ["svelte"]
language-server = { command = "/home/yura/.local/share/nvim/lsp_servers/tailwindcss_npm/node_modules/@tailwindcss/language-server/bin/tailwindcss-language-server", args = ["--stdio"] }
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 71 (21 by maintainers)
I looked into this some, it appears that the tailwindcss language server expects the
configto be an object, and so crashes when a config is not provided, which means the language server never registers thetextDocument/completionhandler.Here are the specific lines
Tailwindcss never checks to make sure
initializationOptionsis in fact an object.My configuration file that does not produce that error looks like this
But even though the error went away (and the logs show the language server working), it’s still not giving completions. (The server keeps returning
nullfor the list of completions)I haven’t figured the issue out, but I thought I would write down what I’ve discovered so far.
Update: In a
.postcssfile after setting the language to tailwindcss, autocomplete works, it is just in svelte that it isn’t workingUpdate 2:
I solved it! Tailwindcss determines which type of file you are in based on the
language-idparameter, so a working configuration for svelte files (only) is below.You need to modify each language tailwindcss works with and overwrite it with tailwindcss and the correct
language-id. Unfortunately, this overwrites the existing language server for all those languages. Until #2507 is merged, there isn’t a way to add two language servers to the same language. Once that PR is merged a configuration file for tailwindcss (for Svelte, CSS, and HTML) would look like this (which is the config I am currently using after building the PR myself).TailwindLSP was working for me on node
v16. Onv18not so much. I tried to debug it(this branch) Helix doesn’t respond to these two requests:I tried to stop these two requests and insert default values(from other editors) and it works(Linux) for React, Vue and Svelte 😃
npm
npm i helix-twcss -gUntil helix client doesn’t respond to
workspace/configurationI will use this.In case anyone else lands here wondering why it still doesn’t work despite all the above, for me the trick was installing the
insidersversion of@tailwindcss/language-serverinstead of the default latest stable release. I see this was mentioned above but I wanted to highlight it and give a little more detail.Then (because the config for the language server is built in) all you have to do is add it to the list for your file type:
Before installing
insidersI was getting errors like thisFor anyone still following the latest version of tailwindcss-language-server was just released (with the fix needed to make this work properly, version 0.0.14). I’m making a package in nixpkgs for those using nixos https://github.com/NixOS/nixpkgs/pull/264899
Anyone do this with tsx files ?
helix-twcsshas been updated. Let’s hope this tailwindlabs/tailwindcss-intellisense#803 gets merged so we don’t need to maintain separate language server.Once https://github.com/tailwindlabs/tailwindcss-intellisense/pull/656 is released the config will be able to be empty without causing tailwind to crash, which fixes this bug.
@sukidhar Your language-id needs to be under the language definition, not the language-server definition.
Example:
The hyphen stuff is a helix problem that will be fixed with the event system
The fix has been merged in the tailwindcss intellisense: https://github.com/tailwindlabs/tailwindcss-intellisense/pull/803
I haven’t tested this extensively, but providing
language-id = "phoenix-heex"also provides tailwind autocomplete within the H sigils. Lexical doesn’t seem to mind and still provides autocomplete too.https://github.com/helix-editor/helix/commit/68fce3e160c64c488567f0e80f8d57bbbdd9dd82 was merged… I suggest updating your configs to avoid cruft and bloat. Keep it clean 😃
you can use the insiders build:
npm install @tailwindcss/language-server@insiders@swlkr maybe you want to move this into a discussion. I’m happy to help because I have working version for javascript/typescript with tailwind running with
npx. I do get null answers when I try to use it with elixir.any info for this? not working and even broke svelte syntax highlighting and completions
my languages.toml file:
Could you file an issue upstream ? There is a new developper on the project that is very responsive. If its a simple fix, it will likely be taken care of.
Can confirm v0.0.14 of @tailwindcss/language-server works (atleast for svelte files)! One issue I am noticing though is that the hyphens in Tailwind’s class names is causing the LSP suggestions to break.
Here is my working config:
Here are screenshots of that hyphen issue, also for some reason certain html elements don’t have syntax highlighting on the opening tag, oh well. Without hyphens:
Then with hyphens:

I can’t make this work with svelteserver, is either one or the other depending on which one is declared first in language-servers.
Edit:
Applied the changes in this commit manually since master is way ahead and recompiled, now it works fine.
To be sure, the fix was upstreamed on master. They mentioned they were about to do a release this week, but its still pending. Ive been in touch with upstream and i will add this to nixpkgs after the release for those interested.
I have made a pull request to get Tailwind into Helix officially, please could everyone involved in this thread hop over and have a look as you all have more experience than me! 😃
https://github.com/helix-editor/helix/pull/8442
seems like the other pr to fix tailwind with helix hasn’t been released yet: https://github.com/tailwindlabs/tailwindcss-intellisense/pull/803 try the insiders command recommended in this pr
i ended up implementing something similar to @uros-5 (before realizing it had been done before) in https://github.com/catdevnull/helix/tree/multiple-lsp-hover. thanks!
uros’ implementation is better for the jsx/svelte + tailwind use case because it just pushes the result of the first server that returns. but mine “tries” (but probably fails, didn’t test) to get hovers from all servers to merge them all together in the same hover window, which could be helpful for some weird use case where you want to see multiple hovers from multiple servers.
There seems to be some bugs in Tailwind’s language server, more info here: https://github.com/tailwindlabs/tailwindcss-intellisense/issues/802
So far, I don’t think Helix’s lsp implementation is to blame.
as mentioned above, it still does not show any hover. sorry I missed that. this is my languages.toml configuration do you see anything that might be wrong?
Please read previous comments… It’s not that hard.
Don’t have much time right now…
language-idis a language specific element (a language-server can support multiple different languages). So this should be under the relevantlanguagesvelte, but by default iflanguage-idunder thelanguageisn’t defined, thenameattribute is used instead.What may give some insight is running helix with the verbose flag (
-v) and checking the logs (in linux~/.cache/helix/helix.log).For tsx the
language-idthat is used by default istypescriptreactwhich follows the recommendation in https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentItemCurrent problem is that with #2507, hover doesn’t work if tailwindcss is not first language added to
language-servers…When Svelte or Vue are second in that array then their features are not working.
I tried to change that, and it works 😃
My temp fork.