rayburgemeestre / phpfolding.vim

Automatic folding of PHP functions, classes,.. (also folds related PhpDoc)
http://www.vim.org/scripts/script.php?script_id=1623
45 stars 21 forks source link

PHPDocs that contain /* are not folded #9

Open mikehaertl opened 3 years ago

mikehaertl commented 3 years ago

Here's an example:

    /**
     * @param string $path a path like /path/*.csv
     */
    public function a($path)
    {
    }

    /**
     * Process paths like /path/*.csv
     */
    public function b($path)
    {
    }

Will be folded like:

    /**                                                                                                                                           
     * @param string $path a path like /path/*.csv                                                                                                
     */                                                                                                                                           
+--  4 lines: public function a($path)············································································································
    /**                                                                                                                                           
     * Process paths like /path/*.csv                                                                                                             
     */                                                                                                                                           
+--  3 lines: public function b($path)············································································································
mikehaertl commented 3 years ago

@rayburgemeestre Before I try to work on a fix I want to share some thoughts. I would totally understand if you're no longer much acquainted with or interested in that plugin. Just let me know. I just want to make sure that I don't accidentally break things.

I'm also by no means an expert on vimscript so bare with me:

rayburgemeestre commented 3 years ago

Hi @mikehaertl This weekend I have almost no behind the keyboard time, but I will have a look at this issue hopefully tonight or otherwise Monday for sure. I'm no expert by any means w/r/t vimscript, I still use phpfolding but not as often these days. So I think it's great if we can further improve it. My quick impression from briefly looking is you're probably right with your suggestions.

rayburgemeestre commented 3 years ago

It took me a little longer, twisted my back on Monday so wasn't able to do much :grimacing:

rayburgemeestre commented 3 years ago

P.S. thanks for looking into this plugin. I hope soon to have some time to have a better look at the code myself.

I'm going to think about how we might be able to create some simple unit testing around the script in order to also make refactoring easier. I was thinking a "unit" test could be:

mikehaertl commented 3 years ago

I will also need some time to get back to this issue. Just one thing: How about adding a small demo.php to the repo that contains all (or at least most) common fold cases that this lib covers? Then we can compare before/after our changes to see if things still work as expected. As alternative to a real unit test ...

PS: Just before I wanted to submit my comment I see you added another comment and had the same idea about unit tests :). I think for now a manual test with a demo file would be a good start.

rayburgemeestre commented 3 years ago

I agree with that! Such a demo.php is definitely needed.

w/r/t that unit test automating, I think I actually already found something that we could also automate it with on https://stackoverflow.com/questions/30583388/how-can-i-save-in-vim-a-file-with-the-actual-fold-text-43-lines

(Manually tried it, and it seems to work (:TOhtml /tmp/a.html, then w3m -dump /tmp/a.html))

A quick try of that /**#@+ edge case just now seems to suggest to me actually it is not handled correctly now either. (Or not the way I remember it should work)

/**
 * My Widget class
 */
class Widget
{
    // beginning of docblock template area
    /**#@+
     * @access private
     * @var string
     */
    var $_var1 = 'hello';
    var $_var2 = 'my';
    /**
     * Two words
     */
    var $_var8 = 'like strings';
    /**#@-*/
    var $publicvar = 'Lookee me!';

    public function foo() {
    }
    public static function bar() {

    }
    static public function baz() {

    }
}

I remember having added support for this #@+ stuff working on a very old code base (zend framework version 1) I don't know if anybody still uses this syntax

rayburgemeestre commented 3 years ago

That var $publicvar is getting folded with that #@-

/**#@-*/
var $publicvar = 'Lookee me!';

While I seem to remember that the idea was that everything between @#+ and @#- should be considered one nested block, or just has to be ignored.

mikehaertl commented 3 years ago

I have to admit that I had never seen #@+ before digging through the plugin code and hat to look it up. It's still valid though, according to this: https://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.howto.pkg.html#basics.docblocktemplate

But as this issue here is actually about another problem, how about a new issue dedicated to testing?

mikehaertl commented 3 years ago

Ok I found some time to come up with a simple demo.php (see MR) where I tried include examples for all "normal" use cases.

I intentionally left out the following:

As comments with // are not folded I've used them to mark the expected behavior with // [FOLDED] and // [NOT FOLDED].

Let me know what you think and if something is missing.

Also what do you think about dropping support for #@- and these $GLOBALS folds? If that's OK I could try to cleanup the code a little and also work on the fix for the actual issue here.

rayburgemeestre commented 2 years ago

I also missed your last comment here it seems. Yes, I totally support dropping the #@- and $GLOBALS stuff! Thanks for the contribution. I've merged the demo.php file.

mikehaertl commented 2 years ago

No worries. I see if I find some time over the next days to adress the above topics and also fix this issue here.