Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 348857 - [content assist] Allow to disable auto insertion trigger characters
Summary: [content assist] Allow to disable auto insertion trigger characters
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 enhancement with 14 votes (vote)
Target Milestone: 4.10 M3   Edit
Assignee: Mickael Istria CLA
QA Contact:
URL:
Whiteboard:
Keywords: Documentation, noteworthy
: 420425 421440 433580 453125 500846 534648 537873 538815 (view as bug list)
Depends on: 539165
Blocks: 508789
  Show dependency tree
 
Reported: 2011-06-09 05:44 EDT by raelg CLA
Modified: 2018-11-21 04:52 EST (History)
22 users (show)

See Also:


Attachments
In the meantime, a workaround (16.82 KB, application/octet-stream)
2013-10-28 10:43 EDT, Timo Kinnunen CLA
no flags Details
A better workaround (with tab completion!) (1.62 MB, application/octet-stream)
2015-04-18 17:17 EDT, Mikey Jensen CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description raelg CLA 2011-06-09 05:44:59 EDT
Build Identifier: 20100218-1602

Hi,

I've set my content assist to suggest code completion as I type (By setting activation triggers to ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._).

The biggest problem with this is suggestions are often auto inserted. 

e.g. typing 
String som
  will suggest somString. This in itself is fine, but the suggestion is automatically inserted upon pressing ; which is usually wrong for parameter name suggestions.

Are there any plugins which behaviour more like Xcode or Visual Studio? Alternatively is it possible for me to write a plugin to 

Reproducible: Always

Steps to Reproduce:
1. Set Java Content Assist Activation Trigger to ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
2. type String anything
3. type ;
Comment 1 Dani Megert CLA 2011-06-09 06:18:37 EDT
>automatically inserted upon pressing ; which is usually wrong for parameter
>name suggestions.
Why to you press ';' then?
Comment 2 raelg CLA 2011-06-09 06:57:59 EDT

(In reply to comment #1)
> >automatically inserted upon pressing ; which is usually wrong for parameter
> >name suggestions.
> Why to you press ';' then?

because java statements terminate with ; ??
Comment 3 Dani Megert CLA 2011-06-09 07:09:14 EDT
(In reply to comment #2)
> 
> (In reply to comment #1)
> > >automatically inserted upon pressing ; which is usually wrong for parameter
> > >name suggestions.
> > Why to you press ';' then?
> 
> because java statements terminate with ; ??

Right, but your not in a statement probably but triggered content assist automatically at the wrong location because you entered all chars as auto-activation triggers.

There's no setting that lets you change this behavior.
Comment 4 raelg CLA 2011-06-09 07:50:04 EDT
(In reply to comment #3)
> (In reply to comment #2)
> > 
> > (In reply to comment #1)
> > > >automatically inserted upon pressing ; which is usually wrong for parameter
> > > >name suggestions.
> > > Why to you press ';' then?
> > 
> > because java statements terminate with ; ??
> 
> Right, but your not in a statement probably but triggered content assist
> automatically at the wrong location because you entered all chars as
> auto-activation triggers.
> 
> There's no setting that lets you change this behavior.

I thought this was the place to raise change requests for unexpected behaviour. I really believe implementing something like this will result in a significant increase in productivity. Switching from Xcode or Visual Studio to Eclipse makes Eclipse development seem incredibly inefficient.
Comment 5 Dani Megert CLA 2011-06-09 08:09:42 EDT
Currently content assist is not targeted for the scenario where one adds all characters as triggers and we currently don't plan to work on this.

If someone wants to offer an option to disable ';' as auto-insertion character then I'm fine with that.
Comment 6 raelg CLA 2011-06-09 08:55:43 EDT
(In reply to comment #5)
> Currently content assist is not targeted for the scenario where one adds all
> characters as triggers and we currently don't plan to work on this.
> 
> If someone wants to offer an option to disable ';' as auto-insertion character
> then I'm fine with that.

time pending, it is something I can look at. As a quick fix can you point me in the correct direction to write a plugin which overrides the default behaviour?
Comment 7 Dani Megert CLA 2011-06-09 09:06:08 EDT
> As a quick fix can you point me in
> the correct direction to write a plugin which overrides the default behaviour?
There's no way to do this from the outside.
Comment 8 Martin Mathew CLA 2013-10-26 02:00:50 EDT
*** Bug 420425 has been marked as a duplicate of this bug. ***
Comment 9 Timo Kinnunen CLA 2013-10-27 00:10:56 EDT
Those triggers don't work correctly. I've configured content assist to auto-activate from keys ; ,.[(=- but when I write a local variable declaration and want to initialize it, pressing <SPACE>, '=', <SPACE> results in (| marks where caret is): 
int name name=name |, and the '=' is in wrong place. So I press that again and the end of line becomes: 
name name=|, now the space is not where it should be! So I press that again which results in:
name=name |, now the assignment is not correct, so I press that again, and so on and so on... Start with:

/* indent here */		String[] \u000a_ALL_WORK_AND_NO_PLAY_MAKES_JACK_A_DULL_BOY|

and soon you workspace is full of: 

/* indent here */		String[] \u000a_ALL_WORK_AND_NO_PLAY_MAKES_JACK_A_DULL_BOY 
ALL_WORK_AND_NO_PLAY_MAKES_JACK_A_DULL_BOY=
ALL_WORK_AND_NO_PLAY_MAKES_JACK_A_DULL_BOY 
ALL_WORK_AND_NO_PLAY_MAKES_JACK_A_DULL_BOY=
ALL_WORK_AND_NO_PLAY_MAKES_JACK_A_DULL_BOY 
ALL_WORK_AND_NO_PLAY_MAKES_JACK_A_DULL_BOY=
ALL_WORK_AND_NO_PLAY_MAKES_JACK_A_DULL_BOY |

This isn't how content assist auto-activation is supposed to work!
Comment 10 Martin Mathew CLA 2013-10-28 03:49:09 EDT
(In reply to Timo Kinnunen from comment #9)
> Those triggers don't work correctly. 
The triggers mentioned in bug 420425(if you are referring to those) are meant to select one of the proposal from the pop-up. These trigger characters are fixed and not configurable.
Auto activation trigger available in preference page (by default '.') is to activate the content proposal pop-up.
Comment 11 Timo Kinnunen CLA 2013-10-28 06:04:47 EDT
Yep, that's where I learned of them. I am kind of cheating by having seen their special status from the code and then using them in a way that maximizes the chances of something going wrong from triggering a data race or an unanticipated interaction in some corner-case. 

Still, there's nothing in the settings UI which would suggest that some keys are special, that they should not be used for auto-activation or that if they are used for auto-activation then the resulting behavior is unspecified. Nor should there be any of that, because some keys being handled on different code paths internally should not be of concern to the consumer.
Comment 12 Timo Kinnunen CLA 2013-10-28 10:43:47 EDT
Created attachment 236956 [details]
In the meantime, a workaround

Here's a small plugin that is used by copying it into your eclipse\dropins -folder. 

The plugin disables Content Assist auto-completion trigger keys automatically every time Eclipse starts. In addition there's a toolbar button and a menu item to toggle the disabled keys back on and off. Source code included.
Comment 13 Pascal Seitz CLA 2013-10-28 15:48:45 EDT
Works great! Thank you so much!
Comment 14 Timo Kinnunen CLA 2014-03-31 09:28:24 EDT
I finally got to cleaning up some old changes and came to this plugin, so here is Gerrit  https://git.eclipse.org/r/24199  for review.
Comment 15 Dani Megert CLA 2014-04-16 06:10:12 EDT
We'll try to review during 4.5.
Comment 16 Dani Megert CLA 2014-04-16 06:31:21 EDT
(In reply to Dani Megert from comment #15)
> We'll try to review during 4.5.

I took a quick look at the Gerrit change: We should offer to set the auto insertion characters like we allow to set the auto activation triggers. The proposed change only allows to disable all at once.
Comment 17 Timo Kinnunen CLA 2014-04-24 03:44:22 EDT
Latest Gerrit patch adds the option to both add additional characters and disable existing trigger characters. In addition trigger characters can optionally be used to close Content Assist instead of inserting the selected completion. That feature is a bit of a hack but the implementation seems to stay within the confines of the APIs.
Comment 18 Dani Megert CLA 2014-04-27 12:24:15 EDT
*** Bug 433580 has been marked as a duplicate of this bug. ***
Comment 19 Tomas R. CLA 2014-05-16 09:55:26 EDT
It is certainly extremely annoying when 'int<space>' autocomplete turns into some 'INTernalWhatnot<space>' on every turn. I remember days, when this wasn't an issue.

BUT

There is another (and complimentary) solution:
- The first suggestion offered by autocomplete should always be the EXACT typed-in words if there is a match.

IMHO in addition to creating this patch, there should be another and simple patch for the auto-complete suggestions list.


That's just my two cents.

Best wishes,
Tomas
Comment 20 Timo Kinnunen CLA 2014-05-16 13:56:09 EDT
(In reply to comment #19)
> - The first suggestion offered by autocomplete should always be the EXACT
> typed-in words if there is a match.
> 
> IMHO in addition to creating this patch, there should be another and simple
> patch for the auto-complete suggestions list.

Haa, guess what my patch does when 'Auto completion resets' option has been selected :)

(TBH, it simply alters the current completion to replace the to-be-inserted characters with what you've already typed at the moment auto completion gets triggered, it doesn't add or change existing completions.)
Comment 21 Mikey Jensen CLA 2015-04-18 17:17:02 EDT
Created attachment 252514 [details]
A better workaround (with tab completion!)

Fixes the Auto completion bug in Eclipse Luna SR2 4.4.2.

Changes auto completion to be triggered only pressing Enter or Tab, nothing else.

I recommend using this with an auto-activation delay of 50ms, and the following triggers: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz =.(!+-*/~,[{@#$%^&" (note the inclusion of the space character).
Comment 22 Mikey Jensen CLA 2015-04-18 17:19:59 EDT
Please, when you implement this, allow for tab to be a valid completion character!!

FYI, Timo Kinnunen's work around plug-in doesn't work for me, so I just made my own patch of the relevant code (via this SO answer: http://stackoverflow.com/a/21898810/398630):

The jar (with embedded src) can be found at http://1drv.ms/1GZhJPq (also, I've attached it to the bug above) -- just dump it in your plugins folder (you probably want to back up the old file, just in case).

The major modification is that in src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java in the verifyKey method, in the second switch statement:

1.) I disabled the default handler, because it's ridiculous that it tries to insert crap that the user hasn't selected.
2.) I disabled the '\t' handler because '\t' should insert, not switch focus to the auto completion window (up and down work just fine, thank you!)
3.) for the handler above those two (the handler for '\r' and '\n'), I added '\t' to the list.

For reference, my auto activation delay is 50ms, and my triggers for Java are: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz =.(!+-*/~,[{@#$%^&" (this includes the space character of course!).
Comment 23 Dani Megert CLA 2015-07-22 08:42:37 EDT
*** Bug 453125 has been marked as a duplicate of this bug. ***
Comment 24 Markus Keller CLA 2015-12-02 13:12:44 EST
*** Bug 421440 has been marked as a duplicate of this bug. ***
Comment 25 Karim Fatehi CLA 2016-01-08 13:56:31 EST
is this bug scheduled to come out anytime soon? im not able to drop in a jar because we dont do that in corp environments.
Comment 26 Dani Megert CLA 2016-01-11 11:31:33 EST
(In reply to Karim Fatehi from comment #25)
> is this bug scheduled to come out anytime soon? im not able to drop in a jar
> because we dont do that in corp environments.

I don't see any relationship to this bug report.
Comment 27 Karim Fatehi CLA 2016-02-03 16:05:02 EST
(In reply to Dani Megert from comment #26)
> (In reply to Karim Fatehi from comment #25)
> > is this bug scheduled to come out anytime soon? im not able to drop in a jar
> > because we dont do that in corp environments.
> 
> I don't see any relationship to this bug report.

sorry, what i meant is, are we going to make it so that the auto inserting triggers will be configurable? i would like to remove space as the acceptance key because i want constant content assist without accepting incorrect choices.
Comment 28 Noopur Gupta CLA 2016-09-06 05:03:16 EDT
*** Bug 500846 has been marked as a duplicate of this bug. ***
Comment 29 Lars Vogel CLA 2016-11-23 01:27:10 EST
FYI - This bug was reported as one of the major pain points in using JDT code completion. See thread behind https://dev.eclipse.org/mhonarc/lists/platform-ui-dev/msg07540.html
Comment 30 Dario Arena CLA 2017-09-01 10:57:44 EDT
I've encountered this issue too. In java this is somewhat tolerable (but annoying sometimes) but in other languages (I occasionally write some Spock tests using Groovy) this forces me to press "ESC" for every keyword i write or disabling autocompletion at all to avoid wrong keyword being inserted. 
"Classic" autocompletion works but i think is a little obsolete because i find this autocompletion method much more convenient.
To me one big improvement would be disabling autocompletion insertion on SPACEBAR and on SEMICOLON.
Comment 31 bob ross CLA 2018-09-03 18:33:00 EDT
I've also encountered this bug, and it also happens a space, '(', or '.' is typed, in addition the the already mentioned ';'. From reading through the comments, it seemed as though the issue was going to be fixed, but it never was. Are there still plans to fix this?
Comment 32 bob ross CLA 2018-09-04 09:04:11 EDT
Auto completion also automatically activates on the following characters:


protected final static char[] METHOD_TRIGGERS= new char[] { ';', ',', '.', '\t', '[', ' ' };

protected final static char[] METHOD_WITH_ARGUMENTS_TRIGGERS= new char[] { '(', '-', ' ' };

protected final static char[] TYPE_TRIGGERS= new char[] { '.', '\t', '[', '(', ' ' };

protected final static char[] VAR_TRIGGER= new char[] { '\t', ' ', '=', ';', '.' };


Because there are so many different auto-insertion characters, I think that it would be a better idea to add a single option to only insert suggestions with 'Enter', instead of having multiple options to turn off each character.
Comment 33 Stephan Herrmann CLA 2018-09-08 08:39:58 EDT
*** Bug 538815 has been marked as a duplicate of this bug. ***
Comment 34 bob ross CLA 2018-09-10 19:48:47 EDT
*** Bug 537873 has been marked as a duplicate of this bug. ***
Comment 35 bob ross CLA 2018-09-10 19:53:39 EDT
I am trying to fix this bug. My proposed fix is:
An option under Preferences -> Java -> Editor -> Content assist. The option would be a checkbox, and it would say "Only insert suggestions when enter key is pressed". I would appreciate any help/guidance in fixing this bug (I can't figure out which sources/classes I need).
Comment 36 Lars Vogel CLA 2018-09-11 01:03:25 EDT
(In reply to bob ross from comment #35)
> I am trying to fix this bug. My proposed fix is:
> An option under Preferences -> Java -> Editor -> Content assist. The option
> would be a checkbox, and it would say "Only insert suggestions when enter
> key is pressed". I would appreciate any help/guidance in fixing this bug (I
> can't figure out which sources/classes I need).

To find the class under the preference pages, you use the plug-in spy http://www.vogella.com/tutorials/EclipsePlatformDevelopment/article.html#plug-in-spy-for-ui-parts.
Comment 37 Mickael Istria CLA 2018-09-11 02:34:21 EDT
(In reply to bob ross from comment #35)
> I would appreciate any help/guidance in fixing this bug (I
> can't figure out which sources/classes I need).

The place where to change the UI is CodeAssistConfigurationBlock.
The place where to change in the "model" is CompletionProposalCollector where you can see the trigger chars for selection of a proposal are hardcoded.
A global preference allowing to bypass those hardcoded ones and pass en empty list of trigger chars instead would be fine. Note that you don't need to add the support for "Enter" as it's built-in, here it's only about removing those extra chars.
Good luck, and thanks for taking care of this! Feel free to ping on the ticket or on Gerrit reviews whenever necessary.
Comment 38 Mickael Istria CLA 2018-09-11 05:44:21 EDT
(In reply to bob ross from comment #35)
> I am trying to fix this bug. My proposed fix is:
> An option under Preferences -> Java -> Editor -> Content assist. The option
> would be a checkbox, and it would say "Only insert suggestions when enter
> key is pressed". I would appreciate any help/guidance in fixing this bug (I
> can't figure out which sources/classes I need).

I seems a lot like what was proposed in https://git.eclipse.org/r/#/c/24199/ , and I'd like to influence in getting this patch merged without need for extra settings.
Can you please give a try to that patch and see whether it works for your use-case and vote/comment on the Gerrit review accordingly.
@Timo: are you still around? Any chance you can rebase your patch?
Comment 39 bob ross CLA 2018-09-11 06:19:34 EDT
(In reply to Mickael Istria from comment #38)
> (In reply to bob ross from comment #35)
> > I am trying to fix this bug. My proposed fix is:
> > An option under Preferences -> Java -> Editor -> Content assist. The option
> > would be a checkbox, and it would say "Only insert suggestions when enter
> > key is pressed". I would appreciate any help/guidance in fixing this bug (I
> > can't figure out which sources/classes I need).
> 
> I seems a lot like what was proposed in https://git.eclipse.org/r/#/c/24199/
> , and I'd like to influence in getting this patch merged without need for
> extra settings.
> Can you please give a try to that patch and see whether it works for your
> use-case and vote/comment on the Gerrit review accordingly.
> @Timo: are you still around? Any chance you can rebase your patch?

I am a little confused now: is the bug already fixed and waiting to be merged?
Comment 40 bob ross CLA 2018-09-11 06:46:54 EDT
(In reply to bob ross from comment #39)
> I am a little confused now: is the bug already fixed and waiting to be merged?

Oh (In reply to bob ross from comment #39)
> (In reply to Mickael Istria from comment #38)
> > (In reply to bob ross from comment #35)
> > > I am trying to fix this bug. My proposed fix is:
> > > An option under Preferences -> Java -> Editor -> Content assist. The option
> > > would be a checkbox, and it would say "Only insert suggestions when enter
> > > key is pressed". I would appreciate any help/guidance in fixing this bug (I
> > > can't figure out which sources/classes I need).
> > 
> > I seems a lot like what was proposed in https://git.eclipse.org/r/#/c/24199/
> > , and I'd like to influence in getting this patch merged without need for
> > extra settings.
> > Can you please give a try to that patch and see whether it works for your
> > use-case and vote/comment on the Gerrit review accordingly.
> > @Timo: are you still around? Any chance you can rebase your patch?
> 
> I am a little confused now: is the bug already fixed and waiting to be
> merged?

Sorry, I did not realize that a patch was already pending. The patch that you linked to is exactly what I was going to do, although we don't need an option to turn off specific characters individually,  only an option to turn them all off (except for the 'enter' key)
Comment 41 Mickael Istria CLA 2018-09-11 09:54:23 EDT
(In reply to bob ross from comment #39)
> Sorry, I did not realize that a patch was already pending.

Me neither, until a few hours ago ;)

> The patch that
> you linked to is exactly what I was going to do, although we don't need an
> option to turn off specific characters individually, only an option to turn
> them all off (except for the 'enter' key)

I agree.
Can you please at least try the pach and comment on the Gerrit whether it fits your use-case? And also comment about the options you find useless?
Comment 42 bob ross CLA 2018-09-14 18:50:38 EDT
(In reply to Mickael Istria from comment #41)
> (In reply to bob ross from comment #39)
> > Sorry, I did not realize that a patch was already pending.
> 
> Me neither, until a few hours ago ;)
> 
> > The patch that
> > you linked to is exactly what I was going to do, although we don't need an
> > option to turn off specific characters individually, only an option to turn
> > them all off (except for the 'enter' key)
> 
> I agree.
> Can you please at least try the pach and comment on the Gerrit whether it
> fits your use-case? And also comment about the options you find useless?

Any idea when the patch will be merged?
Comment 43 Mickael Istria CLA 2018-09-17 06:50:21 EDT
I've sent a personal email to Timo and he said he won't modify his patch because he's busy with other things.
Still, it was submitted under EPL back then. I guess we can modify his patch and then ask him to just sign the ECA and vote on the Gerrit review when we're ready to merge it.
@Bob: do you think you'll have the opportunity to process the comments I've put on the Gerrit review and submit a new patch with those fixed?
Comment 44 Mickael Istria CLA 2018-09-17 11:51:47 EDT
I'm taking this one.
I'll rework Timo's patch and push a fresher version, then ask for review and ask Timo's for IP approval.
Comment 45 Mickael Istria CLA 2018-09-17 16:20:57 EDT
Looking at all comments and all duplicate bugs, it seems like the use-case is much more precise and specific than allowing to configure the auto insertion trigger chars. The use-case is that for people who have configured more completion proposals trigger chars, they basically don't want trigger chars.
I've rephrased the bug title accordingly.
Comment 46 Mickael Istria CLA 2018-09-17 16:57:21 EDT
The issue here goes beyond just JDT and questions the relevancy of auto-activation on about any character vs completion trigger chars in general and in any editor. I think a part of the solution should be implemented in JFace for more reusability: bug 539165 should provide the behavior and API to ignore completion trigger char (it's actually almost trivial to add it in ContentAssistant and family), then JDT should reuse this API and configure its content assistant according to a preference (trivial-ish too).
Comment 47 Eclipse Genie CLA 2018-09-18 09:14:27 EDT
New Gerrit change created: https://git.eclipse.org/r/129618
Comment 48 Mickael Istria CLA 2018-10-05 07:32:24 EDT
*** Bug 534648 has been marked as a duplicate of this bug. ***
Comment 49 Mickael Istria CLA 2018-10-05 07:40:27 EDT
*** Bug 250784 has been marked as a duplicate of this bug. ***
Comment 51 Noopur Gupta CLA 2018-11-12 05:29:46 EST
(In reply to Eclipse Genie from comment #50)
> Gerrit change https://git.eclipse.org/r/129618 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=0b7dfe14f86da01c63a736d7a22858b078fe1e8c
Thanks, Mickael.

I have added a mnemonic for the new option and updated the Javadoc with:
http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=823ad86091f1dcb34ebaf38ab31c43208aff8d62

Please update the following:

- Update the F1 help document at org.eclipse.jdt.doc.user/reference/preferences/java/editor/ref-preferences-content-assist.htm.

- Add an N&N entry for 4.10.
Comment 52 Lars Vogel CLA 2018-11-12 07:19:15 EST
(In reply to Noopur Gupta from comment #51)
> - Add an N&N entry for 4.10.

Please add a link to it in this bug.
Comment 53 Eclipse Genie CLA 2018-11-12 07:43:49 EST
New Gerrit change created: https://git.eclipse.org/r/132278
Comment 54 Eclipse Genie CLA 2018-11-12 08:18:13 EST
New Gerrit change created: https://git.eclipse.org/r/132280
Comment 58 Noopur Gupta CLA 2018-11-21 04:52:47 EST
Verified as fixed in I20181120-1800.