How can I setup auto-formatting on save with Helix? #2263
-
I am on Helix version 23.10, and I have installed the CLI via As per these instructions, I have copied these lines into my [language-server]
biome = { command = "biome", args = ["lsp-proxy"] }
[[language]]
name = "jsx"
language-servers = [ { name = "typescript-language-server", except-features = [ "format" ] }, "biome" ]
auto-format = true
[[language]]
name = "js"
language-servers = [ { name = "typescript-language-server", except-features = [ "format" ] }, "biome" ]
auto-format = true Linting appears to be working correctly, but there isn't any formatting on save. I can run the command
Am I doing something horribly wrong here? This is my first time using this, and I'm not well versed in configuring languages for Helix. Any pointers would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Adding the following line solved this: formatter = { command = "biome", args = ["format", "--stdin-file-path", "test.js"] } |
Beta Was this translation helpful? Give feedback.
-
Not clear why a file name is needed, but yes, I also got it working thanks to this explanation. The docs should definitely be updated. I found this thread through an old post on the discord. the relevant lines in my config: [language-server]
biome = { command = "biome", args = ["lsp-proxy"] }
[[language]]
name = "typescript"
auto-format = true
language-servers = [
{ name = "typescript-language-server", except-features = [
"format",
] },
"biome",
]
formatter = { command = "biome", args = [
"format",
"--stdin-file-path=prd.js", # no idea why a file name is needed
"--indent-style=space",
"--indent-width=4",
] } |
Beta Was this translation helpful? Give feedback.
-
It's needed because Biome needs to know what language you're passing, which is something isn't possible to infer from content only. Biome will use the file name extension to infer the file type, and apply the correct formatting. This becomes even more crucial with a formatter that supports multiple languages This is what Prettier does too. |
Beta Was this translation helpful? Give feedback.
Adding the following line solved this: