Repository: spyder-ide/spyder

Issue:
LSP status crashes after reset, code logic error
<!--- **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)
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [x] Reset preferences with ``spyder --reset``
    * [x] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [x] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description

LSP status crashes after resetting spyder


### What steps reproduce the problem?

1. Reset spyder
2. Click on LSP status (spinning)
3. Error message

This error stills in the master branch. I'm going to create a PR for this on 5.x. Let me know if its ok, thanks.

### What is the expected output? What do you see instead?

The test for None is done after applying string function. 


### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback

Traceback (most recent call last):
  File "../site-packages/spyder/plugins/completion/providers/languageserver/widgets/status.py", line 70, in show_menu
    language = self.current_language.lower()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'lower'
```

## 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: 5.4.3  (conda)
* Python version: 3.11.4 64-bit
* Qt version: 5.15.2
* PyQt5 version: 5.15.9
* Operating System: Linux 5.19.0-46-generic


### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
PASTE DEPENDENCIES HERE
```

LSP status crashes after reset, code logic error
<!--- **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)
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [x] Reset preferences with ``spyder --reset``
    * [x] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [x] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description

LSP status crashes after resetting spyder


### What steps reproduce the problem?

1. Reset spyder
2. Click on LSP status (spinning)
3. Error message

This error stills in the master branch. I'm going to create a PR for this on 5.x. Let me know if its ok, thanks.

### What is the expected output? What do you see instead?

The test for None is done after applying string function. 


### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback

Traceback (most recent call last):
  File "../site-packages/spyder/plugins/completion/providers/languageserver/widgets/status.py", line 70, in show_menu
    language = self.current_language.lower()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'lower'
```

## 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: 5.4.3  (conda)
* Python version: 3.11.4 64-bit
* Qt version: 5.15.2
* PyQt5 version: 5.15.9
* Operating System: Linux 5.19.0-46-generic


### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
PASTE DEPENDENCIES HERE
```



Discussion:

Resolving patch:
diff --git a/spyder/plugins/completion/providers/languageserver/widgets/status.py b/spyder/plugins/completion/providers/languageserver/widgets/status.py
--- a/spyder/plugins/completion/providers/languageserver/widgets/status.py
+++ b/spyder/plugins/completion/providers/languageserver/widgets/status.py
@@ -66,25 +66,27 @@ def __init__(self, parent, provider):
 
     def show_menu(self):
         """Display a menu when clicking on the widget."""
+        
+        if self.current_language is None:
+            return
+
         menu = self.menu
         language = self.current_language.lower()
-
-        if language is not None:
-            menu.clear()
-            text = _(
-                "Restart {} Language Server").format(language.capitalize())
-            restart_action = create_action(
-                self,
-                text=text,
-                triggered=lambda: self.provider.restart_lsp(language,
-                                                            force=True),
-            )
-            add_actions(menu, [restart_action])
-            rect = self.contentsRect()
-            os_height = 7 if os.name == 'nt' else 12
-            pos = self.mapToGlobal(
-                rect.topLeft() + QPoint(-40, -rect.height() - os_height))
-            menu.popup(pos)
+        menu.clear()
+        text = _(
+            "Restart {} Language Server").format(language.capitalize())
+        restart_action = create_action(
+            self,
+            text=text,
+            triggered=lambda: self.provider.restart_lsp(language,
+                                                        force=True),
+        )
+        add_actions(menu, [restart_action])
+        rect = self.contentsRect()
+        os_height = 7 if os.name == 'nt' else 12
+        pos = self.mapToGlobal(
+            rect.topLeft() + QPoint(-40, -rect.height() - os_height))
+        menu.popup(pos)
 
     def set_status(self, lsp_language=None, status=None):
         """Set LSP status."""


Test patch: