Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate server methods based on lsprotocol type definitions #489

Merged
merged 9 commits into from
Aug 22, 2024

Conversation

alcarney
Copy link
Collaborator

@alcarney alcarney commented Aug 14, 2024

#487 introduced some breaking changes, so this PR is taking the opportunity to make a few more that were going to be part of #418.

Similar to the BaseLanguageClient, this PR updates the code generation script to now also produce a BaseLanguageServer with all the server side methods generated based on the type definitions provided by lsprotocol

Not only does this improve consistency and remove the need for the duplicated methods on the LanguageServerProtocol class (Closes #306), we also get all the server side methods we were missing!

Aside from the obvious naming/argument changes, this also introduces the following changes (which we will need to document in a migration guide)

  • server.progress now sends a $/progress notification, rather than giving access to pygls' Progress helper. The helper is now accessed via server.work_done_progress
  • The underlying protocol class is now accessed via server.protocol rather than server.lsp.

Finally, the base Server class has been tidied up a little

  • Removed some LSP specific quriks (e.g. sync_kind)
  • The report_server_error code has been pushed down into the base
  • The feature, thread and command registration code has been pushed down into the base

TODO

Code review checklist (for code reviewer to complete)

  • Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR)
  • Title summarizes what is changing
  • Commit messages are meaningful (see this for details)
  • Tests have been included and/or updated, as appropriate
  • Docstrings have been included and/or updated, as appropriate
  • Standalone docs have been updated accordingly

Automated linters

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

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

@alcarney alcarney force-pushed the generated-server branch 6 times, most recently from 368fbb3 to 5ad2d52 Compare August 20, 2024 20:10
@alcarney
Copy link
Collaborator Author

Added an initial draft of the migration guide, there are a few more changes we can make (e.g. removing deprecated methods) so I expect it will take a few more revisions to get right.

So this should be ready for a review now.

That said, the lint job has started failing and I'm not entirely sure why...

Run source $VENV
/home/runner/work/_temp/0f22c65c-8345-4c8d-8709-e3f4d68c7c6b.sh: /home/runner/work/pygls/pygls/.venv/bin/poe: /home/runner/work/pygls/pygls/.venv/bin/python: bad interpreter: No such file or directory
Error: Process completed with exit code 126.

@alcarney alcarney marked this pull request as ready for review August 20, 2024 20:19
@alcarney alcarney requested a review from tombh August 20, 2024 20:19
@tombh tombh mentioned this pull request Aug 21, 2024
6 tasks
Copy link
Collaborator

@tombh tombh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such great work again ❤️ So many improvements, detailed docs and fixing old issues 💪

Do the new docs get automatically published on merge to main? I can't remember now. It might be good to have an update in our main README about how we're looking for beta testers for the breaking changes and a link to the migration docs?

"2. Commit"
(
"🔴 Pygls client or server not up to date\n"
"1. Re-generate with: `poetry run poe generate_client`\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's generate_client_server now right?

pyproject.toml Outdated
@@ -58,7 +58,7 @@ ruff = "ruff check ."
mypy = "mypy -p pygls"
check_generated_client = "python scripts/check_client_is_uptodate.py"
check_commit_style = "npx commitlint --from origin/main --to HEAD --verbose --config commitlintrc.yaml"
generate_client = "python scripts/generate_client.py --output pygls/lsp/client.py"
generate_client = "python scripts/generate_client_server.py pygls/lsp"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename the command to generate_client_server?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed it and the script to generate_code - seems to complement the check_generated_code_is_uptodate.py script?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename this to check_generated_code_is_uptodate.py?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@tombh
Copy link
Collaborator

tombh commented Aug 21, 2024

I have a PR for the failing CI issue: #491

Similarly to the `BaseLanguageClient` this commit now introduces a
`BaseLanguageServer` with methods automatically generated from type
definitions provided by `lsprotocol`
This commit refactors the `LanguageServer` class to be based on the new
`BaseLanguageServer`. The server has also been moved into the
`pygls.lsp` module in an attempt to be more consistent with the client
side code.

It also takes the opportunity to tidy a few things up

- Pushing generic server features such as error reporting and feature
  registration down into the base `Server` class
- Removing LSP specific quirks from the base class e.g.
  `TextDocumentSyncKind`
- Renames `server.lsp` to `server.protocol` to align better with the
  client code
@alcarney
Copy link
Collaborator Author

Do the new docs get automatically published on merge to main?

Yes, https://pygls.readthedocs.io/en/latest/ points to main

It might be good to have an update in our main README about how we're looking for beta testers for the breaking changes and a link to the migration docs?

I've added a note to the README, though there are a few more changes we should make before shouting too loudly about it :)

Copy link
Collaborator

@tombh tombh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! LGTM 🚀

@alcarney alcarney merged commit d221533 into openlawlibrary:main Aug 22, 2024
16 checks passed
@alcarney alcarney deleted the generated-server branch August 22, 2024 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explore parity between server.LanguageServer and protocol.LanguageServerProtocol methods
2 participants