Repository: spyder-ide/spyder

Issue:
Close brackets or close quotes doesn't update the LSP
<!--- **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! --->

### Issue Report Checklist

* [X] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [X] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [X] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [ ] Tried basic troubleshooting (if a bug/error)
    * [ ] Restarted Spyder
    * [ ] Reset preferences with ``spyder --reset``
    * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [ ] Tried the other applicable steps from the Troubleshooting Guide
* [ ] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description

Adding brackets or quotes with close_brackets or close_quotes enabled doesn't update the code error checking
`print("sweet)`

### What steps reproduce the problem?

1. `print("sweet)` gives error EOL sting literal error
2. type a quote to make `print("sweet")`
3. The error stays

### What is the expected output? What do you see instead?

No errors!

### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback

PASTE TRACEBACK HERE

```

## 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: master
* Python version: 3.6
* Qt version: 
* PyQt version: 
* Operating System name/version: Linux

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
PASTE DEPENDENCIES HERE
```



Discussion:
PR on the way!

Resolving patch:
diff --git a/spyder/plugins/editor/extensions/closebrackets.py b/spyder/plugins/editor/extensions/closebrackets.py
--- a/spyder/plugins/editor/extensions/closebrackets.py
+++ b/spyder/plugins/editor/extensions/closebrackets.py
@@ -39,6 +39,7 @@ def _on_key_pressed(self, event):
         if key in self.BRACKETS_CHAR and self.enabled:
             self.editor.completion_widget.hide()
             self._autoinsert_brackets(key)
+            self.editor.document_did_change()
             event.accept()
 
     def unmatched_brackets_in_line(self, text, closing_brackets_type=None):
diff --git a/spyder/plugins/editor/extensions/closequotes.py b/spyder/plugins/editor/extensions/closequotes.py
--- a/spyder/plugins/editor/extensions/closequotes.py
+++ b/spyder/plugins/editor/extensions/closequotes.py
@@ -56,6 +56,7 @@ def _on_key_pressed(self, event):
         if key in (Qt.Key_QuoteDbl, Qt.Key_Apostrophe) and self.enabled:
             self.editor.completion_widget.hide()
             self._autoinsert_quotes(key)
+            self.editor.document_did_change()
             event.accept()
 
     def _autoinsert_quotes(self, key):


Test patch:
diff --git a/spyder/plugins/editor/widgets/tests/fixtures.py b/spyder/plugins/editor/widgets/tests/fixtures.py
--- a/spyder/plugins/editor/widgets/tests/fixtures.py
+++ b/spyder/plugins/editor/widgets/tests/fixtures.py
@@ -51,6 +51,8 @@ def lsp_codeeditor(lsp_manager, qtbot_module, request):
     editor.setup_editor(language='Python',
                         tab_mode=False,
                         markers=True,
+                        close_quotes=True,
+                        close_parentheses=True,
                         color_scheme='spyder/dark',
                         font=QFont("Monospace", 10))
     editor.resize(640, 480)
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
@@ -11,6 +11,7 @@
 
 # Third party imports
 import pytest
+from qtpy.QtCore import Qt
 
 # Local imports
 from spyder.config.main import CONF
@@ -175,3 +176,67 @@ def test_update_warnings_after_delete_line(qtbot, lsp_codeeditor):
                 ['E261 at least two spaces before inline comment', 2],
                 ["undefined name 's'", 4]]
     assert editor.get_current_warnings() == expected
+
+
+@pytest.mark.slow
+@pytest.mark.second
+def test_update_warnings_after_closequotes(qtbot, lsp_codeeditor):
+    """
+    Test that code errors are correctly updated after activating closequotes
+    in the Editor.
+
+    Regression test for #9323.
+    """
+    editor, _ = lsp_codeeditor
+    editor.textCursor().insertText("print('test)\n")
+
+    expected = [['EOL while scanning string literal', 1]]
+
+    # Notify changes.
+    with qtbot.waitSignal(editor.lsp_response_signal, timeout=30000):
+        editor.document_did_change()
+
+    assert editor.get_current_warnings() == expected
+
+    # Wait for the lsp_response_signal.
+    with qtbot.waitSignal(editor.lsp_response_signal, timeout=30000):
+        # Add a single quote to fix the error
+        editor.move_cursor(-2)
+        qtbot.keyPress(editor, Qt.Key_Apostrophe)
+        assert editor.toPlainText() == "print('test')\n"
+
+    # Assert that the error is gone.
+    expected = [['D100: Missing docstring in public module', 1]]
+    assert editor.get_current_warnings() == expected
+
+
+@pytest.mark.slow
+@pytest.mark.second
+def test_update_warnings_after_closebrackets(qtbot, lsp_codeeditor):
+    """
+    Test that code errors are correctly updated after activating closebrackets
+    in the Editor.
+
+    Regression test for #9323.
+    """
+    editor, _ = lsp_codeeditor
+    editor.textCursor().insertText("print('test'\n")
+
+    expected = [['unexpected EOF while parsing', 1]]
+
+    # Notify changes.
+    with qtbot.waitSignal(editor.lsp_response_signal, timeout=30000):
+        editor.document_did_change()
+
+    assert editor.get_current_warnings() == expected
+
+    # Wait for the lsp_response_signal.
+    with qtbot.waitSignal(editor.lsp_response_signal, timeout=30000):
+        # Add a bracket to fix the error
+        editor.move_cursor(-1)
+        qtbot.keyPress(editor, Qt.Key_ParenRight)
+        assert editor.toPlainText() == "print('test')\n"
+
+    # Assert that the error is gone.
+    expected = [['D100: Missing docstring in public module', 1]]
+    assert editor.get_current_warnings() == expected