tomtom / tcomment_vim

An extensible & universal comment vim-plugin that also handles embedded filetypes
http://www.vim.org/scripts/script.php?script_id=1173
GNU General Public License v3.0
1.39k stars 102 forks source link

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

Open codeinabox opened 9 years ago

codeinabox commented 9 years ago

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()
        );
}
tomtom commented 9 years ago

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 ("new")? 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?

codeinabox commented 9 years ago

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', 'rainbowr2', '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?

tomtom commented 9 years ago

['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?

codeinabox commented 9 years ago

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', 'rainbowr2', '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.

tomtom commented 9 years ago

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