malloryerik

malloryerik

How to use 'phoenix-heex' templates in VSCode

Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode.
The solution seems to be, in a hyphenated word, phoenix-heex.

phoenix-heex is the VSCode “language id” for .html.heex templates. If I understand correctly, Marlus Saraiva @msaraiva set it up, and it seems to solve… everything?

The new Phoenix Framework VSCode extension uses it.

So, just add phoenix-heex (and not, for example, HEEx) as a language for html and the vs-code-eex-formatter, Tailwind IntelliSense extension, HTML expansion/completion and other extensions all work today. :racehorse:

In your VSCode’s settings.json :

emmet HTML/CSS expansion & snippets

    "emmet.includeLanguages": {
        ...
        "phoenix-heex": "html"
    },

vs-code-eex-formatter

    "[phoenix-heex]": {
        "editor.defaultFormatter": "RoyalMist.vscode-eex-format"
    },

Tailwind class autocomplete (<- The maintainer told me how to find a language ID.)

    "tailwindCSS.includeLanguages": {
        "phoenix-heex": "html"
    },

… and likewise for the other extensions I use that allow language id input in setting.json; planting a “phoenix-heex” following the general pattern of other listed languages has seemed to work. :man_farmer:

I know quite little about this stuff, actually, so any help, advice and/or correction is welcome!

Most Liked

mikeclark

mikeclark

Here’s my setup which seems to be working nicely.

Suggested tweaks welcome!

Sebb

Sebb

Thanks for the guide.
I do not quite understand how to find the language ID and how to connect plugins to them.
It’s working for those you posted but I’d like to use some more plugins.

Here is a list of the plugins and the state of affairs:

Extension HEEX ~H-sigil Comment
Alpine.js IntelliSense - -
Auto Close Tag - -
Auto Rename Tag + + works for components
Elixir Templates Formatter o - not for components
Phoenix Framework + +
Tailwind CSS IntelliSense + -

How can we put a + in each cell?

Extension Ver Author ID
Alpine.js IntelliSense v1.2.0 Adrian Wilczyński adrianwilczynski.alpine-js-intellisense
Auto Close Tag v0.5.13 Jun Han formulahendry.auto-close-tag
Auto Rename Tag v0.1.9 Jun Han formulahendry.auto-rename-tag
Elixir Templates Formatter v0.5.0 RoyalMist royalmist.vscode-eex-format
ElixirLS: Elixir support and debugger v0.9.0 ElixirLS jakebecker.elixir-ls
Phoenix Framework v0.1.1 phoenixframework phoenixframework.phoenix
Tailwind CSS IntelliSense v0.7.4 Tailwind Labs bradlc.vscode-tailwindcss
Ritvyk

Ritvyk

@malloryerik ncase you want the same ability with pure .HTML.heex files , take a look at this extension just came into marketplace.

It also takes alpine js x-* and phx and new <.component> syntax into consideration :smiley:

ryanjafari

ryanjafari

An update here:

I am on {:phoenix_live_view, "~> 0.17.10"} and the following works to format .heex (as well as .ex, .exs) using mix format:

# .formatter.exs
[
  plugins: [Phoenix.LiveView.HTMLFormatter],
  inputs: ["*.{heex,ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{heex,ex,exs}"],
  import_deps: [:ecto, :phoenix],
  subdirectories: ["priv/*/migrations"]
]

Appears that the work has been merged in.

I use Elixir Mix Formatter to trigger mix format on save in VSCode with editor.formatOnSave: true in settings.json. Also:

// settings.json
"[elixir]": {
  "editor.defaultFormatter": "animus-coop.vscode-elixir-mix-formatter",
},
"[phoenix-heex]": {
  "editor.defaultFormatter": "animus-coop.vscode-elixir-mix-formatter"
}

…to ensure the right formatter extension is used for these files.

Have fun!

alaadahmed

alaadahmed

Thanks a lot, you really saved me a lot of time searching and figuring out.

Where Next?

Popular in Guides/Tuts Top

tfwright
I thought I’d share a small project I’m working on to gain some familiarty with LiveView in a Phoenix app. Github Repo Deployment It’s...
New
Logan
Here is an example of a Mix application that utilizes Cowboy to handle websocket connections. If anyone has an idea about making this wor...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
WolfDan
So my main OS is Windows, I do must of my work with it, Elixir and vscode elixirls works just fine when you’re working only with elixir, ...
New
dkuku
I Created a blog post about setting up svelte with phoenix. I found it a bit tricky and the only blog post I found was written using som...
New
TwistingTwists
This is a thread to note down things/best practices encountered in LiveBeats App as I explore the source code. Found this usage of r...
New
wfgilman
I'm writing up this quick "How to" because what I thought was going to be an easy implementation of a Plug to validate a webhook request ...
New
lukertty
Install web-mode and mmm-mode first and put this in your config file: (require 'mmm-mode) (require 'web-mode) (setq mmm-global-mode 'may...
New
thetechnologyvault
One of our team members just published this getting started guide for Elixir/Phoenix devs to use the Nanobox platform: https://content.n...
New
slouchpie
Warmest greetings, comrades. I recently started using :dns_cluster (GitHub - phoenixframework/dns_cluster: Simple DNS clustering for dis...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

We're in Beta

About us Mission Statement