question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow formatting unreleased languages

See original GitHub issue

Is 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:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

2reactions
stephancasascommented, Jan 28, 2021

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:

"overrides": [
    {
        "files": "*.edge",
        "options": {
            "parser": "html"
        }
    }
]

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:

getSupportedFileExtensions(e){
    const t=[];
    return (this.getSupportLanguages(e).forEach((e=> {
        e&&e.extensions&&t.push(...e.extensions)
    })),t.filter(((e,t,r)=>r.indexOf(e)===t))).concat('.edge');
}

Sure, it’ll get over-written on an update, but it serves the purpose for now.

1reaction
dcyrillercommented, Jan 25, 2021

Another option is to add a configuration for allowing getSupportLanguage to also return unreleased languages

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

    return prettierInstance.getSupportInfo({ showUnreleased: true }).languages;

(getSupportInfo source)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't remove language and font formatting in document
In the Language>Set Language dialog, make sure that the checkbox for "Detect language automatically" is unchanged. It is. I even removed ...
Read more >
I want to use a language that's not on your list of ... - Final Draft
Go to Edit > Select All;; Go to Format > Font and choose the correct font;; Click OK. Your script will now be...
Read more >
Prettier 2.1: new --embedded-language-formatting option and ...
This release adds a new `--embedded-language-formatting` option, ... This option allows you to switch between the default behavior ( auto ) ...
Read more >
Time Zone, Date Format, and Language - DocuSign Support
By default, these settings apply to all users, existing and new, on the account. If you allow users to set their own time...
Read more >
Textual Input and Output - Wolfram Language Documentation
The Wolfram Language allows you to output expressions in many different ways. ... When the Wolfram Language generates output in a textual format...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found