2072 / PHP-Indenting-for-VIm

The official VIm indent script for PHP
http://www.2072productions.com/to/phpindent.txt
128 stars 29 forks source link

strange behaviour when last } is inlined #87

Closed gcb closed 1 year ago

gcb commented 1 year ago

inherited some code with style:

require_once('Debug.php');
$baseDebug = new Debug();
function debug( mixed $txt, bool $error=false, bool $force=false ): void{
    global $baseDebug;
    $baseDebug->debug( $txt, $error, $force ); }
function error(string $txt): void{
    global $baseDebug;
    $baseDebug->error( $txt ); }
function debug_flush_to_screen_debug_during_headers(){
    global $baseDebug;
    return $baseDebug->debug_flush_to_screen_debug_during_headers(); }

vim is running with

filetype=php
filetype detection:ON  plugin:ON  indent:ON

I have the tested both the syntax/php.vim from this repo and from the repo linked on the README with latest fixes.

after indenting this block i get:

require_once('Debug.php');
$baseDebug = new Debug();
function debug( mixed $txt, bool $error=false, bool $force=false ): void{
    global $baseDebug;
    $baseDebug->debug( $txt, $error, $force ); }
    function error(string $txt): void{
        global $baseDebug;
        $baseDebug->error( $txt ); }
        function debug_flush_to_screen_debug_during_headers(){
            global $baseDebug;
            return $baseDebug->debug_flush_to_screen_debug_during_headers(); }
2072 commented 1 year ago

Thanks for your report and the example. I was able to reproduce the problem, I'll look into it.

gcb commented 1 year ago

thank you! i was trying to fix these last days, but failing. I don't think i will go anywhere.

2072 commented 1 year ago

OK this is fixed.

This script uses a lot of heuristics to do its job, when debugging you need to do 2 things:

" Only define the functions once per Vim session.
if exists("*GetPhpIndent")
    call ResetPhpOptions()
    finish " XXX -- comment this line for easy dev
endif

and enable the debug by executing the command: :%s /" DEBUG \zec//g (you can disable them with :%s /^\s*\zs\zecall DebugPrintReturn/" DEBUG /g)

Then try to indent the line causing issues and follow what is happening to find out which part of the script is causing the issue.

I'm going to add this to the readme.md.