Repository navigation
Configuration examples #172
Description
Activity
As I said several times before, this is not something we can help users with here. It depends on your editor or IDE, i.e. Neovim, Emacs, Sublime, Jupyterlab-LSP, etc.
Most of them allow to set options in json format, so they are sent to the server when it starts. But how to do that, where to put those options and in what format is editor/IDE specific. And most of us here don't use any of the options I mentioned above, so we have no clue about all that.
So the appropriate place to ask for help is in your editor/IDE issue tracker or forum.
The current docs say:
configuration is loaded from zero or more configuration sources. Currently implemented are:
- pycodestyle: discovered in ~/.config/pycodestyle, setup.cfg, tox.ini and pycodestyle.cfg.
- flake8: discovered in ~/.config/flake8, setup.cfg, tox.ini and flake8.cfg
The default configuration source is pycodestyle. Change the pylsp.configurationSources setting to ['flake8'] in order to respect flake8 configuration instead.
Overall configuration is computed first from user configuration (in home directory), overridden by configuration passed in by the language client, and then overridden by configuration discovered in the workspace.
To enable pydocstyle for linting docstrings add the following setting in your LSP configuration: "pylsp.plugins.pydocstyle.enabled": true
This sounds like 3 config sources:
- user config
- "configuration passed in by the language client" i.e. sent from editor
- configuration discovered in the workspace
You are talking about number 2 here I think. I'm asking about 1 and 3. Doesn't this text mean that you can put something in the workspace to affect configuration - a e.g. a
setup.cfgfile in a folder? If not, what does it mean?I'm asking about 1 and 3
Nop, you're asking about 2 as well because neither pycodestyle, flake8 nor any other plugin can be enabled/disabled from user config files.
And this applies to issue #162 too.
Doesn't this text mean that you can put something in the workspace to affect configuration - a e.g. a setup.cfg file in a folder?
Sure, if the plugin is enabled. After that, you can configure it as you would in a regular project.
@ccordoba12 Are you able to point to any examples of adjusting the configuration in a real-project?
I appreciate that all editors do it differently, but the language server protocol a constant, and so we should be able to extrapolate.
At the moment I (and it looks like others) am struggling to get any of the 3rd Party Plugins (under the python-lsp org) listed in the README to register...
Sure, if the plugin is enabled.
I'm guessing that's my issue, but I can't get it working, and I can't find a single example to start working from.
Thanks! 🎁
Thanks so much for your reply @ccordoba12 I think I'm getting there, but I'm still quite confused.
If I understand rightly (which I'm not at all confident of), I would rewrite the Configuration section like this:
Configuration
Like all language servers, configuration can be passed from the client (i.e. the editor/IDE). The details of how this is done depend on the editor or plugin that you are using to communicate with python-lsp-server. The configuration options available are documented in CONFIGURATION.md
python-lsp-server depends on other tools, like flake8 and pycodestyle. These tools can be configured via settings passed from the client (first paragraph above), or alternatively other configuration sources. The following sources are available:
- pycodestyle: discovered in
~/.config/pycodestyle,setup.cfg,tox.iniandpycodestyle.cfg. - flake8: discovered in
~/.config/flake8,setup.cfg,tox.iniandflake8.cfg
The default configuration source is pycodestyle. Change the
pylsp.configurationSourcessetting (in the value passed in from your client) to['flake8']in order to respect flake8 configuration instead.The configuration options available in these config files (
setup.cfgetc) are documented in the relevant tools:Overall configuration is computed first from user configuration (in home directory), overridden by configuration passed in by the language client, and then overridden by configuration discovered in the workspace.
As an example, to change the list of errors that pycodestyle will ignore, assuming you are using the
pycodestyleconfiguration source (the default), you can:- Add the following to your ~/.config/pycodestyle:
[pycodestyle]
ignore = E226,E302,E41- Set the
pylsp.plugins.pycodestyle.ignoreconfig value from your editor - Same as 1, but added to
setup.cfgfile in the root of the project.
This is an attempt to make sense of this, I'm still quite fuzzy on some details, perhaps it's an improvement?
- pycodestyle: discovered in
Are you able to point to any examples of adjusting the configuration in a real-project?
See this comment for JupyterLab-LSP, although I think the
serverSettingskey is specific to that project.This is an attempt to make sense of this, I'm still quite fuzzy on some details, perhaps it's an improvement?
Yes, it is! Thanks for your suggestions @spookylukey!
Could you submit a pull request with them? Thanks!
Reacted by Carlton Gibson- added 2 commits that reference this issue
on Mar 17, 2022 Hello,
Thanks for opening this issue on this subject, I have been facing the same issue about configuring the language server. In my case, I'm using the client (monaco-languageclient). I understand that the problem might be on the client-side, but looking into the websocket event, I can't find the workspace/didChangeConfiguration being called or even set by default in the capabilities of the server (I tried to manually do that but it's not working either). Client capabilities are set correctly too, with the didChangeConfiguration dynamicRegistration set to true.
So my question is the following, is the responsibility of the language server to ask for the configuration to the client, or is it the opposite, the client is in charge of sending it during the initialization?
In my case using monaco-languageclient, the didChangeConfiguration functions are never called. I guess I will open an issue on the lib to ask about it.Another question to make it clearer for the documentation what should be the format of the configuration JSON (client side)?
{ "pylsp": { "configurationSources": ["flake8"], "plugins": { "flake8": { "enabled": true, "exclude": [], "hangClosing": false, "ignore": ["F401", "E133", "E203", "W503"], "maxLineLength": 10, "indentSize": 245, "perFileIgnores": [], "select": [] } } } }Or
{ "pylsp.configurationSources": ["flake8"], "pylsp.plugins.flake8.enabled": true, "pylsp.plugins.flake8.exclude": [], "pylsp.plugins.flake8.hangClosing": false, "pylsp.plugins.flake8.ignore": ["F401", "E133", "E203", "W503"], "pylsp.plugins.flake8.maxLineLength": 10, "pylsp.plugins.flake8.indentSize": 245, "pylsp.plugins.flake8.perFileIgnores": [], "pylsp.plugins.flake8.select": [] }I'm going to move this to our newly opened Discussions because it's not really a bug but a petition for help.
I'll post further comments there.
- locked and limited conversation to collaborators
on Mar 19, 2022
Could you expand on the configuration section with the help of examples?
For example:
"pylsp.plugins.pydocstyle.enabled": true- on a per workspace basis, or globally?Other people are also struggling with configuration e.g. #162
Thanks!