Closed dxkite closed 7 years ago
Thanks for taking the time to open this issue.
Unfortunately there is no fix for this as of now. Microsoft is working on a preSave event for VSCode, which would prevent this issue from cropping up. It is currently in the backlog of the September milestone.
For now, you can work around this issue by creating a custom command that triggers this extension's fix functionality.
In order to avoid future confusion, I will add this to the extension's docs and readme.
You can add Format Code to Right click menu like Native Command Ctrl+F
That's a great suggestion. Do you happen to know how the when
condition should be setup to allow file extensions other than php?
I'm trying something like this:
"contributes": {
"commands": [
{
"command": "phpformatter.fix",
"title": "Format PHP",
"icon": {
"light": "./images/fix-icon-light.svg",
"dark": "./images/fix-icon-dark.svg"
}
}
],
"menus": {
"editor/context": [
{
"when": "resourceLangId == php || vscode.workspace.getConfiguration('phpformatter').get('additionalExtensions', []).indexOf(resourceLangId) > -1",
"command": "phpformatter.fix"
}
]
}
}
htm* or tpl ?
Let me elaborate by saying that I'm trying to use a user setting in the when
condition.
So, if I configured my extension like this:
"phpformatter.additionalExtensions": [
"tpl", "inc"
]
Then the context menu option should only be visible when editing either of those file types. Otherwise the context menu option would be visible on every file type, which would just clutter the UI.
You Can add a item like Format As PHP
when The Extension may has Php code,Or Just Use in php file, another file needn't Format such as in html or template :
<title><?php echo $title ; ?></title>
Yes, that would indeed be unnecessary. However, what I meant is that it would be even less necessary to have the context menu item at all, it the current file is not a PHP file.
So I'm looking for a way to check whether the current file is a PHP file. If that is the case, the context menu item should be displayed. If it is not a PHP file, it should check the user setting called phpformatter.additionalExtensions
. If the current file type matches any of those, it should also display the context menu item.
Last Night,I use PHP Function token_get_all
to Compile template file ( Copy from Laravel ) ,I guess Maybe Can use something like this?
@Dickurt Since version 1.6 VS Code supports the onWillSaveTextDocument
-event. Also there is a new editor.formatOnSave
-setting that will invoke registered formatters on save, see #5
Resolved with conversion to TypeScript in latest milestone.
when set onSave is true, i save some file, the file formatted, but file status is "change" i need to save again,Then Formatting Again And Again....