Skip to content

Commit

Permalink
Only pass the id parameter to types that use it
Browse files Browse the repository at this point in the history
  • Loading branch information
dcermak committed Jan 23, 2023
1 parent b7e6e5c commit 8d15c8b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ and this project adheres to [Semantic Versioning][semver].
- Fix progress example in json extension. ([#230])
- Fix `AttributeErrors` in `get_configuration_async`, `get_configuration_callback`, `get_configuration_threaded` commands in json extension. ([#307])
- Fix type annotations for `get_configuration_async` and `get_configuration` methods on `LanguageServer` and `LanguageServerProtocol` objects ([#307])
- Fix passing `id` to `TextDocumentDidOpenNotification` ([#312])

[#230]: https://github.com/openlawlibrary/pygls/issues/230
[#307]: https://github.com/openlawlibrary/pygls/issues/307
[#312]: https://github.com/openlawlibrary/pygls/issues/312


## [1.0.0] - 2/12/2022
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [Brett Cannon](https://github.com/brettcannon/)
- [Daniel Elero](https://github.com/danixeee)
- [Daniel Miller](https://github.com/millerdev)
- [Dan Čermák](https://github.com/dcermak)
- [DeathAxe](https://github.com/deathaxe)
- [Denis Loginov](https://github.com/dinvlad)
- [Dillan Mills](https://github.com/DillanCMills)
Expand Down
10 changes: 4 additions & 6 deletions pygls/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,10 @@ def send_request(self, method, params=None, callback=None, msg_id=None):
request_type = self.get_message_type(method) or JsonRPCRequestMessage
logger.debug('Sending request with id "%s": %s %s', msg_id, method, params)

request = request_type(
id=msg_id,
method=method,
params=params,
jsonrpc=JsonRPCProtocol.VERSION,
)
kwargs = {"method": method, "params": params, "jsonrpc": JsonRPCProtocol.VERSION}
if hasattr(request_type, "id"):
kwargs["id"] = msg_id
request = request_type(**kwargs)

future = Future()
# If callback function is given, call it when result is received
Expand Down
27 changes: 27 additions & 0 deletions tests/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@
from lsprotocol.types import (
PROGRESS,
TEXT_DOCUMENT_COMPLETION,
TEXT_DOCUMENT_DID_OPEN,
ClientCapabilities,
CompletionItem,
CompletionItemKind,
CompletionParams,
DidOpenTextDocumentParams,
InitializeParams,
InitializeResult,
ProgressParams,
Position,
ShutdownResponse,
TextDocumentCompletionResponse,
TextDocumentIdentifier,
TextDocumentItem,
WorkDoneProgressBegin,
)
from pygls.protocol import (
Expand Down Expand Up @@ -492,6 +495,30 @@ def test_serialize_response_message(msg_type, result, expected):
},
},
),
(
TEXT_DOCUMENT_DID_OPEN,
DidOpenTextDocumentParams(
text_document=TextDocumentItem(
uri="file:///file.txt",
language_id="txt",
version=0,
text="just some text",
)
),
{
"jsonrpc": "2.0",
"id": "1",
"method": TEXT_DOCUMENT_DID_OPEN,
"params": {
"textDocument": {
"uri": "file:///file.txt",
"languageId": "txt",
"version": 0,
"text": "just some text",
},
},
},
),
( # Unknown type with object params.
EXAMPLE_REQUEST,
ExampleParams(
Expand Down

0 comments on commit 8d15c8b

Please sign in to comment.