Repository: spyder-ide/spyder

Issue:
Auto-completion should not complete already complete words
## Problem Description
Auto-completion (without kite, maybe also with, but I didn't test) propose to complete already complete words.

### What steps reproduce the problem?
Use LSP auto-completion (not tested with kite).

Write
```
something = 1
something
```
and wait. Auto-completion propose `something`

### What is the expected output? What do you see instead?
I would expect auto-completion to disappear when I write entirely what I wanted to.
It's not a major bug, but quite annoying.

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 4.0.1
* Python version: 3.7.6
* Jedi version: 0.14.1
*  python-language-server version: 0.31.8



Discussion:
@andfoy, please take a look at this one.
If the prefix matches something on the retuned completion options, do not show it.
I think in the ideal case I would expect something a little more complicated (but faster to run):
1. if there is only one possible completion and it matches the prefix, I expect the completion to be hidden (or closed)(see example in first comment);
2. if several completions are possible, I expect in this case to propose completion for the already complete word (as it work now).

The example bellow should make things clearer for the 2.:
```python
some = 1
something = 2
some
```
In that case I expect completion to propose `some` and `something` so that user can know `some` is a possible choice (showing only `something` would be confusing).

Resolving patch:
diff --git a/spyder/plugins/editor/widgets/codeeditor.py b/spyder/plugins/editor/widgets/codeeditor.py
--- a/spyder/plugins/editor/widgets/codeeditor.py
+++ b/spyder/plugins/editor/widgets/codeeditor.py
@@ -1135,9 +1135,10 @@ def process_completion(self, params):
         position, automatic = args
         try:
             completions = params['params']
+            prefix = self.get_current_word()
             completions = ([] if completions is None else
                            [completion for completion in completions
-                            if completion.get('insertText')
+                            if completion.get('insertText') != prefix
                             or completion.get('textEdit', {}).get('newText')])
 
             replace_end = self.textCursor().position()


Test patch:
diff --git a/spyder/plugins/editor/widgets/tests/test_introspection.py b/spyder/plugins/editor/widgets/tests/test_introspection.py
--- a/spyder/plugins/editor/widgets/tests/test_introspection.py
+++ b/spyder/plugins/editor/widgets/tests/test_introspection.py
@@ -403,11 +403,6 @@ def test_completions(lsp_codeeditor, qtbot):
                           timeout=10000) as sig:
         qtbot.keyPress(code_editor, Qt.Key_Tab)
 
-    qtbot.keyPress(code_editor, Qt.Key_Escape)
-
-    with qtbot.waitSignal(completion.sig_show_completions,
-                          timeout=10000) as sig:
-        qtbot.keyPress(code_editor, Qt.Key_Tab)
     if PY2:
         assert "hypot(x, y)" in [x['label'] for x in sig.args[0]]
     else:
@@ -416,6 +411,20 @@ def test_completions(lsp_codeeditor, qtbot):
 
     assert code_editor.toPlainText() == 'import math\nmath.hypot'
 
+    qtbot.keyPress(code_editor, Qt.Key_Escape)
+
+    try:
+        with qtbot.waitSignal(completion.sig_show_completions,
+                              timeout=10000) as sig:
+            qtbot.keyPress(code_editor, Qt.Key_Tab)
+    except pytestqt.exceptions.TimeoutError:
+        # This should generate a timeout error because the completion
+        # prefix is the same that the completions returned by Jedi.
+        # This is a regression test for spyder-ide/spyder#11600
+        pass
+
+
+
     # enter for new line
     qtbot.keyPress(code_editor, Qt.Key_Enter, delay=300)