openlawlibrary / pygls

A pythonic generic language server
https://pygls.readthedocs.io/en/latest/
Apache License 2.0
568 stars 103 forks source link

Add example semantic tokens server #484

Closed alcarney closed 2 months ago

alcarney commented 2 months ago

Description (e.g. "Related to ...", etc.)

image

This adds an example semantic tokens server, replacing the existing half implementation we have in the json_server.py example. That said, it's still only semantic tokens "level one" - there is still the range based method and delta updates to consider! :sweat_smile:

Unlike most other methods semantic tokens are quite obtuse, for example, here is the result the server sent when highlighting the code in the above screenshot

{"id": 2, "jsonrpc": "2.0", "result": {"data": [0, 0, 4, 0, 0, 0, 5, 9, 5, 8, 0, 9, 1, 3, 0, 0, 1, 1, 1, 0, 0, 1, 1, 3, 0, 0, 2, 1, 1, 0, 0, 1, 1, 3, 0, 0, 2, 1, 1, 0, 0, 1, 1, 3, 0, 0, 2, 1, 1, 0, 0, 1, 1, 3, 0, 0, 2, 1, 3, 0, 0, 2, 1, 3, 0, 0, 1, 1, 4, 0, 0, 1, 1, 3, 0, 0, 2, 1, 1, 0, 0, 1, 1, 3, 0, 0, 2, 1, 4, 0, 0, 1, 1, 3, 0, 0, 2, 1, 1, 0, 0, 1, 1, 3, 0, 0, 2, 5, 4, 0, 0, 5, 1, 3, 0, 0, 2, 1, 1, 0, 0, 1, 1, 3, 0, 0, 2, 6, 4, 0, 0, 6, 1, 3, 0, 0, 2, 1, 1, 0, 0, 2, 1, 3, 0, 1, 0, 4, 0, 0, 0, 5, 6, 5, 8, 0, 6, 1, 3, 0, 0, 1, 1, 1, 0, 0, 1, 1, 3, 0, 0, 2, 1, 1, 0, 0, 1, 1, 3, 0, 0, 2, 1, 1, 0, 0, 1, 1, 3, 0, 0, 2, 1, 3, 0, 0, 2, 9, 5, 0, 0, 9, 1, 3, 0, 0, 1, 1, 1, 0, 0, 1, 1, 3, 0, 0, 2, 1, 1, 0, 0, 1, 1, 3, 0, 0, 2, 1, 1, 0, 0, 1, 1, 3, 0, 0, 2, 1, 1, 0, 0, 1, 1, 3, 0, 2, 0, 2, 0, 0, 0, 3, 4, 2, 8, 0, 4, 1, 3, 0, 0, 1, 4, 1, 0, 0, 4, 1, 3, 0, 0, 2, 9, 5, 0, 0, 9, 1, 3, 0, 0, 2, 2, 3, 0, 0, 3, 4, 1, 0, 0, 4, 1, 3, 0, 0, 1, 5, 1, 0, 0, 6, 1, 3, 0, 0, 2, 4, 1, 0, 0, 4, 1, 3, 0, 0, 1, 6, 1, 0, 2, 0, 2, 0, 0, 0, 3, 6, 2, 8, 0, 6, 1, 3, 0, 0, 1, 4, 1, 0, 0, 4, 1, 3, 0, 0, 2, 9, 5, 0, 0, 9, 1, 3, 0, 0, 2, 6, 1, 0, 0, 6, 1, 3, 0, 0, 2, 5, 5, 4, 0, 5, 1, 3, 0, 0, 2, 2, 3, 0, 0, 3, 4, 2, 8, 0, 4, 1, 3, 0, 0, 1, 4, 1, 0, 0, 4, 1, 3, 0, 0, 2, 1, 3, 0, 0, 2, 6, 1, 0]}}

So this PR also includes an accompanying how to guide containing some interactive demos that (hopefully!) help explain what's going on

image

Code review checklist (for code reviewer to complete)

Automated linters

You can run the lints that are run on CI locally with:

poetry install --all-extras --with dev
poetry run poe lint