tcomment_vim icon indicating copy to clipboard operation
tcomment_vim copied to clipboard

PHP comment syntax sometimes uses <!-- -->

Open codeinabox opened this issue 10 years ago • 5 comments

This is a follow up to issue #144, which continues after 1a9e65e. Given the following PHP file

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            <!-- new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), -->
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new FOS\RestBundle\FOSRestBundle(),
            new JMS\SerializerBundle\JMSSerializerBundle(),
            new JMS\DiExtraBundle\JMSDiExtraBundle($this),
            new JMS\AopBundle\JMSAopBundle(),
            new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new \Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle()
        );
}

If individually comment lines 3, 12 and 17 to 20 I get the following the comments outside the class are fine but inside the class incorrectly use ""

<?php

// use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            <!-- new Symfony\Bundle\SecurityBundle\SecurityBundle(), -->
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new FOS\RestBundle\FOSRestBundle(),
            <!-- new JMS\SerializerBundle\JMSSerializerBundle(), -->
            <!-- new JMS\DiExtraBundle\JMSDiExtraBundle($this), -->
            <!-- new JMS\AopBundle\JMSAopBundle(), -->
            <!-- new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), -->
            new \Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle()
        );
}

codeinabox avatar Jun 20 '15 18:06 codeinabox

If individually comment lines 3, 12 and 17 to 20 I get the following the comments outside the class are fine but inside the class incorrectly use ""

What's the value of

echo synIDattr(synID(line('.'), col('.'), 1), 'name')

at the first non-whitespace character of the line you want to comment out ("__n__ew")? I get phpDefine.

It would also be interesting to know:

echo map(range(1, col('$') - 1), "synIDattr(synID(line('.'), v:val, 1), 'name')")

Do you use a non-standard php plugin?

tomtom avatar Jun 21 '15 07:06 tomtom

Here is the value of echo synIDattr(synID(line('.'), col('.'), 1), 'name') for each of the lines:

3: phpInclude 12: phpKeyword 17: phpKeyword

For echo map(range(1, col('$') - 1), "synIDattr(synID(line('.'), v:val, 1), 'name')")

Line 3

['phpInclude', 'phpInclude', 'phpInclude', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'p hpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion', 'phpRegion']

Line 12

['rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'phpKeyword', 'phpKeyword', 'phpKeyword', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_ r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rain bow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_p3', 'rainbow_p3', 'rainbow_o2']

I am using shawncplus/phpcomplete.vim but judging by the above could luochen1990/rainbow be interfering?

codeinabox avatar Jun 22 '15 09:06 codeinabox

['rainbow_r2' This could indeed explain the behaviour. tcomment cannot detect the filetype based on the syntax group and uses the fallback filetype, which is "html" for php files.

What's the result of :|echo map(range(1, col('$') - 1), "synIDattr(synID(line('.'), v:val, 0), 'name')")

If it yields something matching php\u\w* then we could do something about it.

Disabling the plugin solves the problem?

| |

tomtom avatar Jun 24 '15 19:06 tomtom

For line 12 I get:

['rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'phpKeyword', 'phpKeyword', 'phpKeyword', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_ r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rain bow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_r2', 'rainbow_p3', 'rainbow_p3', 'rainbow_o2']

Disabling the rainbow plugin gives me this for line 12:

['phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpKeyword', 'phpKeyword', 'phpKeyword', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'p hpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpPare nt', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'phpParent', 'Delimiter', 'Delimiter', 'phpParent']

After that it comments fine properly. If I didn't want to remove the rainbow plugin is there a way I can set the fallback filetype? I could submit a PR to do so.

codeinabox avatar Jun 25 '15 08:06 codeinabox

After that it comments fine properly. If I didn't want to remove the rainbow plugin is there a way I can set the fallback filetype?

You can set g:tcommentGuessFileType_php = 1 or 'php' but you'll probably use the ability to comment out html, js etc. If you're certain that rainbow syntax groups are used only in php code, you could also add a rewrite rule to |g:tcomment#syntax_substitute|.

IMHO you should ask the author of the rainbow plugin to change the syntax definition, maybe add 'transparent'.

HTH

tomtom avatar Jun 25 '15 18:06 tomtom