Injecting TailwindCSS language server in Golang strings #12118
-
Per the title, I am trying to use the tailwind LS for auto-completions of classes inside of Go functions, specifically a function with the signature Here is what I have: Custom treesitter injection inside
Configuration inside [[language]]
name = "html"
scope = "text.html"
injection-regex = "html"
language-servers = ["tailwindcss"]
[language-server.tailwindcss]
command = "tailwindcss-language-server"
args = ["--stdio"]
root-pattern = ["tailwind.config.js", "package.json"]
file-types = ["html", "css", "javascript", "typescript"] And I get html highlighting, so I suspect I am along some right path, but not auto-completion for Tailwind, or hover documentation.
Any advice on if this is even the right way to go about this, or if it is how to fix it would be greatly appreciated :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I've tried now doing away with the treesitter injection, and just having the following in my languages.toml: [[language]]
name = "go"
scope = "source.go"
injection-regex = "go"
file-types = ["go"]
roots = ["go.work", "go.mod"]
auto-format = true
comment-token = "//"
block-comment-tokens = { start = "/*", end = "*/" }
language-servers = ["tailwindcss-ls", "gopls", "golangci-lint-lsp"]
# TODO: gopls needs utf-8 offsets?
indent = { tab-width = 4, unit = "\t" }
[language-server.tailwindcss-ls]
command = "tailwindcss-language-server"
args = ["--stdio"]
config = { userLanguages = { go = "html", "*.go" = "html" }, experimental = { classRegex = [
[
"Class(?:es)?[({]([^)}]*)[)}]",
"[\"`]([^\"`]*)[\"`]",
],
] } } And this does give me autocompletions on line 3 and 4 in the following screenshot but not line 2. Which makes me think that the experimental classRegex is not getting passed to the tailwind LS, as it's just finding classes like it normally does. I found this customization by following the instructions on this gomponents example repo. I'll continue messing around with getting these classRegexes to pass through. I will say though, I currently get the following logs on startup of the go file: And when in the file, and after running :lsp-restart I get these logs:
|
Beta Was this translation helpful? Give feedback.
-
I found how deep the rabbit hole goes... After digging way too deep, I figured out I was missing a prefix on the initialization options, so, the final solution is: [language-server.tailwindcss-ls]
command = "tailwindcss-language-server"
args = ["--stdio"]
config = { userLanguages = { go = "html", "*.go" = "html" }, tailwindCSS = { experimental = { classRegex = [
[
"Class(?:es)?[({]([^)}]*)[)}]",
"[\"`]([^\"`]*)[\"`]",
],
] } } } |
Beta Was this translation helpful? Give feedback.
I found how deep the rabbit hole goes...
After digging way too deep, I figured out I was missing a prefix on the initialization options, so, the final solution is: