-
-
Notifications
You must be signed in to change notification settings - Fork 471
Add prettier.forceFormatDocument
to code actions
#2500
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
Changes from all commits
83b9e1f
9761dd2
45c383f
cc624e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||
import { | ||||||
CodeAction, | ||||||
CodeActionKind, | ||||||
type CodeActionProvider, | ||||||
type ProviderResult, | ||||||
} from "vscode"; | ||||||
|
||||||
const FORCE_FORMAT_DOCUMENT_COMMAND = "prettier.forceFormatDocument"; | ||||||
const FORCE_FORMAT_DOCUMENT_CODE_ACTION_KIND = CodeActionKind.Source.append( | ||||||
FORCE_FORMAT_DOCUMENT_COMMAND | ||||||
); | ||||||
const FORCE_FORMAT_DOCUMENT_TITLE = "Format Document (Forced)"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it forced? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because this code action uses a command of the same name that exists in the command palette.
Suggested change
|
||||||
|
||||||
export default class CodeActionOnSave implements CodeActionProvider { | ||||||
public static readonly providedCodeActionKinds = [ | ||||||
FORCE_FORMAT_DOCUMENT_CODE_ACTION_KIND, | ||||||
]; | ||||||
|
||||||
public provideCodeActions(): ProviderResult<CodeAction[]> { | ||||||
const forceFormatDocumentAction = this.createForceFormatDocumentAction(); | ||||||
return [forceFormatDocumentAction]; | ||||||
} | ||||||
|
||||||
private createForceFormatDocumentAction(): CodeAction { | ||||||
const action = new CodeAction( | ||||||
FORCE_FORMAT_DOCUMENT_TITLE, | ||||||
FORCE_FORMAT_DOCUMENT_CODE_ACTION_KIND | ||||||
); | ||||||
action.command = { | ||||||
command: FORCE_FORMAT_DOCUMENT_COMMAND, | ||||||
title: FORCE_FORMAT_DOCUMENT_TITLE, | ||||||
}; | ||||||
return action; | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a new recommended best practice from the VS Code team or just preference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's not. I'm going to undo this difference if it is not necessary.
This difference has two intent.
First, The intent of this difference is to resolve #1277 by realizing the following quoted portion.
Second, it is for testing the created new code action in this PR.
The intention was to make it clear that I was testing through the code action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like Microsoft's recommended settings
https://github.com/microsoft/vscode-eslint