vkravets / FileTemplatesVariable

File Template Variables per Project IDEA plugin
BSD 3-Clause "New" or "Revised" License
12 stars 6 forks source link

Not replacing custom variables on on existing files #6

Closed ghost closed 10 years ago

ghost commented 10 years ago

Hi,

first thanks for this great plugin, proved very useful already!

But I have one little issue.

It it's only replacing the variables when using the "New File" / #parse(<INCLUDE_NAME>) function. It's not working when I simply add a "File and Code Template - Includes" in an existing file.

Thx in advance.

regards

th3fallen commented 10 years ago

The solution i've found for that is to remove the .idea folder and reopen the directory, its not optimal but it works.

vkravets commented 10 years ago

@MTon I'm not sure that understand you... Could you please a litle bit more describe the scenario what happens and what should be?

th3fallen commented 10 years ago

@MTon or a better one i just found is to copy the templates directory from the .idea dir into your old projects.

ghost commented 10 years ago

@vkravets Sorry to be not precise. Next try.

Preconditions

Under the Settings IDE Settings -> File and Code Templates I got these three tabs Templates, Includes and Code

Under the Templates-Tab I got a template for PHP-Classes called PHP Class which looks like this.

<?php
#if (${NAMESPACE})
namespace ${NAMESPACE};
#end

#parse("PHP Class Doc Comment.php")
class ${NAME}
{

}

The Include PHP Class Doc Comment looks like this, where ${AUTHOR} and ${COPYRIGHT} are my custom variables that are set under Default Settings -> File and Code Template Variables and Settings -> Project Settings -> File and Code Template Variables

/**
 *
 * Class        ${NAME}
 *
#if (${NAMESPACE}) * @package     ${NAMESPACE}
#end
 *
 * @author      ${AUTHOR}
 * @copyright   ${COPYRIGHT}
 */

The Problem

When I create a new PHP-Class in a project, ${AUTHOR} and ${COPYRIGHT} are filled with the correct values from the settings. So far so good.

But when I try to add the docblock from the above Include to an existing class. Eg.

<?php
namespace MyNamespace;

class MyClass
{
    // some stuff
}

I'm doing it this by adding /** and press enter above the class definition. It should add the stuff from the above Include too. But I get

<?php
namespace MyNamespace;

/**
 *
 * Class        MyClass
 *
 * @package   MyNamespace
 *
 * @author      ${AUTHOR}
 * @copyright   ${COPYRIGHT}
 */
class MyClass
{
    // some stuff
}

As you can see, the default variables are filed, but the custom ones aren't.

Hope you can follow now :-)

@th3fallen Thx for the suggestions, will try!

ghost commented 10 years ago

@th3fallen Removing the .idea-Folder from the project didn't make any difference to me.

vkravets commented 10 years ago

Ok, now it's clear for me what happens. The similar issue was already open (#3) and I cannot implement such functionality since I cannot inject(trigger) my code during docblock insert. IDEA Platform don't have such API, unfortunately... Sorry... =(

ghost commented 10 years ago

Ok! Thanks a lot anyway!