Allow formatting unreleased languages
See original GitHub issueIs your feature request related to a problem? Please describe.
The Handlebars language is currently unreleased in Prettier (https://github.com/prettier/prettier/blob/main/src/language-handlebars/index.js). Because of this Prettier-VSCode doesn’t currently format hbs
files.
The Ember.js community created this extension for using Prettier to format Handlebars: https://github.com/mfeckie/handlebars-formatter
This extension hardcodes the Prettier version it supports and doesn’t use the installed version in the project. Personally I wanted to use a different version of Prettier, so I forked the extension and released my own: https://github.com/ember-tooling/prettier-for-handlebars-vscode/
The issue with this is that this still hardcodes the version. Yesterday I played around with the notion of adding support to Pretter-VSCode for Handlebars and the outcome works, without too many changes.
You can see the changes I made here: https://github.com/prettier/prettier-vscode/compare/main...ember-tooling:main
Describe the solution you’d like
I would like Pretter-VSCode to add a new configuration which allows passing in a prettier.SupportLanguage
object that will be added to the supportedLanguages for the extension.
Describe alternatives you’ve considered
Another option is to add a configuration for allowing getSupportLanguage
to also return unreleased
languages. The issue with this is that from what I understand this would require a change to Prettier itself as the exported getSupportInfo
function from Prettier doesn’t accept arguments. https://github.com/prettier/prettier/blob/main/src/index.js#L62
Finally, if none of these are approved I can go ahead and release a new version of my extension Prettier For Handlebars VSCode with the new code from https://github.com/ember-tooling/prettier-vscode but this seems like a waste of maintaining effort and having support built into the official extension will allow much easier access to users.
Additional context Open to chat about this 😃 Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:5
Top GitHub Comments
On this same note, it would be nice to pass in an array of file extensions that Prettier should parse. For example, I’ve setup my local
prettier.json
to treat Adonis Edge templates as HTML because they are effectively standard markup with mustache syntax:However, despite including the extension in the
overrides
array, Prettier does not load support for those files.As usual, you can set a
files.associations
object in VSCode’s config, but then you lose the ability to make use of other extensions which are targeted for Edge templates.For now, I’ve just modified the method within the installed extension, in-place:
Sure, it’ll get over-written on an update, but it serves the purpose for now.
If you you’d like to add Handlebars to the list of the supported languages, I wonder if you could not change https://github.com/prettier/prettier-vscode/blob/d4505c8cb3aa51ad255c7e19db752bc2afc6bd23/src/LanguageResolver.ts#L72 to
(
getSupportInfo
source)