python-lsp / python-lsp-server

Fork of the python-language-server project, maintained by the Spyder IDE team and the community
MIT License
1.82k stars 192 forks source link

configuration: how to #156

Open humanitiesNerd opened 2 years ago

humanitiesNerd commented 2 years ago

How do I write a configuration file that is local to a project ?

The home page says that Pylsp follows this order

  1. a conf in the user home folder
  2. supeseded by a configuration passed in by the lsp client
  3. superseded by a configuration local to the workspace

How do I get a workspace local configuration file ?

Thanks

haplo commented 2 years ago

I think this issue highlights a point where python-lsp-server's documentation is lacking, I would like to see it addressed by improving it.

Part of the problem is that the LSP server configuration is passed in different ways depending on the client (e.g. Emacs, Vim, VSCode...). Still it would be useful to either point to the popular clients' documentation in this regard or even to put some examples in python-lsp-server's documentation so users have at least a starting point.

About overriding config per workspace, that is also client-specific. For Emacs I think it's doable with dir_locals.el. Again it would be useful to have either examples or links to clients' documentation.

humanitiesNerd commented 2 years ago

I came up with this dir_locals.el in my project root, but it seems it doesn't work

   (
      (lsp-mode . ((lsp-clients-pylsp-library-directories . '("contrib" "odoo"))))
      )

or maybe it DOES work and I'm misinterpreting what I see

Here it says that the type of lsp-clients-pylsp-library-directories is (repat string)

I assumed it's a list of strings but I'm not sure

I'm not well versed in Elisp

How do I express a repeat string ?

humanitiesNerd commented 2 years ago

I say it seems it's not working becaue if I call lsp-find-definition on the "many2one method (from Odoo) it says "not found"

So I guess it's not working

humanitiesNerd commented 2 years ago

I think I achieved a bit of progress thanks to this answer

but it still doesn't work

at this point, I think it's more about pypls than it is about lsp-mode

This is my project root layout

$ tree -L 2
.
├── contrib
│   ├── l10n-italy
│   └── OCA
├── dir_locals.el
├── filestore
├── local
│   └── my-project
├── logs
├── poetry.lock
├── pyproject.toml
├── my-project.cfg
├── src
│   └── odoo
└── stubs
    └── odoo
humanitiesNerd commented 2 years ago

I think this is related to #157

DevJac commented 2 years ago

I've spend awhile trying to figure this out. I'm using Emacs with lsp-mode, and I hope this will be applicable to others.

I wanted to ignore a D100 error, so I tried putting it in .flake8, .flake8rc, .pylintrc, etc. Nothing was working. Eventually I found that is has to go in .pydocstyle. (I'd never even heard of pydocstyle before. :shrug: )

As best I can tell, pylsp is using several different checking / linting packages and it can be tricky to figure out where a specific error came from. When it seems your config is being ignored, maybe it's because you're configuring the wrong package.

I eventually put something like the following in setup.cfg at the root of my project and it seems to be working well:

[pydocstyle]
ignore = D100

[flake8]
ignore = F401

There's flake8, pydocstyle, pycodestyle, pylint and maybe others. Try them on the command line to figure them out and track down where specific errors or warnings are coming from, and remember you'll have to configure all of them.

doolio commented 1 year ago

@humanitiesNerd

dir_locals.el

This should be .dir-locals.el.

In any case, I added a complete .dir-locals.el for the pylsp server here. It applies to the Eglot LSP client rather than lsp-mode but it may be a good starting point for you.