This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 212742 - Code templates are broken in 7.2
Summary: Code templates are broken in 7.2
Status: RESOLVED WORKSFORME
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 7.1.2
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Assignee: Ondrej Brejla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-19 22:25 UTC by digitman
Modified: 2012-08-16 09:42 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Test project where templates don't work (2.18 MB, application/octet-stream)
2012-05-21 13:20 UTC, digitman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description digitman 2012-05-19 22:25:07 UTC
(All methods require that the 'expand tabs to spaces' setting is on under tools > options > editor > formatting )

Method to reproduce # 1: 

- Open a new php file.

- Type fore and press tab.

- Sometimes this will cause a foreach loop template to be placed in, other times it will just add a tab. Assuming that it does work:

- Delete the code and type fore and hit tab again.

- Template isn't generated.

Method to reproduce # 2:

- Open a php file

- Type fore and hit tab. Assuming that it produces the foreach template:

- Press enter and type fore and hit tab again.

- Template isn't expanded to foreach.

Turning off the expand tabs to spaces option fixes this.
Comment 1 digitman 2012-05-19 22:26:47 UTC
This seems to be related to this bug:

http://netbeans.org/bugzilla/show_bug.cgi?id=197887

It was marked as fixed, perhaps the fix isn't included in the netbeans download?
Comment 2 digitman 2012-05-20 05:36:46 UTC
Correction, I have the 'Expand spaces to tabs' setting disabled and templates still don't seem to be working for me. So this probably doesn't have anything to do with that setting :(.

Please fix this?
Comment 3 Ondrej Brejla 2012-05-21 07:33:40 UTC
Sorry, but I have todays build and it works properly for me in all cases you described. There is just one use case, I think, when code templates are not expanded...if the scanning of sources is in progress. But it can't be simply workarounded since we need the whole parser result to evaluate the right context (to know which templates can be expanded and which can't).

Product Version: NetBeans IDE Dev (Build 20120521-4b726a72112f)
Java: 1.6.0_26; Java HotSpot(TM) Client VM 20.1-b02
System: Linux version 3.2.0-24-generic-pae running on i386; UTF-8; cs_CZ (nb)
User directory: /home/warden/userdir
Cache directory: /home/warden/userdir/var/cache
Comment 4 digitman 2012-05-21 09:47:42 UTC
Hi,

It sometimes works and other times it doesn't, have you tried at least a few times? Its possible that if you tried it once and it worked, but if you tried it again a few times (especially after deleting the code and saving) then it won't.

Otherwise its possible that I don't have the latest build though I installed 7.1.2 a few days ago. Where can I download the latest build?
Comment 5 Ondrej Brejla 2012-05-21 11:07:23 UTC
I tried it many times, because I use the latest NB (7.2dev) for developing of PHP apps. So try that [1]. But I can't do anything with that if I'm not able to reproduce that :(

[1] http://bits.netbeans.org/download/trunk/nightly/latest/
Comment 6 digitman 2012-05-21 12:12:58 UTC
Could you try this code:

<?php
set_time_limit(0);
error_reporting(E_ALL);
class Test extends BaseController
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
		
    }
}
?>

Inside the function, type a template, hit tab. If it works, press enter, hit CTRL + S, then type the abbreviation and hit tab again. Do this at least 2-3 times, when I try this it randomly works and doesn't work for me.

Let me know if it still works or not, thanks.
Comment 7 Ondrej Brejla 2012-05-21 12:31:52 UTC
I tried it many times, and the result is as expected.

<?php

set_time_limit(0);
error_reporting(E_ALL);
class Test extends BaseController
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        foreach ($array as $value) {
            foreach ($array as $value) {
                foreach ($array as $value) {
                    foreach ($array as $value) {
                        foreach (fore as $value) {
                            foreach ($array as $value) {
                                foreach ($array as $value) {
                                    foreach ($array as $value) {
                                        
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
?>

Don't know what to suggest to you... I can better watch the behavior of code templates during my PHP coding, but as I wrote, it works for me properly and I didn't noticed any inconvenience in 7.2 dev.
Comment 8 digitman 2012-05-21 12:47:59 UTC
Hello,

Thanks for your help in this.

Which operating system are you trying this on? I'm using Windows XP.

If I try it with the fore template, it seems to work most of the time for me, however if I try it with a custom template that I added (dbs expanding to $this->db->set() ) then I get this output:

<?php
set_time_limit(0);
error_reporting(E_ALL);
class Test extends BaseController
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
		dbs	
		dbs	
		$this->db->set();
		dbs	
		dbs	
		dbs	
		dbs	
		$this->db->set();
		dbs	
		dbs	
		$this->db->set();
		dbs	
		dbs	
		dbs	
		dbs	
		dbs	
		$this->db->set();
    }
}
?>

Culd you may be try that template? Also,have you tested doing CTRL + S after each template, and deleting a template and trying to re insert it in the same place?
Comment 9 digitman 2012-05-21 12:57:24 UTC
Hello,

On further testing I've found that if I grab a single php file which is not linked to any project, and I test the same thing, the templates work. However if I add a new file to a project which has 100+ files (using the codeigniter framework) then I get the output as in my last comment.

Is there any chance if you could download codeigniter from http://codeigniter.com/downloads/ , add a new project from existing sources and import codeigniter into that, then add a new file to that project, and test the same code as my last comment?
Comment 10 digitman 2012-05-21 13:20:48 UTC
Created attachment 119687 [details]
Test project where templates don't work

Hello,

I've narrowed this problem down, its definitely related to when a file is added to an existing project. If its a single file, then templates work, but in a project, they don't.

For your convenience I'm attaching a .zip of a test project I just created to test this. If you open controllers/test.php and test the dbs template in there (expanding to $this->db->set() ) then it should likely reproduce the bug for you.

Just extract the zip and then in netbeans, do 'File -> Open project' and point to the directory where you extracted.

Thanks again for your help.
Comment 11 Ondrej Brejla 2012-05-21 13:22:21 UTC
I'll try it, thanks.
Comment 12 Ondrej Brejla 2012-05-21 13:23:06 UTC
Have you tried the dev build 7.2? I put here a link.

http://bits.netbeans.org/download/trunk/nightly/latest/
Comment 13 digitman 2012-05-21 13:26:05 UTC
I don't think I have to because the templates are working for me if I test on a file not linked to a project. If they work for you in the test project I sent, then I'll download and try it.
Comment 14 digitman 2012-05-21 13:31:09 UTC
The file to test it in is application/controllers/test.php
Comment 15 Ondrej Brejla 2012-05-21 13:45:00 UTC
I tried it right now and it work for me properly with both "expand tabs" (which has nothing to do with invoking code templates AFAIK) settings...and with your type of custom code template in your CodeIgniter_2.1.0 project. No problem at all. Sorry.
Comment 16 digitman 2012-05-21 13:47:29 UTC
ok, i will try installing the version you linked
Comment 17 Ondrej Brejla 2012-05-21 13:49:10 UTC
Don't forget to DO NOT IMPORT old NB settings...make a pure clean instalation.
Comment 18 digitman 2012-05-21 13:51:43 UTC
will do
Comment 19 digitman 2012-05-21 14:29:09 UTC
Hello,

I've downloaded and installed the version you linked, but I get this error when I  try to run it:

http://i45.tinypic.com/12172q1.png

I've checked that the folder netbeans/dev on that path exists but still the same error.

Any ideas? Should I just do a pure re-install from http://netbeans.org/downloads/index.html ?
Comment 20 Ondrej Brejla 2012-05-21 14:34:11 UTC
The development version should create its own user directory. And it has been created since you have a "dev" directory there. Try to delete it and reinstal that Dev version. It should work without any problem. Really don't know why it complains.

Or you can try this one: http://bertram2.netbeans.org:8080/job/PHP-build/lastSuccessfulBuild/artifact/nbbuild/NetBeans-dev-2012-05-21_06-03-55%20-php.zip
Comment 21 digitman 2012-05-21 15:00:53 UTC
Deleted the dev directory and reinstalled, same issue. How about I download the stable 7.1.2 again and do a pure install?
Comment 22 digitman 2012-05-21 15:37:49 UTC
I tried a clean install of 7.1.2 but it doesn't work in that either.

downloaded the .zip you linked but it seems to have the source code and not an installer.
Comment 23 Ondrej Brejla 2012-05-22 06:21:16 UTC
Sorry, but I need a response from your use of 7.2, not 7.1.2. But I still can't reproduce that. Yes, that zip is not installable, you can just run the sources.

Vlado, can you reproduce that with a 7.2dev on Windows? Thanks.

Please, let the status be, until Vlada tries that on win and writes some conclusion. Thanks.
Comment 24 digitman 2012-05-22 15:31:37 UTC
I don't think I can run that version because of the bug that pops up regarding the dev folder.
Comment 25 Vladimir Riha 2012-05-22 22:18:44 UTC
Sorry, cannot reproduce it. The only possible situation when the template is not expanded is if you type "fore" and wait a while so the code completion window appears and atfer that simple "foreach" is completed from CC instead of expanding template. And this seems OK to me.

Custom template also works for me.




Product Version: NetBeans IDE Dev (Build 201205200400)
Java: 1.7.0_04; Java HotSpot(TM) Client VM 23.0-b21
System: Windows 7 version 6.1 running on x86; Cp1252; en_US (nb)
Comment 26 Ondrej Brejla 2012-05-23 06:19:08 UTC
Thanks.
Comment 27 digitman 2012-05-23 09:05:18 UTC
Guys, any chance you could try that on windows XP?
Comment 28 Vladimir Riha 2012-06-12 11:49:08 UTC
So I checked WindowsXP and it also works fine, sorry


Product Version: NetBeans IDE Dev (Build 201206120719)
Java: 1.6.0_26; Java HotSpot(TM) Client VM 20.1-b02
System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb)
Comment 29 tylik 2012-08-16 09:02:50 UTC
I'm running Windows 7x64 and having problems with code templates also. I've upgraded from netbeans 6.9 to 7.2 an code templates don't work as they used to.
They work with html file, but don't work with css and js files. I've imported all my defaults from Netbeans 6.9 as I've made tons of code templates for front-end web developmentand don't have time to rewrite from scratch. I've tried files from php project and also standalone files. The problem appears in both of them.
Comment 30 tylik 2012-08-16 09:09:59 UTC
I've found out the problem.
${selection} reserved name doesn't work in netbeans 7.2
When I remove ${selection} everything works as before.
Comment 31 Ondrej Brejla 2012-08-16 09:16:33 UTC
Don't reopen this issue if code templates for JS and HTML don't work for you. It's not handled by php. File new issues for JS.

And upgrade from 6.9 to 7.2 is not supported afaik. Only upgrade from one previous version to new one is supperted. Try it with a clean install and fresh userdir.

Lado, can you confirm such a problems?
Comment 32 tylik 2012-08-16 09:36:45 UTC
Ok, sorry. In php code templates ${selection} works properly
Comment 33 Vladimir Riha 2012-08-16 09:42:26 UTC
${selection} works for me too, I'll try the upgrade scenario as Ondra said, only 1 version back is supported, so 7.1