-
-
Notifications
You must be signed in to change notification settings - Fork 288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vscode: Integrations w/ Prettier, Emmet, etc. #230
Comments
That's interesting! My goal was to have a standard format, just like Go has a standard format with If that can be achieved with a prettier configuration, I'd definitely consider ditching the way that A few people have made changes to templ in main (will come out in the next release) to formatting, including formatting the Go code bits using I note that prettier is written in JavaScript which I think would require Node.js to be installed, so so I might prefer a Go, Rust, or C etc. tool for the task, which may also be faster. I guess it would also have to recreate the rules of Is the VS Code extension not working for you? I'm wondering what you're missing. I use Neovim day to day, so I might simply not know what your expectations are of how the intellisense would work. Some examples, with screenshots or gifs could be useful. |
Just stumbled upon this aswell while trying to use the tailwindcss lsp inside a .templ file in Neovim. Unfortunately just adding the file type ".templ" to the lsp config of tailwindcss doesn't help. I am not sure yet if this needs to be addressed in the tailwindcss lsp server itself. |
FWIW i think the built in formatter is definitely good enough (and getting better each release) and much faster than prettier. And has no external dependencies. But getting Emmet working, and getting tailwind intellisense working would be great. Now there's a lot of typing that could be automated. For emmet, i don't think it's part of the LSP, just to configure vscode to activate emmet for the html parts of.templ files. For tailwind, well it wants to know what class names have been used, for minification of the generated css. So it might need some connection to the data structures in templ. |
Following up with some more findings after my initial post after reading some of the comments. Format on SaveI was able to get formatting on save to work in VSCode by adding the following to the settings.json. This makes it so the current VSCode extension can be used to format the code pretty easily. {
"editor.formatOnSave": true,
"[templ]": {
"editor.defaultFormatter": "a-h.templ"
},
{ Prettier PluginAs for the Prettier plugin discussion; I mentioned that I'm using tailwind and with that, I enjoy using the tailwind-prettier plugin that auto-sorts the tailwind classes. This is the main reason for wanting a Tailwind IntelliSenseFor tailwind, after some more experimenting, I was able to get the official TailwindCSS VSCode extension configured to add IntelliSense within {
"tailwindCSS.includeLanguages": {
"templ": "html"
}
} Emmet AbbreviationsI did find that the Emmet abbreviations do seem to work when configured in settings.json as an included language as follows: {
"emmet.includeLanguages": {
"templ": "html"
},
} HTML Shortcomings in LSPHowever, the above is for Emmet abbreviations specifically. This does not cover the IntelliSense for HTML (element names/attributes/auto-closing tags). It's possible to configure VSCode to associate |
Thank you @alehechka. With that information I could also fix the issue I had with tailwindcss in neovim. Just in case someone needs it following the config you need to set for lsp: require("lspconfig").tailwindcss.setup({
filetypes = {
'templ',
'html' -- include any other filetypes where you need tailwindcss
},
init_options = {
userLanguages = {
templ = "html"
}
}
}) Maybe some of these information could be included somewhere in the docs/guide? |
Why don't you create a Pull Request? |
I can surely create one, just questioned if it makes sense to include it |
I rely on the automatic class sorting in tailwind quite a bit. I would be interested in seeing how to make this work with templ. |
I found a cli tool call rustywind. And I pipe the formatted string into rustywind.
I add the hook to saving file in Emacs, and it kind of works like the prettier plugin. However, the rustywind order is slightly different than the prettier taliwind order. |
I have played around with vs code and prettier settings a bit try and get this to work with templ, no luck yet but would be willing to work on something |
Had a little think about it. Might be able to try make a PR after work |
I would die for this feature! Spent the last hour researching and fiddeling arround with vscode but sadly, I wasn't able to get class sorting to work :( I also would be willing to dedicate some time to this :) |
I've been getting by without the prettier-tailwind class sorting, but I do miss the sorted classes a lot. Additionally, the LSP seems to only support the Would love to have both of these features made available, but haven't had a ton of time available to dig in to help figure out a solution. Is there any recommended path to take in implementing either of the above mentioned features? I wonder if there's a way to tap into the HTML LSP to cover those parts of |
@alehechka You can try the Tailwind Raw Reorder extension for class sorting. |
@irsyadpage, gave this a quick try and this is a sweet find! Gonna have to play with it a bit more though. I've been manually adding newlines in my I've also been experimenting with templ's class expressions to provide an array of strings which can be formatted across multiple lines and including conditional logic, but the built-in regex doesn't seem to trigger on that syntax. It's really sweet that the extension gives so much flexibility with the regex matching, so I'll give it a swing to see if I can get something working for class expressions. |
Going to close this as most of my concerns have been addressed and the only remaining one seems to have a good conversation over in #498. |
I added these lines for better experimenc: "auto-close-tag.activationOnLanguage": [
"xml",
"php",
"blade",
"ejs",
"jinja",
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"plaintext",
"markdown",
"vue",
"liquid",
"erb",
"lang-cfml",
"cfml",
"templ",
"HTML (Eex)"
],
"auto-rename-tag.activationOnLanguage": [
"html",
"xml",
"php",
"javascript",
"templ"
],
|
Overview
I just recently found this project and really like the concept of being able to create and define components in a manner that generates Go code and can be packaged as a single binary.
I have one project that uses the default Go templating structure with heavy usage of tailwind for styling and htmx for interactivity. The problem I'm running into and would like to propose as a new feature of the templ ecosystem is plugin support for things such as Prettier/Tailwind/Emmet.
The
.templ
file extension is not supported by these tools and I have not been able to find a way to finagle them to work as I would like. For formatting, thetempl
CLI already has a formatter included, so I wonder if it would be possible to build a Prettier plugin with it and have prettier handle formatting the.templ
files. This would also make it so other prettier settings/plugins can be used in tandem.For tailwind and emmet, the
.templ
file extension isn't supported natively and from what I can tell, VS Code has a hard time attributing an unknown language to use these tools. With the default Go templates I'm able to build them within html files and thus get the support needed natively. It would be amazing if these tools could also work within.templ
so we can continue to write our templates "blazingly fast" with IntelliSense.If this is something the project maintainers are interested in but won't have enough bandwidth to work on, let me know and I can help contribute.
The text was updated successfully, but these errors were encountered: