samuelcolvin / jinjahtml-vscode

Syntax highlighting for jinja(2) html templates in vscode
https://marketplace.visualstudio.com/items?itemName=samuelcolvin.jinjahtml
MIT License
135 stars 55 forks source link

Not indenting #121

Closed JannieT closed 1 year ago

JannieT commented 1 year ago

This might be an installation / configuration issue, because the extension is not working for me at all. I installed the extension and changed this in my settings.json for the project:

  "files.associations": {
    "*.html": "jinja-html"
  }

After I restart VS Code and open a template file, I get a warning that:

Formatting: There are multiple formatters for ''Jinja HTML'' files. One of them should be configured as default formatter.

I have only vscode.html-language-features and esbenp.prettier-vscode to choose from. If I choose either of those and save my template file, the formatting the template tags does not get indented:

Screenshot 2022-10-04 at 11 50 51

I would have expected that line 26 and line 34 would be indented. Am I missing something?

stianpr commented 1 year ago

Same thing here, indents are wrong. I had to downgrade to previous version, 0.18.0.

samuelcolvin commented 1 year ago

This is most likely caused by #118, @devmattrick @nathan-barrett any ideas what's going on?

rmarscher commented 1 year ago

I believe that formatting was not working before the update to load vscode html language features. Now, it is triggering the html formatters which don't understand how to handle jinja templates. As far as I know, there isn't a way to configure prettier or the built-in formatter to handle the jinja template tags and there isn't another extension that handles it.

It is possible to disable auto formatting just for jinja-html files in your settings.json. That's how I am working around this change:

    "[jinja-html]": {
        "editor.formatOnSave": false
    }
samuelcolvin commented 1 year ago

great, thanks for the explanation.

devmattrick commented 1 year ago

Afaik there's kinda no way to make HTML Language Features understand how to indent Jinja templates, right? Maybe it would be possible to add a Jinja HTML formatter to the Better Jinja extension itself? That might be a lot of work, though.

Prettier support is kinda unrelated since Prettier doesn't seem to support Jinja out of the box, not something that this extension can fix short of writing a Prettier plugin.

JannieT commented 1 year ago

Looks like I misunderstood the role of this extension. I did not realise that it is focused on syntax highlighting. I was looking for a code formatter. Thanks for clarifying.

samuelcolvin commented 1 year ago

Happy to review a PR to add formatting if someone wants to have a crack at it.