Closed zbelial closed 1 month ago
Yes, the pyright-langserver will read the pyrightconfig.json or pyproject.toml automatically. It looks in the project root directory passed to the language server. This is assumed to be passed to the language server in the initialization command (in the rootPath
field). The language server also supports workspaces, and a different root directory can be passed for each workspace. In that case, a separate instance of the type checker is instantiated for each workspace.
Hi @erictraut , thanks very for this quick reply.
So a lsp client does not have to support dynamic registretion, or server request (such as workspace/configuration
), right?
Is there any way to confirm that pyright-langserver has read the pyrightconfig.json file? Or is there any way to debug why does the pyrightconfig.json have no effect?
Following are some info about my testing project. There are too files (bs.py and pyrighgconfig.json) and a virtual env directory (.venv).
import baostock as bs
import pandas as pd
lg = bs.login()
print('login response error code: ' + lg.code)
2. a pyrightconfig.json file
```json
{
"include": [
"venv"
],
"exclude": [
"**/__pycache__"
],
"pythonVersion": "3.12",
"pythonPlatform": "Linux",
"venvPath": "/home/XXXX/tmp/venv",
"venv": ".venv"
}
baostock
and pandas
are installed in it), the tree structure of it (files and directories in deeper subdirs are not showed):
.venv
├── bin
├── include
│ └── python3.12
├── lib
│ └── python3.12
│ └── site-packages
│ ├── baostock
│ ├── baostock-0.8.9.dist-info
│ ├── dateutil
│ ├── numpy
│ ├── numpy-2.0.0.dist-info
│ ├── numpy.libs
│ ├── pandas
│ ├── pandas-2.2.2.dist-info
│ ├── pip
│ ├── pip-24.0.dist-info
│ ├── __pycache__
│ ├── python_dateutil-2.9.0.post0.dist-info
│ ├── pytz
│ ├── pytz-2024.1.dist-info
│ ├── six-1.16.0.dist-info
│ ├── tzdata
│ └── tzdata-2024.1.dist-info
└── lib64 -> lib
When I enabled my lsp client (lspce), it told that baostock and pandas could not be resolved. Any advice? Thanks.
The source code for pyright is open source. Here is the initialization callback for the language server. If you'd like to insert debug statements or connect a debugger to help you diagnose the problem, there are some instructions here. I would also normally suggest adding a "verboseOutput": true
to your config file to tell pyright to output more verbose logs, but that presupposes that pyright is able to locate and read the config file.
Converting this to a discussion since this isn't a bug report.
Hi guys, I have some questions about pyrightonfig.json and I haven't found answers in the document.
Thanks!
I ask these question because I couldn't make it work and don't know why. I created a simple project, in which I used
python -m venv
to create a virtualenv, then I created a pyrightconfig.json at the root of the project and specifiedvenvPath
andvenv
in it, but it seemed that it didn't work(It couldn't find packages installed in this virtual env).I used my own lsp client in Emacs. I can provide other info if you need. Thanks.