How can I keep the VSCode HTML-language-server formatting from breaking the frontmatter in a WebC-component?

118 Views Asked by At

I am working on an 11ty (eleventy) blog in the multimodal editor helix using WebC as a templating language. To get syntax-highlighting and autoformatting for different languages, helix requires a compatible language server to be installed and offers a curated list of compatible LSPs. For HTML, they recommend the VSCode HTML LSP. I am using that for WebC as well, since it is valid markup. I do get syntax highlighting and code-formatting (on save and on demand) now. However, the frontmatter of the WebC-component is formatted as well, such that the indentation is removed - breaking the pagination-key which has indented sub-keys that lose their indentation.

To illustrate, before formatting:

---
layout: "_layouts/document.webc"
title: home
pagination:
  data: collections.post
  size: 2
  alias: posts
  reverse: true
---

and after the broken variant:

---
layout: "_layouts/document.webc"
title: home
pagination:
data: collections.post
size: 2
alias: posts
reverse: true
---

I have looked into the helix-logs when opening my WebC-component with hx -v my-component.webcand then :log-open, and the back-and-forth of helix and the LSP are visible like so:

2023-10-17T14:18:04.923 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/formatting","params":{"options":{"insertSpaces":true,"tabSize":2},"textDocument":{"uri":"file:///<redacted>.webc"}},"id":1}
2023-10-17T14:18:04.966 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","id":1,"result":[{"range":{"start":{"line":0,"character":0},"end":{"line":28,"character":8}},"newText":"---\nlayout: \"_layouts/document.webc\"\ntitle: home\npagination:\ndata: collections.post\nsize: 2\nalias: posts\nreverse: true\n--- <redacted>]}

I assume there must be a possibility to configure the LSP such that it will (best case) ignore the frontmatter entirely, or maybe tell helix to ignore it when sending the string TO the LSP.

0

There are 0 best solutions below