Repository: spyder-ide/spyder

Issue:
Reconnect warning menu with PyLS output
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

## Problem Description
Reconnect the following options to the PyLS output:

1.  Show warning/error list
2. Previous warning/error
3.  Next warning/error


### What steps reproduce the problem?

1. Open a file
2. Source > Show warning/error list doesn't do anything
3. Source > Previous warning/error doesn't do anything
4. Source > Next warning/error doesn't do anything

![image](https://user-images.githubusercontent.com/20992645/54658395-39b41400-4a9b-11e9-952a-df44702d2575.png)

### What is the expected output? What do you see instead?
Given the output of PyLS, get a list of entries for the three options stated above as in spyder 3

![image](https://user-images.githubusercontent.com/20992645/54658616-556bea00-4a9c-11e9-85b5-396fadd40189.png)

When an entry is clicked, the cursor in the editor should move to the position when the error is given.

## 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: Spyder 4.0.0.dev0
* Python version: 3.6.8 64-bit
* Qt version: 5.9.6
* PyQt version: PyQt5 5.9.2
* Operating System name/version: Darwin 18.2.0 

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
pygments >=2.0    :  2.3.1 (OK)
qdarkstyle >=2.6.4:  2.6.5 (OK)
sphinx >=0.6.6    :  1.8.2 (OK)
psutil >=0.3      :  5.4.8 (OK)
pyls >=0.19.0     :  0.25.0 (OK)
nbconvert >=4.0   :  5.4.0 (OK)
pandas >=0.13.1   :  None (NOK)
numpy >=1.7       :  None (NOK)
sympy >=0.7.3     :  None (NOK)
cython >=0.21     :  None (NOK)
qtconsole >=4.2.0 :  4.4.3 (OK)
IPython >=4.0     :  7.2.0 (OK)
matplotlib >=2.0.0:  None (NOK)
pylint >=0.25     :  2.2.2 (OK)
```



Discussion:

Resolving patch:
diff --git a/spyder/plugins/editor/plugin.py b/spyder/plugins/editor/plugin.py
--- a/spyder/plugins/editor/plugin.py
+++ b/spyder/plugins/editor/plugin.py
@@ -1379,9 +1379,8 @@ def refresh_save_all_action(self):
 
     def update_warning_menu(self):
         """Update warning list menu"""
-        # TODO: COnnect this to the LSP!
-        editorstack = self.get_current_editorstack()
-        check_results = [] #editorstack.get_analysis_results()
+        editor = self.get_current_editorstack().get_current_editor()
+        check_results = editor.get_current_warnings()
         self.warning_menu.clear()
         filename = self.get_current_filename()
         for message, line_number in check_results:
@@ -1466,10 +1465,8 @@ def opened_files_list_changed(self):
             self.open_file_update.emit(self.get_current_filename())
 
     def update_code_analysis_actions(self):
-        # TODO: Connect this to the LSP!
-        editorstack = self.get_current_editorstack()
-        results = None #editorstack.get_analysis_results()
-
+        editor = self.get_current_editorstack().get_current_editor()
+        results = editor.get_current_warnings()
         # Update code analysis buttons
         state = (self.get_option('code_analysis/pyflakes') \
                  or self.get_option('code_analysis/pep8')) \
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
@@ -1663,6 +1663,24 @@ def highlight_line_warning(self, block_data):
         QTimer.singleShot(
             5000, lambda: self.clear_extra_selections('code_analysis'))
 
+    def get_current_warnings(self):
+        """
+        Get all warnings for the current editor and return
+        a list with the message and line number.
+        """
+        block = self.document().firstBlock()
+        line_count = self.document().blockCount()
+        warnings = []
+        while True:
+            if block.blockNumber() + 1 == line_count:
+                break
+            data = block.userData()
+            if data and data.code_analysis:
+                for warning in data.code_analysis:
+                    warnings.append([warning[-1], block.blockNumber()])
+            block = block.next()
+        return warnings
+
     def go_to_next_warning(self):
         """Go to next code analysis warning message
         and return new cursor position"""


Test patch:
diff --git a/spyder/plugins/editor/widgets/tests/test_warnings.py b/spyder/plugins/editor/widgets/tests/test_warnings.py
--- a/spyder/plugins/editor/widgets/tests/test_warnings.py
+++ b/spyder/plugins/editor/widgets/tests/test_warnings.py
@@ -125,3 +125,18 @@ def test_move_warnings(qtbot, construct_editor):
     editor.go_to_previous_warning()
     assert 5 == editor.get_cursor_line_number()
     lsp_manager.close_client('python')
+
+
+@pytest.mark.skipif(os.name == 'nt' and os.environ.get('CI') is not None,
+                    reason="Times out on AppVeyor")
+def test_menu_show_warnings(qtbot, construct_editor):
+    editor, lsp_manager = construct_editor
+
+    # Get current warnings
+    warnings = editor.get_current_warnings()
+
+    expected = [['W293 blank line contains whitespace', 1],
+                ['E261 at least two spaces before inline comment', 2],
+                ["undefined name 's'", 4]]
+
+    assert warnings == expected