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 plugins to do range formatting #7639

Open
dangmai opened this issue Feb 19, 2020 · 2 comments
Open

Allow plugins to do range formatting #7639

dangmai opened this issue Feb 19, 2020 · 2 comments
Labels
area:api Issues with Prettier's Application Programming Interface area:plugin api area:ranges Issues about formatting/ignoring/etc segments of files status:needs discussion Issues needing discussion and a decision to be made before action can be taken type:enhancement A potential new feature to be added, or an improvement to how we print something

Comments

@dangmai
Copy link
Member

dangmai commented Feb 19, 2020

Environments:

  • Prettier Version: 1.19.1
  • Running Prettier via: CLI
  • Runtime: Node.js v12
  • Operating System: Linux

Steps to reproduce:

Currently a Prettier plugin cannot do range formatting correctly, because Prettier core hard codes a list of parsers for isSourceElement here, which is used as a predicate for finding the start and end nodes that contain the range - see here.

Expected behavior:

Prettier should let its plugins set their own isSourceElement or the predicate, so that range formatting can be done by plugins.

Actual behavior:

The current predicate always returns false, which means that range formatting does not happen for custom parsers.

I can open a PR to add this functionality, but I want to check if there's a better solution than I'm not aware of before doing so.

Thank you!

@alexander-akait alexander-akait added area:api Issues with Prettier's Application Programming Interface status:needs discussion Issues needing discussion and a decision to be made before action can be taken type:enhancement A potential new feature to be added, or an improvement to how we print something labels Feb 19, 2020
@alexander-akait
Copy link
Member

I think it is good idea, feel free to send a PR

@BoussonKarel
Copy link

I use Format selection a lot in typescript and handlebars files.

In next-gen Ember, we now have a new component authoring format called with "template tags". These are written in .gts and .gjs files, so we use a plugin (https://github.com/gitKrystan/prettier-plugin-ember-template-tag) to format these.

It would be really handy if I could use this Format selection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:api Issues with Prettier's Application Programming Interface area:plugin api area:ranges Issues about formatting/ignoring/etc segments of files status:needs discussion Issues needing discussion and a decision to be made before action can be taken type:enhancement A potential new feature to be added, or an improvement to how we print something
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants