Skip to content

Commit

Permalink
chore: align tests with new server implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Aug 18, 2024
1 parent fd38dd1 commit 368fbb3
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 154 deletions.
71 changes: 0 additions & 71 deletions tests/e2e/test_inline_value.py

This file was deleted.

22 changes: 11 additions & 11 deletions tests/ls_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
ClientCapabilities,
InitializeParams,
)
from pygls.server import LanguageServer
from pygls.lsp.server import LanguageServer


from . import CMD_ASYNC, CMD_SYNC, CMD_THREAD
Expand Down Expand Up @@ -62,8 +62,8 @@ def __init__(self, dest: LanguageServer):
def close(self): ...

def write(self, data):
object_hook = self.dest.lsp._deserialize_message
self.dest.lsp._procedure_handler(json.loads(data, object_hook=object_hook))
object_hook = self.dest.protocol._deserialize_message
self.dest.protocol._procedure_handler(json.loads(data, object_hook=object_hook))


class PyodideClientServer:
Expand All @@ -74,11 +74,11 @@ def __init__(self, LS=LanguageServer):
self.server = LS("pygls-server", "v1")
self.client = LS("pygls-client", "v1")

self.server.lsp.connection_made(PyodideTestTransportAdapter(self.client))
self.server.lsp._send_only_body = True
self.server.protocol.connection_made(PyodideTestTransportAdapter(self.client))
self.server.protocol._send_only_body = True

self.client.lsp.connection_made(PyodideTestTransportAdapter(self.server))
self.client.lsp._send_only_body = True
self.client.protocol.connection_made(PyodideTestTransportAdapter(self.server))
self.client.protocol._send_only_body = True

def start(self):
self.initialize()
Expand All @@ -90,7 +90,7 @@ def decorate(cls):
return pytest.mark.parametrize("client_server", [cls], indirect=True)

def initialize(self):
response = self.client.lsp.send_request(
response = self.client.protocol.send_request(
INITIALIZE,
InitializeParams(
process_id=12345, root_uri="file://", capabilities=ClientCapabilities()
Expand Down Expand Up @@ -140,9 +140,9 @@ def start(self):
self.initialize()

def stop(self):
shutdown_response = self.client.lsp.send_request(SHUTDOWN).result()
shutdown_response = self.client.protocol.send_request(SHUTDOWN).result()
assert shutdown_response is None
self.client.lsp.notify(EXIT)
self.client.protocol.notify(EXIT)
self.server_thread.join()
self.client._stop_event.set()
try:
Expand All @@ -154,7 +154,7 @@ def stop(self):
@retry_stalled_init_fix_hack()
def initialize(self):
timeout = None if "DISABLE_TIMEOUT" in os.environ else 1
response = self.client.lsp.send_request(
response = self.client.protocol.send_request(
INITIALIZE,
InitializeParams(
process_id=12345, root_uri="file://", capabilities=ClientCapabilities()
Expand Down
8 changes: 4 additions & 4 deletions tests/lsp/test_call_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_capabilities(client_server):
@ConfiguredLS.decorate()
def test_call_hierarchy_prepare_return_list(client_server):
client, _ = client_server
response = client.lsp.send_request(
response = client.protocol.send_request(
TEXT_DOCUMENT_PREPARE_CALL_HIERARCHY,
CallHierarchyPrepareParams(
text_document=TextDocumentIdentifier(uri="file://return.list"),
Expand All @@ -145,7 +145,7 @@ def test_call_hierarchy_prepare_return_list(client_server):
@ConfiguredLS.decorate()
def test_call_hierarchy_prepare_return_none(client_server):
client, _ = client_server
response = client.lsp.send_request(
response = client.protocol.send_request(
TEXT_DOCUMENT_PREPARE_CALL_HIERARCHY,
CallHierarchyPrepareParams(
text_document=TextDocumentIdentifier(uri="file://return.none"),
Expand All @@ -159,7 +159,7 @@ def test_call_hierarchy_prepare_return_none(client_server):
@ConfiguredLS.decorate()
def test_call_hierarchy_incoming_calls_return_list(client_server):
client, _ = client_server
response = client.lsp.send_request(
response = client.protocol.send_request(
CALL_HIERARCHY_INCOMING_CALLS,
CallHierarchyIncomingCallsParams(item=CALL_HIERARCHY_ITEM),
).result()
Expand All @@ -177,7 +177,7 @@ def test_call_hierarchy_incoming_calls_return_list(client_server):
@ConfiguredLS.decorate()
def test_call_hierarchy_outgoing_calls_return_list(client_server):
client, _ = client_server
response = client.lsp.send_request(
response = client.protocol.send_request(
CALL_HIERARCHY_OUTGOING_CALLS,
CallHierarchyOutgoingCallsParams(item=CALL_HIERARCHY_ITEM),
).result()
Expand Down
4 changes: 2 additions & 2 deletions tests/lsp/test_document_highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_capabilities(client_server):
@ConfiguredLS.decorate()
def test_document_highlight_return_list(client_server):
client, _ = client_server
response = client.lsp.send_request(
response = client.protocol.send_request(
TEXT_DOCUMENT_DOCUMENT_HIGHLIGHT,
DocumentHighlightParams(
text_document=TextDocumentIdentifier(uri="file://return.list"),
Expand All @@ -97,7 +97,7 @@ def test_document_highlight_return_list(client_server):
@ConfiguredLS.decorate()
def test_document_highlight_return_none(client_server):
client, _ = client_server
response = client.lsp.send_request(
response = client.protocol.send_request(
TEXT_DOCUMENT_DOCUMENT_HIGHLIGHT,
DocumentHighlightParams(
text_document=TextDocumentIdentifier(uri="file://return.none"),
Expand Down
25 changes: 15 additions & 10 deletions tests/lsp/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import time

import pytest
from lsprotocol import types

from pygls.exceptions import JsonRpcInternalError, PyglsError, JsonRpcException
from lsprotocol.types import WINDOW_SHOW_MESSAGE, MessageType
from pygls.server import LanguageServer
from pygls.lsp.server import LanguageServer

from ..conftest import ClientServer

Expand All @@ -48,7 +48,12 @@ class CustomLanguageServerSendAll(LanguageServer):
def report_server_error(
self, error: Exception, source: Union[PyglsError, JsonRpcException]
):
self.show_message(self.default_error_message, msg_type=MessageType.Error)
self.window_show_message(
types.ShowMessageParams(
message="Error in LSP server",
type=types.MessageType.Error,
),
)


class ConfiguredLS(ClientServer):
Expand All @@ -63,7 +68,7 @@ def init(self):
def f1(params: Any):
raise Exception(ERROR_MESSAGE)

@self.client.feature(WINDOW_SHOW_MESSAGE)
@self.client.feature(types.WINDOW_SHOW_MESSAGE)
def f2(params: Any):
self.client.messages.append(params.message)

Expand All @@ -89,7 +94,7 @@ def test_request_error_reporting_default(client_server):
assert len(client.messages) == 0

with pytest.raises(JsonRpcInternalError, match=ERROR_MESSAGE):
client.lsp.send_request(ERROR_TRIGGER).result()
client.protocol.send_request(ERROR_TRIGGER).result()

time.sleep(0.1)
assert len(client.messages) == 0
Expand All @@ -101,7 +106,7 @@ def test_request_error_reporting_override(client_server):
assert len(client.messages) == 0

with pytest.raises(JsonRpcInternalError, match=ERROR_MESSAGE):
client.lsp.send_request(ERROR_TRIGGER).result()
client.protocol.send_request(ERROR_TRIGGER).result()

time.sleep(0.1)
assert len(client.messages) == 1
Expand All @@ -110,17 +115,17 @@ def test_request_error_reporting_override(client_server):
@ConfiguredLS.decorate()
def test_notification_error_reporting(client_server):
client, _ = client_server
client.lsp.notify(ERROR_TRIGGER)
client.protocol.notify(ERROR_TRIGGER)
time.sleep(0.1)

assert len(client.messages) == 1
assert client.messages[0] == LanguageServer.default_error_message
assert client.messages[0].startswith("Error in server:")


@CustomConfiguredLSSafe.decorate()
def test_overriding_error_reporting(client_server):
client, _ = client_server
client.lsp.notify(ERROR_TRIGGER)
client.protocol.notify(ERROR_TRIGGER)
time.sleep(0.1)

assert len(client.messages) == 0
Expand All @@ -129,7 +134,7 @@ def test_overriding_error_reporting(client_server):
@CustomConfiguredLSPotentialRecusrion.decorate()
def test_overriding_error_reporting_with_potential_recursion(client_server):
client, _ = client_server
client.lsp.notify(ERROR_TRIGGER)
client.protocol.notify(ERROR_TRIGGER)
time.sleep(0.1)

assert len(client.messages) == 0
4 changes: 2 additions & 2 deletions tests/lsp/test_folding_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_capabilities(client_server):
@ConfiguredLS.decorate()
def test_folding_range_return_list(client_server):
client, _ = client_server
response = client.lsp.send_request(
response = client.protocol.send_request(
TEXT_DOCUMENT_FOLDING_RANGE,
FoldingRangeParams(
text_document=TextDocumentIdentifier(uri="file://return.list"),
Expand All @@ -82,7 +82,7 @@ def test_folding_range_return_list(client_server):
@ConfiguredLS.decorate()
def test_folding_range_return_none(client_server):
client, _ = client_server
response = client.lsp.send_request(
response = client.protocol.send_request(
TEXT_DOCUMENT_FOLDING_RANGE,
FoldingRangeParams(
text_document=TextDocumentIdentifier(uri="file://return.none"),
Expand Down
4 changes: 2 additions & 2 deletions tests/lsp/test_linked_editing_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_capabilities(client_server):
@ConfiguredLS.decorate()
def test_linked_editing_ranges_return_ranges(client_server):
client, _ = client_server
response = client.lsp.send_request(
response = client.protocol.send_request(
TEXT_DOCUMENT_LINKED_EDITING_RANGE,
LinkedEditingRangeParams(
text_document=TextDocumentIdentifier(uri="file://return.ranges"),
Expand All @@ -92,7 +92,7 @@ def test_linked_editing_ranges_return_ranges(client_server):
@ConfiguredLS.decorate()
def test_linked_editing_ranges_return_none(client_server):
client, _ = client_server
response = client.lsp.send_request(
response = client.protocol.send_request(
TEXT_DOCUMENT_LINKED_EDITING_RANGE,
LinkedEditingRangeParams(
text_document=TextDocumentIdentifier(uri="file://return.none"),
Expand Down
4 changes: 2 additions & 2 deletions tests/lsp/test_moniker.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_capabilities(client_server):
@ConfiguredLS.decorate()
def test_moniker_return_list(client_server):
client, _ = client_server
response = client.lsp.send_request(
response = client.protocol.send_request(
TEXT_DOCUMENT_MONIKER,
MonikerParams(
text_document=TextDocumentIdentifier(uri="file://return.list"),
Expand All @@ -83,7 +83,7 @@ def test_moniker_return_list(client_server):
@ConfiguredLS.decorate()
def test_references_return_none(client_server):
client, _ = client_server
response = client.lsp.send_request(
response = client.protocol.send_request(
TEXT_DOCUMENT_MONIKER,
MonikerParams(
text_document=TextDocumentIdentifier(uri="file://return.none"),
Expand Down
Loading

0 comments on commit 368fbb3

Please sign in to comment.