python-lsp / python-lsp-server

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

can't autocomplete project modules from tests folder #500

Open MatrixManAtYrService opened 9 months ago

MatrixManAtYrService commented 9 months ago

Hello. I really appreciate your work on python-lsp-server, thank you.

I made a repo for this issue: https://github.com/MatrixManAtYrService/sample-repo-helix-pylsp/blob/main/README.md. The problem is described in detail in the linked README.

Summary: I can't autocomplete the package name in imports while authoring tests. I can autocomplete the package name while authoring modules in that package.

Is there some hint that I need to give python-lsp-server that will tell it to consider the contents of src as imports?

If this doesn't sound like a python-lsp-server issue to you, is there maybe a way to expose details that I might later write into an issue in the helix repo?


$ pylsp -V
pylsp v1.9.0
MatrixManAtYrService commented 9 months ago

I've discovered a workaround. I add a symlink called sample which points to src/sample

.
|-- pyproject.toml
|-- sample -> src/sample  # here
|-- src
|   `-- sample
|       |-- say_foo.py
|       `-- say_foo_loudly.py
`-- test
    `-- test_say_foo.py

Following this, sample will autocomplete in imports while editing test/test_say_foo.py. I'd like to make this work without altering my repo structure though (the rest of my team would be like :roll_eyes: ).

Ttayu commented 5 months ago

I've reproduced the same problem. This is very annoying when writing test code. The src-layout is a well-known structure in python, and pytest and others recommend it as standard. I have added the src directory to config.settings.pylsp.plugins.jedi.extra_paths, but I think this needs to be addressed on the pylsp side.