Bug 316894

Summary: Code completion erases following word
Product: [Developer tools] kdev-python Reporter: Todd <toddrme2178>
Component: Code completionAssignee: Sven Brauch <mail>
Status: CONFIRMED ---    
Severity: wishlist CC: antonis+kdebugs, aspotashev
Priority: NOR    
Version: 1.4.0 / 1.4.1 (stable)   
Target Milestone: 1.4.0   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:

Description Todd 2013-03-17 10:21:33 UTC
Whenever autocomplete actives, it erases all characters after the current character.

Reproducible: Always

Steps to Reproduce:
1.  Open a python document
2. Type "list()"
3. Put the cursor before the "l"
4. Type "di"
5. Select the "dict" entry from the autocomplete list
Actual Results:  
you get "dict|()"  (the | indicates the position of the cursor)

Expected Results:  
you get "dict|list()"  (the | indicates the position of the cursor)

The example is artificial.  To see why this is a problem, consider the case where you want to change position arguments for a function to keyword arguments.

You have a function like this: 

def myFunc(spam=None, eggs=None):

Being used like so:

a = myFunc(spam1, eggs1)

You want to change it to use keyword arguments, like so:

a = myFunc(spam=spam1, eggs=eggs1)

But if you use code completion to try to add "spam=" and "eggs=" before "spam1" and "eggs1", it will erase the "spam1" and "eggs1" text.  You will end up with:

a = myFunc(spam, eggs)
Comment 1 Sven Brauch 2013-03-17 12:51:02 UTC
This is a difficult one, since how it currently is is not good, but if you change it to always insert text it won't be good either...
For example, assume it always inserted the text, and you wanted to
* change the object a method is called on
* change the method that is being called
* change the key of a named argument
then it will go wrong too. Thus, I will not simply change it from "replace" to "insert" since it's just a personal preference which one is more annoying.

What C++ does, and what I will now do too, is making it so that the text is inserted and deleted in two steps, so you can press Ctrl+Z once after you triggered the completion to get the deleted text back. That's not a clean solution of course. In general I'd be for having another shortcut for using autocompletion, e.g. Shift+Enter, which inserts the text, and have Enter always replace it.

As another workaround you can insert a space character behind the text you're typing to prevent text replacenemnt.
Comment 2 Todd 2013-03-17 14:35:41 UTC
It is already pretty easy to replace.  Just double-click on the text before you start type, or you can hit ctrl+delete or ctrl+backspace.  

In pretty much every context, adding text adds text, rather than overwriting.  We have an insert key to switch between insert/overwrite mode, but it always defaults to insert.  I think that is because destructive actions are inherently dangerous, so it is safer to default to a non-destructive behavior.  

This is the only case I can think of where the default behavior is destructive, and you have to take extra steps to make it non-destructive.  All the other cases I can think of it is the other way around.  

And there isn't any warning that it is destructive, either.  There have been a number of cases personally where I have forgotten that it works like this, tried to run my code and realized that parts were missing because they had been deleted without me realizing it.
Comment 3 Sven Brauch 2013-03-17 16:46:32 UTC
Git commit f3d15c67c26fbabae40e2feeaf1b7069d866f03f by Sven Brauch.
Committed on 17/03/2013 at 17:34.
Pushed by brauch into branch 'master'.

Fix a performance issue with multiple calls in a chain

see unit test from previous commit for an example.
The cause for the issue was calling the parent visitor in the Expression
Visitor *plus* creating an extra expression visitor. Creating the
extra visitor is bad enough (n**2 compexity) but additionally calling
AstDefaultVisitor::visit... will blow it up to exp(n).

M  +1    -3    duchain/expressionvisitor.cpp

http://commits.kde.org/kdev-python/f3d15c67c26fbabae40e2feeaf1b7069d866f03f
Comment 4 Sven Brauch 2013-03-17 18:19:24 UTC
Huh. Wrong bug ID. Sorry.
Comment 5 Sven Brauch 2013-03-20 09:39:31 UTC
I'm really unsure about this. I'll look into whether we can add an extra shortcut to let the user decide what to do, but that'll require modifying the kate api, which will take time.
Comment 6 Christoph Feck 2013-04-24 08:57:50 UTC
Try Text Editor Settings > Editing > Auto Completion > Remove tail on complete.