DEVSENSE / phptools-docs

PHP Tools public content
Apache License 2.0
82 stars 10 forks source link

Auto-indent is stupid #658

Open php4fan opened 1 month ago

php4fan commented 1 month ago

I want to write this:

<?php
$buttons = [];
$buttons[] = [
    [
        'this' => 123,
        'that' => 456
    ]
];

Note that this is the correct default indentation.

So I start writing this: image

Note that so far I have only typed what's before the cursor, and the closing brakets after that have been added automatically. I haven't typed any indentation, all of it has been added automatically and it's as expected so far.

So I keep going: image

Again, so far so good, and I haven't had to manually add or correct any of the indentation.

So now I move the cursor to the end to add the semicolon, and BOOM, as soon as I type the semicolon, this happens:

image

The last closing bracket gets wrongly indented for no reason.

Miloslav commented 1 month ago

Hello,

This is VS Code behaviour which we overwrite by our format on type implementation. Just make sure you have this setting on:

"[php]": {
    "editor.formatOnType": true
}

if you want it for PHP only, or:

"editor.formatOnType": true

globally

php4fan commented 1 month ago

Hmmm, I think I might have disabled "formatOnType" because something about it made me hate it.

Given that this behavior happens even with formatOnType disabled, and it's wrong at least in PHP, shouldn't you override it even with formatOnType disabled?

jakubmisek commented 1 month ago

Is this what's happening to you?

https://github.com/user-attachments/assets/76ccec55-493d-4314-8e82-153d4cd85d4a

Miloslav commented 1 month ago

yes, vsc is putting it to the right and format on type is putting it back to the correct place. We'll check if we could override this somehow, or make a pull request to vsc.

btw. php4fan do you remember what did you hate about format on type. We would try to do something about it. Thanks!

php4fan commented 1 month ago

do you remember what did you hate about format on type. We would try to do something about it.

I'm not sure but now that I think about it, I think it was a "false alarm".

I think I had a yaml file with a multi-line string with empty lines like this:

some_string: |-
    This

    string

    has

    empty 

    lines

and VSC insisted in silently removing the indentations from the empty lines (which in this case is very meaningful), even after I had manually re-added them over and over again, and since I couldn't find a way to disable it for a specific file (which definitely should exist) I just disabled it completely. But, IIRC, it turned out I had mistyped the |-, so it was my fault after all (except that I think if I, the user, insist in manually overriding some auto-indenting decision, the IDE should surrender to my will no matter what). But then I didn't re-enable it because I haven't had any other issue so far with it being disabled.

Miloslav commented 1 month ago

got it, thank you for details!

yaml formatting is completely out of our hands, but you can selectively turn on/off format on type(or any other feature) by specifying the language in settings.json. So for now, you can just turn it on for PHP (by the snippet bellow) and if you find something to hate, please let us know :-)

"[php]": {
    "editor.formatOnType": true
}