Repository: spyder-ide/spyder

Issue:
Disable pyls-flake8 in PyLSP configuration
<!--- **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``
    * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [ ] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below

## Problem Description

When I have code style linting turned on and increase the line length, this information is not passed on to flake8 if `pyls-flake8` is installed.  And if code style linting is turned off, flake8 still reports issues.  This may well also apply to other pyls plugins.

### What steps reproduce the problem?

1. Start with a clean install of spyder (I used a venv and ran `spyder --reset`).
2. Install `pyls-flake8`
3. Open a file with some lines between 80 and 88 characters long.
4. Leave  "Enable code style linting" off in the preferences; flake8 still flags issues.
5. Switch "Enable code style linting" on in the preferences.  Then both pycodestyle and flake8 report overly long lines.
6. Set the maximum allowed line length to 88.  Then pycodestyle stops issuing warnings but flake8 still does.

### What is the expected output? What do you see instead?

This is what is seen with line length 79, no linting:
![Screenshot_spyder-nolinting](https://user-images.githubusercontent.com/1658936/163863864-445f19e6-9a44-42a6-839b-efe5d5e5d57e.png)

This is what is seen with line length 79, linting:
![Screenshot_spyder-79](https://user-images.githubusercontent.com/1658936/163863851-a523f152-b3d4-4afd-b0ee-99287447dbc3.png)

This is what is seen with line length 88, linting:
![Screenshot_spyder-88](https://user-images.githubusercontent.com/1658936/163863853-90b34cb4-a7de-4fc9-9bb8-fd63fcb41f70.png)

## 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.3.0 None
* Python version: 3.9.12 64-bit
* Qt version: 5.15.2
* PyQt5 version: 5.15.6
* Operating System: Linux 5.16.0-6-amd64

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  2.0.0 (OK)
cookiecutter >=1.6.0          :  1.7.3 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.31.1;<8.0.0       :  7.32.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.1 (OK)
jellyfish >=0.7               :  0.9.0 (OK)
jsonschema >=3.2.0            :  4.4.0 (OK)
keyring >=17.0.0              :  23.5.0 (OK)
nbconvert >=4.0               :  6.5.0 (OK)
numpydoc >=0.6.0              :  1.2.1 (OK)
parso >=0.7.0;<0.9.0          :  0.8.3 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.9.0 (OK)
pygments >=2.0                :  2.11.2 (OK)
pylint >=2.5.0                :  2.13.5 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.4.1;<1.5.0          :  1.4.1 (OK)
pylsp_black >=1.2.0           :  1.2.1 (OK)
qdarkstyle >=3.0.2;<3.1.0     :  3.0.3 (OK)
qstylizer >=0.1.10            :  0.2.1 (OK)
qtawesome >=1.0.2             :  1.1.1 (OK)
qtconsole >=5.3.0;<5.4.0      :  5.3.0 (OK)
qtpy >=2.0.1                  :  2.0.1 (OK)
rtree >=0.9.7                 :  1.0.0 (OK)
setuptools >=49.6.0           :  59.6.0 (OK)
sphinx >=0.6.6                :  4.5.0 (OK)
spyder_kernels >=2.3.0;<2.4.0 :  2.3.0 (OK)
textdistance >=4.2.0          :  4.2.2 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.7 (OK)
xdg >=0.26                    :  0.27 (OK)
zmq >=17                      :  22.3.0 (OK)

# Optional:
cython >=0.21                 :  None (NOK)
matplotlib >=3.0.0            :  None (NOK)
numpy >=1.7                   :  None (NOK)
pandas >=1.1.1                :  None (NOK)
scipy >=0.17.0                :  None (NOK)
sympy >=0.7.3                 :  None (NOK)
```



Discussion:
Hi @juliangilbey thank for the feedback! I think the config setup is done at https://github.com/spyder-ide/spyder/blob/715973319f0c4b69b196812c5ce6bec9b333a9cb/spyder/plugins/completion/providers/languageserver/provider.py#L702-L707

So most probably adding a entry for `pyls-flake8` there and setting the proper config key to be equal to https://github.com/spyder-ide/spyder/blob/715973319f0c4b69b196812c5ce6bec9b333a9cb/spyder/plugins/completion/providers/languageserver/provider.py#L719

should help. So basically for the moment you will need to use a `.flake8` file to config `pyslp-flake8` I think.

Edit: What do you think @ccordoba12 should we add configs for third-party pylsp plugins from Spyder or maybe add a way to do so from the preferences?
Hey @juliangilbey, thanks for reporting. Two things about this:

* We don't offer control over most third party PyLSP plugins, like `pyls-flake8` or `pylsp-mypy` (we only do for `pylsp-black` and `pyls-spyder`). This means that you need to configure them by yourself, i.e. like @dalthviz just said.
* As far as I know, the `pyls-flake8` functionality is already implemented in the `flake8` PyLSP internal plugin. But we don't use flake8 for linting at the moment (we plan to do it at some point in the future though).

So, the bottom line is: if you want to use `pyls-flake8` with Spyder, you need to configure it manually. And for now we wouldn't recommend installing both packages because most people don't know how to do that.
Given that we already have issue #16249 for flake8 support, I think the best we can do to solve this one is to disable `pyls-flake8` in the configuration we send to the server from Spyder. That way users wouldn't be caught by the problems reported here.

@dalthviz, what do you think?
If that is enough to deactivate it I guess is okay. If that is the approach to take then I would suggest also to add some sort of documentation regarding which pyslp plugins are available to config from Spyder and how to work with/config third-party plugins as @juliangilbey was doing (at least an explanation saying that you will need to check the third-party plugin handling of config by config files or other ways outside Spyder).
> Hey @juliangilbey, thanks for reporting. Two things about this:
> 
>     * We don't offer control over most third party PyLSP plugins, like `pyls-flake8` or `pylsp-mypy` (we only do for `pylsp-black` and `pyls-spyder`). This means that you need to configure them by yourself, i.e. like @dalthviz just said.
> 
>     * As far as I know, the `pyls-flake8` functionality is already implemented in the `flake8` PyLSP internal plugin. But we don't use flake8 for linting at the moment (we plan to do it at some point in the future though).
> 
> 
> So, the bottom line is: if you want to use `pyls-flake8` with Spyder, you need to configure it manually. And for now we wouldn't recommend installing both packages because most people don't know how to do that.

OK, thanks! And taking this point further: now that PyLSP supports flake8 internally, would it make sense to stop advertising the `pyls-flake8` plugin on the PyLSP page?  I am quite confused by the overlap, for obvious reasons!

Resolving patch:
diff --git a/spyder/config/lsp.py b/spyder/config/lsp.py
--- a/spyder/config/lsp.py
+++ b/spyder/config/lsp.py
@@ -120,11 +120,14 @@
                     'args': []
                 },
                 'flake8': {
-                     'enabled': False,
+                    'enabled': False,
                 },
                 'pyls_spyder': {
                     'enable_block_comments': True,
                     'group_cells': True
+                },
+                'pyls_flake8': {
+                    'enabled': False,
                 }
             },
 


Test patch: