Repository: spyder-ide/spyder

Issue:
Highlighting errors and warnings wipe underlining of errors and warning.
## Problem Description

When an error or warning is highlighted in the editor, the underlining of errors and warnings are removed. They are reapplied only when a call is make to process code analysis again.

### What steps reproduce the problem?

1. Go over an error or a warning in the error and warning panel of the Editor

![underine_bug](https://user-images.githubusercontent.com/10170372/59895268-ea3ef600-93b1-11e9-885d-529fc2f8f804.gif)

The problem is with the call to `clear_extra_selections` in the `highlight_line_warning` method of the `codeeditor.py`. I do not know how this could be fixed easily.

```python
    def highlight_line_warning(self, block_data):
        return
        self.clear_extra_selections('code_analysis')
        self.__highlight_selection('code_analysis', block_data.selection,
                                   background_color=block_data.color)
        self.update_extra_selections()
        self.linenumberarea.update()
        QTimer.singleShot(
            5000, lambda: self.clear_extra_selections('code_analysis'))
```

## Versions

* Spyder 4.0.0.dev0 (Commit: ffa3deb3d) 
* Python 3.7.1 64-bit | Qt 5.9.6 | PyQt5 5.9.2 | Windows 10 



Discussion:
I think to fix that we will need to add a new key to `__highlight_selection` so to distinguidh between `code_analysis` highlight and `code_analysis` underline.
> I think to fix that we will need to add a new key to __highlight_selection so to distinguidh between code_analysis highlight and code_analysis underline.

Yes, that is the way! I have a branch with these modifications, if you are interested in this one

https://github.com/andfoy/spyder/tree/fix_warning_highlighting
@andfoy do you want to fix it since you already have a working solution? If you're busy with other things atm, I will take care of it though.
@jnsebgosselin, if you can help @andfoy with this one, it'll be highly appreciated!

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
@@ -1245,7 +1245,10 @@ def set_occurrence_timeout(self, timeout):
     def set_underline_errors_enabled(self, state):
         """Toggle the underlining of errors and warnings."""
         self.underline_errors_enabled = state
-        self.document_did_change()
+        if state:
+            self.document_did_change()
+        else:
+            self.clear_extra_selections('code_analysis_underline')
 
     def set_highlight_current_line(self, enable):
         """Enable/disable current line highlighting"""
@@ -1912,7 +1915,8 @@ def exec_gotolinedialog(self):
     def cleanup_code_analysis(self):
         """Remove all code analysis markers"""
         self.setUpdatesEnabled(False)
-        self.clear_extra_selections('code_analysis')
+        self.clear_extra_selections('code_analysis_highlight')
+        self.clear_extra_selections('code_analysis_underline')
         for data in self.blockuserdata_list():
             data.code_analysis = []
 
@@ -1965,8 +1969,11 @@ def process_code_analysis(self, results):
             block.setUserData(data)
             block.selection = QTextCursor(cursor)
             block.color = color
+
+            # Underline errors and warnings in this editor.
             if self.underline_errors_enabled:
-                self.__highlight_selection('code_analysis', block.selection,
+                self.__highlight_selection('code_analysis_underline',
+                                           block.selection,
                                            underline_color=block.color)
 
         self.sig_process_code_analysis.emit()
@@ -1986,6 +1993,7 @@ def hide_tooltip(self):
         """
         self._last_hover_word = None
         self.tooltip_widget.hide()
+        self.clear_extra_selections('code_analysis_highlight')
 
     def show_code_analysis_results(self, line_number, block_data):
         """Show warning/error messages."""
@@ -2039,13 +2047,13 @@ def show_code_analysis_results(self, line_number, block_data):
             self.highlight_line_warning(block_data)
 
     def highlight_line_warning(self, block_data):
-        self.clear_extra_selections('code_analysis')
-        self.__highlight_selection('code_analysis', block_data.selection,
+        """Highlight errors and warnings in this editor."""
+        self.clear_extra_selections('code_analysis_highlight')
+        self.__highlight_selection('code_analysis_highlight',
+                                   block_data.selection,
                                    background_color=block_data.color)
         self.update_extra_selections()
         self.linenumberarea.update()
-        QTimer.singleShot(
-            5000, lambda: self.clear_extra_selections('code_analysis'))
 
     def get_current_warnings(self):
         """


Test patch: