Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow formatting unreleased languages #1747

Closed
Alonski opened this issue Jan 24, 2021 · 5 comments
Closed

Allow formatting unreleased languages #1747

Alonski opened this issue Jan 24, 2021 · 5 comments
Labels
locked Please open a new issue and fill out the template instead of commenting.

Comments

@Alonski
Copy link

Alonski commented Jan 24, 2021

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: 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!

@dcyriller
Copy link

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

return prettierInstance.getSupportInfo().languages;

to

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

(getSupportInfo source)

@Alonski
Copy link
Author

Alonski commented Jan 25, 2021

@dcyriller That is what I wrote in alternatives :)
The exported function doesn't accept arguments:
https://github.com/prettier/prettier/blob/4d58724016186d0a3eff235db5459d1e966b1d3f/src/index.js#L62

@stephancasas
Copy link

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.

@Alonski
Copy link
Author

Alonski commented Feb 8, 2021

Closing this. It is possible to do this today :)
https://dev.to/jelhan/format-glimmer-templates-with-prettier-ipa

@Alonski Alonski closed this as completed Feb 8, 2021
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot added the locked Please open a new issue and fill out the template instead of commenting. label May 10, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

No branches or pull requests

3 participants