Skip to content

configuration: how to #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
humanitiesNerd opened this issue Jan 25, 2022 · 7 comments
Open

configuration: how to #156

humanitiesNerd opened this issue Jan 25, 2022 · 7 comments

Comments

@humanitiesNerd
Copy link

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
Copy link
Contributor

haplo commented Jan 26, 2022

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

humanitiesNerd commented Feb 14, 2022

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
Copy link
Author

I think this is related to #157

@DevJac
Copy link

DevJac commented Apr 14, 2022

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. 🤷 )

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
Copy link
Contributor

doolio commented Nov 7, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants