Repository: spyder-ide/spyder

Issue:
Exception while writing pyqt code
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

I wrote the following code when the exception occured:

```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Aug  2 22:45:02 2021

@author: mike
"""

from PyQt5.QtWidgets import QApplication, QWidget
import sys

app = QApplication(sys.argv)

window=QWidget()
window.sho
```
The exception occurred while I type "w" at the end of the last line.

### Traceback
```python-traceback
Traceback (most recent call last):
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 1090, in receive_response
    self.match_and_reply(req_id)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 1145, in match_and_reply
    self.skip_and_reply(req_id)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 1173, in skip_and_reply
    self.gather_and_reply(request_responses)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 1191, in gather_and_reply
    response_instance.handle_response(req_type, responses)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/editor/widgets/codeeditor.py", line 989, in handle_response
    handler(params)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/editor/widgets/codeeditor.py", line 1434, in handle_completion_item_resolution
    self.completion_widget.augment_completion_info(response['params'])
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/editor/widgets/completion.py", line 504, in augment_completion_info
    if self.current_selected_item_label == item['label']:
TypeError: list indices must be integers or slices, not str
Traceback (most recent call last):
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 1090, in receive_response
    self.match_and_reply(req_id)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 1145, in match_and_reply
    self.skip_and_reply(req_id)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 1173, in skip_and_reply
    self.gather_and_reply(request_responses)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 1191, in gather_and_reply
    response_instance.handle_response(req_type, responses)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/editor/widgets/codeeditor.py", line 989, in handle_response
    handler(params)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/editor/widgets/codeeditor.py", line 1434, in handle_completion_item_resolution
    self.completion_widget.augment_completion_info(response['params'])
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/editor/widgets/completion.py", line 504, in augment_completion_info
    if self.current_selected_item_label == item['label']:
TypeError: list indices must be integers or slices, not str
Traceback (most recent call last):
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 1090, in receive_response
    self.match_and_reply(req_id)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 1145, in match_and_reply
    self.skip_and_reply(req_id)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 1173, in skip_and_reply
    self.gather_and_reply(request_responses)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 1191, in gather_and_reply
    response_instance.handle_response(req_type, responses)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/editor/widgets/codeeditor.py", line 989, in handle_response
    handler(params)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/editor/widgets/codeeditor.py", line 1434, in handle_completion_item_resolution
    self.completion_widget.augment_completion_info(response['params'])
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/editor/widgets/completion.py", line 504, in augment_completion_info
    if self.current_selected_item_label == item['label']:
TypeError: list indices must be integers or slices, not str
Traceback (most recent call last):
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 1090, in receive_response
    self.match_and_reply(req_id)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 1145, in match_and_reply
    self.skip_and_reply(req_id)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 1173, in skip_and_reply
    self.gather_and_reply(request_responses)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 1191, in gather_and_reply
    response_instance.handle_response(req_type, responses)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/editor/widgets/codeeditor.py", line 989, in handle_response
    handler(params)
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/editor/widgets/codeeditor.py", line 1434, in handle_completion_item_resolution
    self.completion_widget.augment_completion_info(response['params'])
  File "/home/mike/.local/lib/python3.8/site-packages/spyder/plugins/editor/widgets/completion.py", line 504, in augment_completion_info
    if self.current_selected_item_label == item['label']:
TypeError: list indices must be integers or slices, not str
```

## Versions

* Spyder version: 5.1.0 
* Python version: 3.8.6
* Qt version: 5.12.10
* PyQt5 version: 5.12.3
* Operating System: Linux 5.8.0-50-generic

### Dependencies

```

# Mandatory:
atomicwrites >=1.2.0                         :  1.4.0 (OK)
chardet >=2.0.0                              :  3.0.4 (OK)
cloudpickle >=0.5.0                          :  1.6.0 (OK)
cookiecutter >=1.6.0                         :  1.7.3 (OK)
diff_match_patch >=20181111                  :  20200713 (OK)
intervaltree >=3.0.2                         :  3.1.0 (OK)
IPython >=7.6.0                              :  7.23.0 (OK)
jedi >=0.17.2;<0.19.0                        :  0.17.2 (OK)
jsonschema >=3.2.0                           :  3.2.0 (OK)
keyring >=17.0.0                             :  21.3.0 (OK)
nbconvert >=4.0                              :  6.0.7 (OK)
numpydoc >=0.6.0                             :  1.1.0 (OK)
parso >=0.7.0;<0.9.0                         :  0.7.0 (OK)
pexpect >=4.4.0                              :  4.6.0 (OK)
pickleshare >=0.4                            :  0.7.5 (OK)
psutil >=5.3                                 :  5.8.0 (OK)
pygments >=2.0                               :  2.9.0 (OK)
pylint >=2.5.0                               :  2.9.6 (OK)
pyls_spyder >=0.4.0                          :  0.4.0 (OK)
pylsp >=1.2.0;<1.3.0                         :  1.2.0 (OK)
pylsp_black >=1.0.0                          :  None (OK)
qdarkstyle =3.0.2                            :  3.0.2 (OK)
qstylizer >=0.1.10                           :  0.2.1 (OK)
qtawesome >=1.0.2                            :  1.0.3 (OK)
qtconsole >=5.1.0                            :  5.1.1 (OK)
qtpy >=1.5.0                                 :  1.9.0 (OK)
rtree >=0.9.7                                :  0.9.7 (OK)
setuptools >=49.6.0                          :  56.0.0 (OK)
sphinx >=0.6.6                               :  4.1.2 (OK)
spyder_kernels >=2.1.0;<2.2.0                :  2.1.0 (OK)
textdistance >=4.2.0                         :  4.2.1 (OK)
three_merge >=0.1.1                          :  0.1.1 (OK)
watchdog >=0.10.3                            :  1.0.2 (OK)
xdg >=0.26                                   :  0.26 (OK)
zmq >=17                                     :  22.0.3 (OK)

# Optional:
cython >=0.21                                :  None (OK)
matplotlib >=2.0.0                           :  3.4.2 (OK)
numpy >=1.7                                  :  1.21.0 (OK)
pandas >=1.1.1                               :  1.2.4 (OK)
scipy >=0.17.0                               :  1.6.3 (OK)
sympy >=0.7.3                                :  None (OK)

# Spyder plugins:
spyder.plugins.completion.plugin 5.1.0       :  5.1.0 (OK)
spyder.plugins.outlineexplorer.plugin 5.1.0  :  5.1.0 (OK)
spyder.plugins.projects.plugin 5.1.0         :  5.1.0 (OK)
spyder.plugins.variableexplorer.plugin 5.1.0 :  5.1.0 (OK)
```



Discussion:
Hey @mghansen256, thanks a lot for reporting and the reproducible use case. I was able to reproduce your error and will fix it in our next version (5.1.1), to be released shortly.

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
@@ -1431,7 +1431,20 @@ def resolve_completion_item(self, item):
 
     @handles(CompletionRequestTypes.COMPLETION_RESOLVE)
     def handle_completion_item_resolution(self, response):
-        self.completion_widget.augment_completion_info(response['params'])
+        try:
+            response = response['params']
+
+            if not response:
+                return
+
+            self.completion_widget.augment_completion_info(response)
+        except RuntimeError:
+            # This is triggered when a codeeditor instance was removed
+            # before the response can be processed.
+            return
+        except Exception:
+            self.log_lsp_handle_errors(
+                "Error when handling completion item resolution")
 
     # ------------- LSP: Signature Hints ------------------------------------
     @request(method=CompletionRequestTypes.DOCUMENT_SIGNATURE)


Test patch: