phptools-docs
phptools-docs copied to clipboard
Disable auto-formatting
Hi there, is there a way to disable PHP code auto-formatting and only use it on demand?
This is because if I type a statement such as print_r($example); exit;
, it puts the exit
statement on the next line which is unwanted behavior since I'd like to be able to comment out the whole line.
Additionally, the indentation is not always detected correctly and the extensions sometimes reduce the indentation of a new statement which is also unwanted behavior.
It would be nice if I could select a portion, or apply the formatting to the whole document only when asked, not automatically.
This behavior reminds me of other IDEs such as Visual Studio and PhpStorm, which are unpleasant IDEs to work with due to excessive auto-formatting. I'd prefer VS Code to act more like a text editor with advanced symbol scanning instead.
@DRSDavidSoft We have custom formatting rules, so I guess you'd like something like "keep statements on the single line"?
Anyways, you can disable formatting as described on https://docs.devsense.com/en/vscode/editor/formatting#triggering-format :
-
editor.formatOnType
to true which enables the editor to format code blocks and statements upon typing;
and}
. -
editor.formatOnSave
to true instructs the formatter to run when saving the document. -
editor.formatOnPaste
to true triggers format when pasting.
@jakubmisek Thanks for the quick reply,
"keep statements on the single line" Does that exist? (If the statements were typed on a single line, keep it as it is)
Anyways, "editor.formatOnType": false
does not work as it still puts the statement on the next line, and also reduces indentation one level.
cc @Miloslav?
BTW Isn't "editor.format*
options related to global VS Code settings, and NOT the devsense PHP extension? I'd like to specifically turn off formatting in PHP extension, not globally for all other languages.
Also, it would be nice if the formatter could detect that the first line after the <?php
starting tag has an indentation of one level, and instead of forcing every new statement to be brought back one level, keep the indentation that is already used in the file.
Or better yet, if it could detect indentation from adjacent lines (or maybe ask VS Code itself, if there were any APIs for this) instead of trying to calculate it itself, it would be super awesome. Sometimes, I don't entirely agree with the extension's desicion regarding the indentation of statements such as break
, continue
, exit
, etc.
you can set it for php
language only:
"[php]": {
"editor.formatOnType": false
}
If someone specifies editor.formatOnType
= false it will not have an effect on PHP. Only if it's language-specific settings for php
as @jakubmisek mentioned.
This is caused because PHP Tools have this:
"[php]": {
"editor.formatOnType": true
}
as configurationDefaults
in package.json
, since PHPDoc comment generation relies on that.
We should make the PHPDoc generation independent of format on type.
We no longer have "editor.formatOnType": true
as default and since version 1.49
it will not be required for PHPDoc generation.