Code Completion Removes Characters Right of Cursor

When using code completion, the characters to the right of the cursor are removed if there is no leading space. For example, if I have:

String test = "value";
test;


If I place the cursor directly in front of the 't' in "test" and type "Sys", completion for java.lang.System appears. Hitting enter to accept this completion results in "System" appearing, but the word "test" disappears. A leading space is required to prevent the completion from swallowing "test". I thought this behavior appeared in 10.5, but checking back to 10 it happens there too. I think it has become an issue for me because the completion suggestions have improved with 10.5. Is there an option to prevent completion from swallowing what's to the right of the cursor? So that after hitting enter to accept competion in the above scenario I'm left with "Systemtest" with the cursor positioned between the letters 'm' and 't'

10 comments
Comment actions Permalink

I cannot reproduce this now. Please try 10.5.1 (http://confluence.jetbrains.net/display/IDEADEV/IDEA+10.5+EAP). If the problem persists, please provide more details: e.g. the complete class text. Is it Java? Are you sure you're using Enter and not Tab to choose the item?

0
Comment actions Permalink

Yes, this still happens on the current EAP and yes this is java. I've attached a video showing the full class and behavior to hopefully clarify (Using tab for completiong):
http://vimeo.com/25765092

0
Comment actions Permalink

Tab is replacing test for purpose, it's specifically dedicated to this. It has been so for ages. If you use Enter, you should get what you expect without replacement.

0
Comment actions Permalink

Enter inserts a line break unless you have 'Preselect the first suggestion' In Editor -> Code Completion set to some value other than 'Never'. Smart is wrong often enough that it's more problematic than helpful and I therefore use the value 'Never' because of the way it automatically chosses classes to import.

0
Comment actions Permalink

I see. That's really a problem. Tab always replaces the identifier, so it would be inconsistent not to do it with a non-focused completion list. We've tried and it felt awkward. But this leads to a crazy situation when to insert something you have to press more keys than to replace something. Unfortunately I haven't invented a solution for that conflict. Maybe you have some ideas?

0
Comment actions Permalink

This isn't a general solution, but my personal reason for turning off the preselent smart completion was imports. I didn't want to interrupt my train of thought by arrowing down and selecting the correct class - but the smart preselection chooses the selected term after hitting the space in the class name.  For example, java.util.logging.Logger is imported after typing
private static final Logger
and hitting a space, when it's the wrong choice. I realize I can exclude from auto imports, but this happens with enough classes that it was easier to turn off the smart preselection. I can't think of anywhere else smart preselection is an issue for me.

I realize it wouldn't be a general purpose to the solution you described, but giving a toggle exclude import choices from smart preselection would at least resolve the issue for me.  Thanks for your responses.

0
Comment actions Permalink

Too bad. As for the import issue, could you please provide more details on it? Which classes are suggested and how are they sorted? What are those 'enough classes' that make it hard to exclude each from completion (given you can also exclude the whole packages)?

0
Comment actions Permalink

Here are a couple examples (order that classes appear):

  • Logger:
    • java.util.logging
    • org.apache.log4j
    • org.jboss.logging
    • org.codehaus.plexus.logging.Logger
    • net.sourceforge.jtds.util.Logger
  • Date: Both java.util and java.sql used, so exclusion not viable solution
  • StringUtils:
    • dce.util
    • org.codehaus.plexus.util
    • org.apache.commons.lang
    • org.apache.tools.ant.util
    • org.codehaus.plexus.interpolation.util
    • org.apache.maven.artifact.ant.shared
    • com.sun.xml.internal.ws.util
  • Services - internal class, but if I mistype as Service instead of Services then I have a "Provider.Servie." imported from java.security.Provider. This comes up on different classes as well. Some inner class of something pulls in so a backspace no longer fixes a typo. This is probably the best example of something that exclusion can't solve.
  • Log
    • org.apache.commons.logging.Log
    • android.util.Log


Those are the examples I can bring immediately to mind, though more come up. Once you have the apache commons libraries, hibernate, a web framework, google collections, internal libraries, and a few other utility libraries in a project the shorter generic class names have a lot of overlap.

0
Comment actions Permalink

I haven't been bitten by the code completion eating the characters to the right. However, I, too have set Editor -> Code Completion set to 'Never' because the editor was selecting the wrong class and automatically adding a bad import statement.

I cited this behavior back in in http://devnet.jetbrains.net/thread/304428.

This is really too bad because the auto-completion would be nice to have if it saved more time than it costs cleaning up the bad imports.

I, for one, would be happy if auto-completion was completely disabled for imports. I'm fine with always picking the possible import classes from a list. (Maybe unique imports would be auto-completed, but even then, I'm not sure.)  I probably spend 99% of my time coding against the imported class and 1% importing it.  Giving up auto-completion for 99% of my activities to work around a problem with 1% of what I do is not a great trade-off.

jack

0
Comment actions Permalink

I was trying to understand whether it would help you if the completion suggested only the classes that are visible in the current place without having to add new imports. AFAIU Logger has little chance to be imported, so in this case there would be two alternatives:
1. Not suggesting Logger at all, so you need to type it or invoke the completion manually.
2. Suggesting it when no other imported classes match (e.g. after you've typed Logg). This is less predictable and you'll still be suggested a whole bunch of Loggers.

Just listing all the class names without adding imports is strange. One may carefully choose an Logger, then select it, and realize he has to choose it again to import. Non-friendly.

So the first solution looks like a good variant except that now to import a new class you'll have to do more keypresses.

0

Please sign in to leave a comment.