PHP8.1 Formatting Issue
Subject: Issue with PHP Formatting in PHP8.1, the plugin version is 1.2.12 我目前的配置如下:
"phpfmt.passes": [
"SplitElseIf",
"AlignEquals",
"AlignGroupDoubleArrow",
"AlignPHPCode",
"AlignDoubleArrow",
"AlignComments"
],
before:
$arr = [
'a' => 1, //xxxx
'aa' => 1, // xxxx
'aaaa' => 1,// xxxxxx
'aaaaaa' => 1, // x
];
after format, it becomes like this:
$arr = [
'a' => 1, //xxxx
'aa' => 1, // xxxx
'aaaa' => 1, // xxxxxx
'aaaaaa' => 1, // x
];
exexpected: align comments and alian keys
$arr = [
'a' => 1, //xxxx
'aa' => 1, // xxxx
'aaaa' => 1, // xxxxxx
'aaaaaa' => 1, // x
];
Hi @m2cc , I'm on this. Related to https://github.com/driade/phpfmt8/issues/62
Hi @m2cc . Let's see if the lastest release fixes this. Thanks!
Hi @m2cc . Let's see if the lastest release fixes this. Thanks!你好 。让我们看看最新版本是否修复了这个问题。谢谢!
yes, you fixed this, thank you!!
but when the array keys is chinese,it not works。
the code :
$arr = [
'键一' => 4, // 1
'键2' => 11, // xxxx
'键三' => 12, // xxxx
'其它长键' => 6445, // xxxx
'absc' => 6445, // xxxx
];
after format, it becomes like this:
$arr = [
'键一' => 4, // 1
'键2' => 11, // xxxx
'键三' => 12, // xxxx
'其它长键' => 6445, // xxxx
'absc' => 6445, // xxxx
];
expected: align comments and align keys。
My current configuration is as follows:
"phpfmt.passes": [
"AlignEquals",
"AlignSuperEquals",
"AlignPHPCode",
"AlignDoubleArrow",
"AlignGroupDoubleArrow",
"AlignComments",
"AutoSemicolon",
"ClassToStatic",
"MergeElseIf",
"OrderAndRemoveUseClauses",
"PrettyPrintDocBlocks",
"PSR2EmptyFunction",
"ReindentAndAlignObjOps",
"ReindentSwitchBlocks",
"ReindentEnumBlocks",
"RemoveIncludeParentheses",
"RemoveSemicolonAfterCurly",
"ShortArray",
"SmartLnAfterCurlyOpen",
"SortUseNameSpace",
"SpaceBetweenMethods",
"TrimSpaceBeforeSemicolon",
"WrongConstructorName",
],
Hi @m2cc I've been checking this and I think that the problem is mixing chinese characters with standard ones.
The "space" we use to fill the lines comes from standard " ". But chinese characters are wider than the standard (monospaced) ones, so when we fill the lines with spaces, arrows get visually misaligned.
Please check the screenshot where you may see it.
I've read overthere that people have similar problems
https://github.com/Microsoft/vscode/issues/47983
If chinese characters would be rendered as 2 wide standard chars we could make the calculations to perfectly align the code.