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

Add code action to format with prettier in codeActionsOnSave in VS Code #1555

Open
bhajneet opened this issue Sep 15, 2020 · 11 comments
Open
Labels
enhancement help-wanted Not something we plan on doing, but we will take a pull request.

Comments

@bhajneet
Copy link

Originally posted by @rohit-gohri in #1277 (comment) is a working solution for running prettier before eslint.

The above solution runs the default formatter (which can be set to Prettier) then uses the code action for eslint afterwards.

There is already one example of a code action to create a config file in this extension.

Could a code action be added for formatting? Such that if a user were to hit ctrl+shift+p in VS Code it would show something like "Prettier: Format Document"

Here are examples from Microsoft

@rohit-gohri
Copy link

This would be great as my current workaround hangs a little when working on bigger projects.

@J3m5
Copy link

J3m5 commented Feb 1, 2021

Please, can we have this feature ?
This would solve the prettier / eslint conflict as from March 2020 we can have order actions on save microsoft/vscode#92681

See related API: https://code.visualstudio.com/api/references/vscode-api#CodeActionProvider

@jtanner
Copy link

jtanner commented Mar 2, 2021

@J3m5
Copy link

J3m5 commented Mar 2, 2021

@jtanner This is what I've been using too for a while and it's working well.

@ntotten ntotten added this to the v6.0.0 milestone Mar 5, 2021
@ntotten ntotten removed this from the v6.0.0 milestone Mar 13, 2021
@ntotten ntotten added the help-wanted Not something we plan on doing, but we will take a pull request. label Apr 5, 2021
@bietkul
Copy link

bietkul commented Jan 22, 2022

Is there any update on this issue?

@bhajneet
Copy link
Author

Currently, this issue has the most thumbs-up emojis:

https://github.com/prettier/prettier-vscode/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc

If @ntotten or any other developer of the project could please share their thoughts on this request, then others in this thread can appreciate a two way conversation

@ntotten
Copy link
Member

ntotten commented Jan 30, 2022

I'm not going to work on this any time soon, but happy to accept a PR.

@roottool
Copy link
Contributor

roottool commented Apr 3, 2022

@bhajneet I have an one question. Which an action do you want?

  1. CodeAction such as Prettier: Create Configuration File
  2. CodeActionsOnSave such as source.fixAll.eslint

I have a feeling you are requesting about 1, but I have a feeling the commenters are requesting about 2.
I want 2 too.

BTW, a code action like "Prettier: Format Document" exists in this extension.
It is "Format Document (Forced)".

"ext.command.forceFormatDocument.title": "Format Document (Forced)",

@J3m5
Copy link

J3m5 commented Apr 3, 2022

@roottool What you are mentioning is the definition of the command exposed on the command palette.
For exposing actions for the CodeActionsOnSave option, the plugin needs to provide a Code Action by using the CodeAction API, and especially a CodeActionKind of type "source"

Base kind for source actions: source

Source code actions apply to the entire file. They must be explicitly requested and will not show in the normal lightbulb menu. Source actions can be run on save using editor.codeActionsOnSave and are also shown in the source context menu.

@roottool
Copy link
Contributor

roottool commented Apr 3, 2022

Thank you for teaching me! I was able to create PR for this issue by your comment.

@silentcloud
Copy link

Mark up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help-wanted Not something we plan on doing, but we will take a pull request.
8 participants