Open
Conversation
|
Would you mind helping me with python-lsp/python-lsp-server#579 as well? That would be wonderful! :) |
Author
|
@rumpelsepp Yep, was planning to help with that next. I want to push this one over the line first — I see tests are failing. |
Author
|
The test failure seems unrelated to this change: |
Member
Implemented as requested in this comment: python-lsp/python-lsp-server#579 (review)
0477625 to
eec1388
Compare
Author
|
@ccordoba12 Done; thanks for the fix and sorry for the delay! |
Member
|
@valrus, it seems that this is ready, thanks! Now, the next step is to open a PR in the pylsp-server repo that pulls this one and checks our tests pass there with orjson. For that, you can also start with this previous PR from @rumpelsepp: python-lsp/python-lsp-server#579. |
Author
|
@ccordoba12 OK, I gave it a try: python-lsp/python-lsp-server#591 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is an attempt to carry #28 to completion, making the necessary changes to ensure compatibility with
orjsonand adding tests against bothorjsonand the stdlibjsonto ensure that the writer works no matter which is imported.There were two main pieces necessary for the migration:
orjsondoesn't support thesort_keyskwarg todumps; instead itsdumpstakes anoptionkwarg which expects bitwise flags. This PR makes the necessary changes toself._json_dumps_argsinJsonRpcStreamWriter.__init__depending on whetherorjsonis available. (Unnecessary but hopefully helpful: it also adds theseparators=(',', ':')kwarg to the stdlib json case so that it matchesorjson's behavior of omitting unnecessary spaces.)orjson.dumpsreturns bytes, not a string. This PR encodes the dumped JSON if necessary (i.e. in the stdlib case) and uses bytestring % formatting to populateresponseinJsonRpcStreamWriter.write.It was tricky to make sure that this worked with or without
orjson. The existing test only tests theorjsoncase iforjsonis available on the system on which the tests are run, but I wanted to be sure to testJsonRpcStreamWriteragainst the stdlibjsontoo. As such, this PR adds atest_writer_stdlib_jsontest that uses some funky patching to ensure thatJsonRpcStreamWriter.writebehaves correctly whenorjsonis unavailable. It's a bit hacky but I confirmed that it does what's intended in the debugger and it seemed better than risking a developer breaking the writer for users who can't importorjson. (Unfortunately I don't think there's any good way to test the writer againstorjsonif it can't be imported in the dev's environment!)