Release Notes: - Added support for pyright workspace configuration, as described in https://microsoft.github.io/pyright/#/settings .
Showing the changes to docs/src/languages/python.md (1 of 2 files). Show all
Unified · Split
| @@ -11,6 +11,35 @@ The [pyright](https://github.com/microsoft/pyright) language server offers flexi · 10 unmodified lines | ||
| 11 | 11 | |
| 12 | 12 | For more information, see the Pyright [configuration documentation](https://microsoft.github.io/pyright/#/configuration). |
| 13 | 13 | |
| 14 | +### Settings | |
| 15 | + | |
| 16 | +The [pyright](https://github.com/microsoft/pyright) language server also accepts specific LSP related settings, not necessarily connected to a project. These can be changed in the `lsp` section of your `settings.json`. | |
| 17 | + | |
| 18 | +For example, in order to: | |
| 19 | +- use strict type-checking level | |
| 20 | +- diagnose all files in the workspace instead of the only open files default | |
| 21 | +- provide the path to a specific python interpreter | |
| 22 | + | |
| 23 | +```json | |
| 24 | +{ | |
| 25 | + "lsp": { | |
| 26 | + "pyright": { | |
| 27 | + "settings": { | |
| 28 | + "python.analysis": { | |
| 29 | + "diagnosticMode": "workspace", | |
| 30 | + "typeCheckingMode": "strict" | |
| 31 | + }, | |
| 32 | + "python": { | |
| 33 | + "pythonPath": ".venv/bin/python" | |
| 34 | + } | |
| 35 | + } | |
| 36 | + } | |
| 37 | + } | |
| 38 | +} | |
| 39 | +``` | |
| 40 | + | |
| 41 | +For more information, see the Pyright [settings documentation](https://microsoft.github.io/pyright/#/settings). | |
| 42 | + | |
| 14 | 43 | ### Virtual environments |
| 15 | 44 | |
| 16 | 45 | A python [virtual environment](https://docs.python.org/3/tutorial/venv.html) allows you to store all of a project's dependencies, including the Python interpreter and package manager, in a single directory that's isolated from any other Python projects on your computer. |
| @@ -48,6 +77,22 @@ venvPath = "." · 31 unmodified lines | ||
| 48 | 77 | venv = ".venv" |
| 49 | 78 | ``` |
| 50 | 79 | |
| 80 | +You can also configure this option directly in your `settings.json` file ([pyrights settings](#settings)), as recommended in [Configuring Your Python Environment](https://microsoft.github.io/pyright/#/import-resolution?id=configuring-your-python-environment). | |
| 81 | + | |
| 82 | +```json | |
| 83 | +{ | |
| 84 | + "lsp": { | |
| 85 | + "pyright": { | |
| 86 | + "settings": { | |
| 87 | + "python": { | |
| 88 | + "pythonPath": ".venv/bin/python" | |
| 89 | + } | |
| 90 | + } | |
| 91 | + } | |
| 92 | + } | |
| 93 | +} | |
| 94 | +``` | |
| 95 | + | |
| 51 | 96 | ### Code formatting |
| 52 | 97 | |
| 53 | 98 | The Pyright language server does not provide code formatting. If you want to automatically reformat your Python code when saving, you'll need to specify an \_external_code formatter in your settings. See the [configuration](../configuring-zed.md) documentation for more information. |