samuelcolvin / jinjahtml-vscode

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

Override language for file ending in .j2 #83

Open lonix1 opened 3 years ago

lonix1 commented 3 years ago

By default all files that end in .j2 are matched to jinja-html (unless they have a more specific extension, e.g. .sql.j2).

The extension often incorrectly identifies files because of this. Linux config files usually don't have extensions (but they are templates, so end with .j2), so this extension always assumes jinja-html.

How can I override this setting, to jinja-properties? The problem is many of file extensions end with .j2 so how do I specify just that one?

samuelcolvin commented 3 years ago

Not that I know of, but if you can find a way, I'd be happy to accept a PR.

You can always change the highlighting language using the dialog in the bottom right.

lonix1 commented 3 years ago

Yeah that's what I do - click that language button - but it's a real chore to do that every time.

The only solutions I can think of:

Nonetheless, thanks for making this cool extension, it's quite useful!

samuelcolvin commented 3 years ago

I'm not entirely clear what you're asking for here?

Do you want to change the .js extension to highlight as jinja-raw?

This would be a a breaking change, but I think it might be reasonable. I wonder if anyone else has an opinion either way?

I unfortunately don't have any skill at vscode extensions.

Me neither before I build this extension, luckily building extensions is quite well documented by Microsoft. Why don't you spend a bit of time researching settings for vscode extensions and see if you can fix this?

lonix1 commented 3 years ago

That is why I made the other issue, as its a feature request which is self contained.

What I meant is, not to make a breaking change, but to make the default configurable and keep it as it is today: that .j2 must open with jinja-html. So only those people who don't like that, can set it to something else, OR unset it ("") so it doesn't trigger the extension at all.

Smething like: "betterjinja.default": "jinja-html" or "betterjinja.j2": "jinja-html".

If this results in incorrect file detection (as it is for my case, with linux config files), then one can override this to "betterjinja.default": "jinja-properties" or even "betterjinja.default": "".

alextremblay commented 3 years ago

I also think that the best course of action would be a configuration option to specify the default jinja "language", that way I could set my personal default for *.j2 to jinja-raw, and @lonix1 could set it to jinja-properties, but i don't know how much work that would entail.

I'm only just starting to learn how to write / modify VSCode extensions, so i don't know if I'd be able to contribute to this

maciejmatczak commented 1 year ago

Currently the behavior I observe for any lang that is not supported, is that my association like:

  "files.associations": {
    ".lang.j2": "jinja"
  },

... looses a priority with Better Jinja, where I would like to hook up a Jira Raw.

Each time I open a file, same session, it opens with Jira HTML. I can close it and reopen after I changed mode - Better Jira knows better I should use Jira HTML :)