Repository: spyder-ide/spyder

Issue:
Error in cv2 autocompletion
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

This error pops up when using autocompletion in opencv.
It can be reproduced by typing 

```
import cv2
cv2.<autocomplete>
```

### Traceback
```python-traceback
  File "/usr/local/lib/python3.6/dist-packages/spyder/plugins/editor/widgets/codeeditor.py", line 1086, in process_completion
    completion_list = sorted(completions, key=sort_key)
  File "/usr/local/lib/python3.6/dist-packages/spyder/plugins/editor/widgets/codeeditor.py", line 1077, in sort_key
    first_insert_letter = completion['insertText'][0]
IndexError: string index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/logging/__init__.py", line 994, in emit
    msg = self.format(record)
  File "/usr/lib/python3.6/logging/__init__.py", line 840, in format
    return fmt.format(record)
  File "/usr/lib/python3.6/logging/__init__.py", line 577, in format
    record.message = record.getMessage()
  File "/usr/lib/python3.6/logging/__init__.py", line 338, in getMessage
    msg = msg % self.args
ValueError: incomplete format
Call stack:
  File "/usr/local/bin/spyder3", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/dist-packages/spyder/app/start.py", line 195, in main
    mainwindow.main()
  File "/usr/local/lib/python3.6/dist-packages/spyder/app/mainwindow.py", line 3646, in main
    mainwindow = run_spyder(app, options, args)
  File "/usr/local/lib/python3.6/dist-packages/spyder/app/mainwindow.py", line 3529, in run_spyder
    app.exec_()
  File "/usr/local/lib/python3.6/dist-packages/spyder/plugins/completion/languageserver/client.py", line 343, in on_msg_received
    handler(resp['result'], req_id)
  File "/usr/local/lib/python3.6/dist-packages/spyder/plugins/completion/languageserver/providers/document.py", line 109, in process_document_completion
    LSPRequestTypes.DOCUMENT_COMPLETION, {'params': response})
  File "/usr/local/lib/python3.6/dist-packages/spyder/plugins/completion/languageserver/plugin.py", line 279, in receive_response
    self.COMPLETION_CLIENT_NAME, req_id, response)
  File "/usr/local/lib/python3.6/dist-packages/spyder/plugins/completion/plugin.py", line 138, in receive_response
    self.gather_and_send(request_responses)
  File "/usr/local/lib/python3.6/dist-packages/spyder/plugins/completion/plugin.py", line 189, in gather_and_send
    response_instance.handle_response(req_type, responses)
  File "/usr/local/lib/python3.6/dist-packages/spyder/plugins/editor/widgets/codeeditor.py", line 915, in handle_response
    handler(params)
  File "/usr/local/lib/python3.6/dist-packages/spyder/plugins/editor/widgets/codeeditor.py", line 1098, in process_completion
    self.log_lsp_handle_errors('Error when processing completions')
  File "/usr/local/lib/python3.6/dist-packages/spyder/plugins/editor/widgets/codeeditor.py", line 946, in log_lsp_handle_errors
    logger.error('%', 1, stack_info=True)
Message: '%'
Arguments: (1,)
```

## Versions

* Spyder version: 4.0.0b7 
* Python version: 3.6.8
* Qt version: 5.12.4
* PyQt5 version: 5.12.3
* Operating System: Linux 5.0.0-23-generic

### Dependencies

```
cloudpickle >=0.5.0          :  1.2.1 (OK)
pygments >=2.0               :  2.4.2 (OK)
qtconsole >=4.5.5            :  4.5.5 (OK)
nbconvert >=4.0              :  5.6.0 (OK)
sphinx >=0.6.6               :  2.1.2 (OK)
pylint >=0.25                :  2.3.1 (OK)
psutil >=0.3                 :  5.6.3 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
zmq >=17                     :  18.1.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
numpydoc >=0.6.0             :  0.9.1 (OK)
spyder_kernels >=1.5.0;<2.0.0:  1.6.0 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
atomicwrites >=1.2.0         :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
watchdog                     :  None (OK)
keyring                      :  10.6.0 (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pympler                      :  None (OK)
sympy >=0.7.3                :  1.4 (OK)
cython >=0.21                :  None (NOK)
IPython >=4.0                :  7.7.0 (OK)
matplotlib >=2.0.0           :  3.1.1 (OK)
pandas >=0.13.1              :  0.25.1 (OK)
numpy >=1.7                  :  1.17.1 (OK)
scipy >=0.17.0               :  1.3.1 (OK)
pyls >=0.28.2;<0.29.0        :  0.28.3 (OK)
xdg >=0.26                   :  0.26 (OK)
```



Discussion:
@dalthviz, please take a look at this one.

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
@@ -1069,7 +1069,9 @@ def process_completion(self, params):
         position, automatic = args
         try:
             completions = params['params']
-            completions = [] if completions is None else completions
+            completions = ([] if completions is None else
+                           [completion for completion in completions
+                            if completion['insertText']])
 
             replace_end = self.textCursor().position()
             under_cursor = self.get_current_word_and_position(completion=True)


Test patch: