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.
Dear NetBeans Team! My background: I seriously would like to switch from Eclipse to NB as I am interested in building upon the NB Platform. Currently I am working with MyEclipse. As ever when someone using Eclipse comes accross NB he will claim that coding in the NB editor is painful. One of these pains IMHO is this issue for which I could not find any solution on the web. Please please please address this as soon as possible :-) The issue: NB code templates at /Tools/Options/Editor/Code Templates gives use predefined templates and the option for creating custom ones. The issue arises when using custom templates in the editor. Please reproduce as follows: 1. Create a new java class 2. Add a public static void main(String[] args){} method 3. Within the method body type "for" and invoke the code completion "Ctrl+Space" What we get are proposals which take the predefined "forx"-templates into account. Great so far so good. Now reproduce as follows: 1. Open /Tools/Options/Editor/Code Templates 2. Set Language to Java 3. Click New 4. Type "mytemplate" as abbreviation 5. Click OK 6. Type "This is my template text" in the Expanded Text tab 7. Click OK at the bottom of the window 8. Back in the editor delete the typed "for" from the method body 9. Type "mytemplate" and invoke the code completion "Ctrl+Space" What we get is "No suggestions". Sigh :-( What I expected was the same behaviour as for the built-in templates. For me it also does not make much sens to have a hugh stack of custom code templates and have to remember each and every abbreviation to be able to expand it with TAB or whatever. Because please reporduce as follows: 1. Delete the typed "mytemplate" from the method body 2. Retype "mytemplate" and press "TAB" What we get is "This is my template text". This shows us that the IDE is perfectly aware of the custom code templates but for some reason the code completion is not. I file this as an ENHANCEMENT but actually consider it a DEFECT from an Eclipse point of view. I chose P2 as there is a workaround but I consider it difficult and impractical to learn all my custom abbreviations off by heart or use a cheat sheet to get along with the expansion key scenario. It would be very great if you addressed this as soon as possible and make code completion also aware of custom code templates. Looking forward to seeing this fixed :-) Yours sincerly Thomas (A guy who would really love to use NB)
Thanks for your feedback!
*** Issue 163428 has been marked as a duplicate of this issue. ***
*** Issue 166441 has been marked as a duplicate of this issue. ***
I want to switch from Eclipse to NetBeans as well, but I find it particularly difficult to learn that custom code templates require another key(combination) than code completion. Even if this seems negligible, it is quite a cognitive effort I have to take every time thinking on which function I have to use now, where before I just pressed the same keys for completion as well as templates. My suggestion is to be able to enhance the completion feature by including the defined code templates, giving a list of options when different possibilities are available. This would ease using (and switching to) NetBeans for Eclipse users to a really great extent.
CodeTemplateCompletionProvider shows only those code templates in the code completion list that have their contexts specified. The contexts are unique identifiers used by the infrastructure (CodeTemplateFilters) to filter out code templates that are not suitable for the editor context, where a user types. The actual identifiers are defined by each particular language (mime type) and can be different for different languages. The language defines contexts for its constructs such as loops, methods, classes, if-else blocks, etc. and than tags each code template available for that language with a context, where it is meaningful to apply the template. To implement the customizer that allows for uses to specify the contexts for their custom code templates we need the infrastructure (CodeTemplateFilters) to specify all the possible context values valid for the given language (supported by the particular CodeTemplateFilter). To that purpose CodeTemplateFilter.ContextBasedFactory interface with the getSupportedContexts() method is proposed as an extension to the existing SPI.
Created attachment 133919 [details] Proposed SPI change
Fixed in jet-main. http://hg.netbeans.org/jet-main/rev/86f9686c1afc
Integrated into 'main-golden', will be available in build *201305042300* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-golden/rev/86f9686c1afc User: Dusan Balek <dbalek@netbeans.org> Log: Issue #160771: Custom Code Templates and Code Completion - fixed.
*** Bug 212176 has been marked as a duplicate of this bug. ***
Very nice! The next logical step is to allow code templates with the same name so long as the contexts don't overlap. Created issue #232287.
It is not working on netbeans 7.4 Product Version: NetBeans IDE 7.4 (Build 201310111528) Updates: NetBeans IDE is updated to version NetBeans 7.4 Patch 3 Java: 1.8.0_20; Java HotSpot(TM) Client VM 25.20-b23 Runtime: Java(TM) SE Runtime Environment 1.8.0_20-b26 System: Linux version 3.2.0-67-generic-pae running on i386; UTF-8; en_US (nb) User directory: /home/edutrul/.netbeans/7.4 Cache directory: /home/edutrul/.cache/netbeans/7.4 I've got plenty of code templates but code completion is not working yet Do I have to aplly patch or sth like that ? Please help! thanks a lot best regards
Have the code templates configured context? The code completion will not show then, when the context is left blank, (as stated in comment 5)
How to configure context in order to support code completion for PHP ? It is not clear yet Thanks a lot! best regards
(In reply to edutrul from comment #11) > It is not working on netbeans 7.4 > > Product Version: NetBeans IDE 7.4 (Build 201310111528) > Updates: NetBeans IDE is updated to version NetBeans 7.4 Patch 3 > Java: 1.8.0_20; Java HotSpot(TM) Client VM 25.20-b23 > Runtime: Java(TM) SE Runtime Environment 1.8.0_20-b26 > System: Linux version 3.2.0-67-generic-pae running on i386; UTF-8; en_US (nb) > User directory: /home/edutrul/.netbeans/7.4 > Cache directory: /home/edutrul/.cache/netbeans/7.4 > > I've got plenty of code templates but code completion is not working yet > > Do I have to aplly patch or sth like that ? > > Please help! thanks a lot > best regards @edutrul: Please do not reopen issues from old versions (8.0 is the most recent stable). File an issue for the PHP component of NetBeans! Currently the PHP component does not implement the specific API (support of context), so you will never see your PHP templates. FYI: Set the state to Resolved Fixed - again.
(In reply to markiewb from comment #14) > File an issue for the PHP component of NetBeans! See https://netbeans.org/bugzilla/show_bug.cgi?id=246664
Blogged about it at https://benkiew.wordpress.com/2016/01/09/quicktip-how-to-display-your-own-java-code-templates-in-the-code-completion-of-netbeans-ide/