|
| 1 | +# Setup the environment |
| 2 | + |
| 3 | +1. Clone the repo: `git clone [email protected]:python-lsp/python-lsp-server.git` |
| 4 | +2. Create the virtual environment: `python3 -m virtualenv .venv` |
| 5 | +3. Activate: `source .venv/bin/activate` |
| 6 | + |
| 7 | +Create a helper script to run the server without the need to `pip3 install` it |
| 8 | +on every change and name it `run` or similar: |
| 9 | + |
| 10 | +```py |
| 11 | +#!/home/user/projects/python-lsp-server/.venv/bin/python |
| 12 | +import sys |
| 13 | + |
| 14 | +from pylsp.__main__ import main |
| 15 | + |
| 16 | +sys.exit(main()) |
| 17 | +``` |
| 18 | + |
| 19 | +## Configure your editor |
| 20 | + |
| 21 | +In Sublime Text 4, open LSP-pylsp settings and change the path to the `pylsp` command: |
| 22 | + |
| 23 | +```json |
| 24 | +{ |
| 25 | + "command": ["/home/user/projects/python-lsp-server/run", "-vvv", "--log-file", "pylsp.log"] |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +Option `-v` increases verbosity and `--log-file` will write all log messages |
| 30 | +into a file, which can be used for debugging. |
| 31 | + |
| 32 | +Running command `LSP: Troubleshoot server` you should now see the configured command, |
| 33 | +if not, then the configuration doesn't work as expected. |
| 34 | + |
| 35 | +To enabled plugins like `ruff`, you also need to point your editor to the correct |
| 36 | +`PYTHONPATH`: |
| 37 | + |
| 38 | +```json |
| 39 | +{ |
| 40 | + "command": ["/home/user/projects/python-lsp-server/run", "-vvv", "--log-file", "pylsp.log"], |
| 41 | + "env": { |
| 42 | + "PYTHONPATH": "/home/user/projects/python-lsp-server/.venv/lib/python3.11/site-packages", |
| 43 | + }, |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +## Trying out if it works |
| 48 | + |
| 49 | +Go to file `pylsp/python_lsp.py`, function `start_io_lang_server`, |
| 50 | +and on the first line of the function, add some logging: |
| 51 | + |
| 52 | +```py |
| 53 | +log.info("It works!") |
| 54 | +``` |
| 55 | + |
| 56 | +Save the file, restart the LSP server and you should see the log line: |
| 57 | + |
| 58 | +``` |
| 59 | +2023-10-12 16:46:38,320 CEST - INFO - pylsp._utils - It works! |
| 60 | +``` |
| 61 | + |
| 62 | +Now the project is setup in a way you can quickly iterate change you want to add. |
| 63 | + |
| 64 | +# Running tests |
| 65 | + |
| 66 | +1. Install dependencies: `pip3 install .[test]` |
| 67 | +2. Run `pytest`: `pytest -v` |
0 commit comments