Skip to content

Commit

Permalink
Update test suite to use LanguageClient
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Apr 4, 2023
1 parent baf0e70 commit d164ebf
Show file tree
Hide file tree
Showing 31 changed files with 101 additions and 185 deletions.
46 changes: 20 additions & 26 deletions tests/ls_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,18 @@ class PyodideTestTransportAdapter:
"""Transort adapter that's only useful for tests in a pyodide environment."""

def __init__(self, dest: LanguageServer):
self.dest = dest

if hasattr(dest, "lsp"):
self.protocol = dest.lsp
else:
self.protocol = dest.protocol

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.protocol._deserialize_message
self.protocol._procedure_handler(json.loads(data, object_hook=object_hook))


class PyodideClientServer:
Expand All @@ -76,14 +78,14 @@ class PyodideClientServer:

def __init__(self, LS=LanguageServer):

self.server = LS('pygls-server', 'v1')
self.client = LS('pygls-client', 'v1')
self.server = LS("pygls-server", "v1")
self.client = LanguageClient("pygls-client", "v1")

self.server.lsp.connection_made(PyodideTestTransportAdapter(self.client))
self.server.lsp._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 @@ -100,13 +102,10 @@ def decorate(cls):
)

def initialize(self):
response = self.client.lsp.send_request(
INITIALIZE,
response = self.client.initialize(
InitializeParams(
process_id=12345,
root_uri="file://",
capabilities=ClientCapabilities()
)
process_id=12345, root_uri="file://", capabilities=ClientCapabilities()
),
).result(timeout=CALL_TIMEOUT)

assert response.capabilities is not None
Expand All @@ -133,7 +132,7 @@ def __init__(self, LS=LanguageServer):
self.server_thread.daemon = True

# Setup client
self.client = LS('client', 'v1', asyncio.new_event_loop())
self.client = LanguageClient("client", "v1", loop=asyncio.new_event_loop())
self.client_thread = threading.Thread(
name='Client Thread',
target=self.client.start_io,
Expand All @@ -156,11 +155,9 @@ def start(self):
self.initialize()

def stop(self):
shutdown_response = self.client.lsp.send_request(
SHUTDOWN
).result()
shutdown_response = self.client.shutdown(None).result()
assert shutdown_response is None
self.client.lsp.notify(EXIT)
self.client.exit(None)
self.server_thread.join()
self.client._stop_event.set()
try:
Expand All @@ -172,13 +169,10 @@ 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(
INITIALIZE,
timeout = None if "DISABLE_TIMEOUT" in os.environ else 1
response = self.client.initialize(
InitializeParams(
process_id=12345,
root_uri="file://",
capabilities=ClientCapabilities()
process_id=12345, root_uri="file://", capabilities=ClientCapabilities()
),
).result(timeout=timeout)
assert response.capabilities is not None
Expand Down
6 changes: 2 additions & 4 deletions tests/lsp/semantic_tokens/test_delta_missing_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def test_capabilities(client_server):
@ConfiguredLS.decorate()
def test_semantic_tokens_full_delta_return_tokens(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_SEMANTIC_TOKENS_FULL_DELTA,
response = client.text_document_semantic_tokens_full_delta(
SemanticTokensDeltaParams(
text_document=TextDocumentIdentifier(
uri="file://return.tokens"),
Expand All @@ -85,8 +84,7 @@ def test_semantic_tokens_full_delta_return_tokens(client_server):
@ConfiguredLS.decorate()
def test_semantic_tokens_full_delta_return_none(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_SEMANTIC_TOKENS_FULL_DELTA,
response = client.text_document_semantic_tokens_full_delta(
SemanticTokensDeltaParams(
text_document=TextDocumentIdentifier(uri="file://return.none"),
previous_result_id="id",
Expand Down
6 changes: 2 additions & 4 deletions tests/lsp/semantic_tokens/test_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ def test_capabilities(client_server):
@ConfiguredLS.decorate()
def test_semantic_tokens_range_return_tokens(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_SEMANTIC_TOKENS_RANGE,
response = client.text_document_semantic_tokens_range(
SemanticTokensRangeParams(
text_document=TextDocumentIdentifier(
uri="file://return.tokens"),
Expand All @@ -96,8 +95,7 @@ def test_semantic_tokens_range_return_tokens(client_server):
@ConfiguredLS.decorate()
def test_semantic_tokens_range_return_none(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_SEMANTIC_TOKENS_RANGE,
response = client.text_document_semantic_tokens_range(
SemanticTokensRangeParams(
text_document=TextDocumentIdentifier(uri="file://return.none"),
range=Range(
Expand Down
6 changes: 2 additions & 4 deletions tests/lsp/semantic_tokens/test_semantic_tokens_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ def test_capabilities(client_server):
@ConfiguredLS.decorate()
def test_semantic_tokens_full_return_tokens(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_SEMANTIC_TOKENS_FULL,
response = client.text_document_semantic_tokens_full(
SemanticTokensParams(
text_document=TextDocumentIdentifier(
uri="file://return.tokens")
Expand All @@ -90,8 +89,7 @@ def test_semantic_tokens_full_return_tokens(client_server):
@ConfiguredLS.decorate()
def test_semantic_tokens_full_return_none(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_SEMANTIC_TOKENS_FULL,
response = client.text_document_semantic_tokens_full(
SemanticTokensParams(
text_document=TextDocumentIdentifier(uri="file://return.none")
),
Expand Down
16 changes: 6 additions & 10 deletions tests/lsp/test_call_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,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(
TEXT_DOCUMENT_PREPARE_CALL_HIERARCHY,
response = client.text_document_prepare_call_hierarchy(
CallHierarchyPrepareParams(
text_document=TextDocumentIdentifier(uri='file://return.list'),
position=Position(line=0, character=0),
Expand All @@ -139,8 +138,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(
TEXT_DOCUMENT_PREPARE_CALL_HIERARCHY,
response = client.text_document_prepare_call_hierarchy(
CallHierarchyPrepareParams(
text_document=TextDocumentIdentifier(uri='file://return.none'),
position=Position(line=0, character=0),
Expand All @@ -153,9 +151,8 @@ 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(
CALL_HIERARCHY_INCOMING_CALLS,
CallHierarchyIncomingCallsParams(item=CALL_HIERARCHY_ITEM)
response = client.call_hierarchy_incoming_calls(
CallHierarchyIncomingCallsParams(item=CALL_HIERARCHY_ITEM),
).result()

item = response[0]
Expand All @@ -171,9 +168,8 @@ 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(
CALL_HIERARCHY_OUTGOING_CALLS,
CallHierarchyOutgoingCallsParams(item=CALL_HIERARCHY_ITEM)
response = client.call_hierarchy_outgoing_calls(
CallHierarchyOutgoingCallsParams(item=CALL_HIERARCHY_ITEM),
).result()

item = response[0]
Expand Down
6 changes: 2 additions & 4 deletions tests/lsp/test_code_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ def test_capabilities(client_server):
@ConfiguredLS.decorate()
def test_code_action_return_list(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_CODE_ACTION,
response = client.text_document_code_action(
CodeActionParams(
text_document=TextDocumentIdentifier(uri="file://return.list"),
range=Range(
Expand Down Expand Up @@ -105,8 +104,7 @@ def test_code_action_return_list(client_server):
@ConfiguredLS.decorate()
def test_code_action_return_none(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_CODE_ACTION,
response = client.text_document_code_action(
CodeActionParams(
text_document=TextDocumentIdentifier(uri="file://return.none"),
range=Range(
Expand Down
14 changes: 4 additions & 10 deletions tests/lsp/test_code_lens.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ def test_capabilities(client_server):
@ConfiguredLS.decorate()
def test_code_lens_return_list(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_CODE_LENS,
CodeLensParams(
text_document=TextDocumentIdentifier(uri="file://return.list")
),
response = client.text_document_code_lens(
CodeLensParams(text_document=TextDocumentIdentifier(uri="file://return.list")),
).result()

assert response[0].data == "some data"
Expand All @@ -88,11 +85,8 @@ def test_code_lens_return_list(client_server):
@ConfiguredLS.decorate()
def test_code_lens_return_none(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_CODE_LENS,
CodeLensParams(
text_document=TextDocumentIdentifier(uri="file://return.none")
),
response = client.text_document_code_lens(
CodeLensParams(text_document=TextDocumentIdentifier(uri="file://return.none")),
).result()

assert response is None
3 changes: 1 addition & 2 deletions tests/lsp/test_color_presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def f(params: ColorPresentationParams) -> List[ColorPresentation]:
@ConfiguredLS.decorate()
def test_color_presentation(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_COLOR_PRESENTATION,
response = client.text_document_color_presentation(
ColorPresentationParams(
text_document=TextDocumentIdentifier(uri="file://return.list"),
color=Color(red=0.6, green=0.2, blue=0.3, alpha=0.5),
Expand Down
3 changes: 1 addition & 2 deletions tests/lsp/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ def test_capabilities(client_server):
@ConfiguredLS.decorate()
def test_completions(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_COMPLETION,
response = client.text_document_completion(
CompletionParams(
text_document=TextDocumentIdentifier(uri="file://test.test"),
position=Position(line=0, character=0),
Expand Down
12 changes: 4 additions & 8 deletions tests/lsp/test_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ def test_capabilities(client_server):
@ConfiguredLS.decorate()
def test_declaration_return_location(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_DECLARATION,
response = client.text_document_declaration(
DeclarationParams(
text_document=TextDocumentIdentifier(
uri="file://return.location"
Expand All @@ -102,8 +101,7 @@ def test_declaration_return_location(client_server):
@ConfiguredLS.decorate()
def test_declaration_return_location_list(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_DECLARATION,
response = client.text_document_declaration(
DeclarationParams(
text_document=TextDocumentIdentifier(
uri="file://return.location_list"),
Expand All @@ -122,8 +120,7 @@ def test_declaration_return_location_list(client_server):
@ConfiguredLS.decorate()
def test_declaration_return_location_link_list(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_DECLARATION,
response = client.text_document_declaration(
DeclarationParams(
text_document=TextDocumentIdentifier(
uri="file://return.location_link_list"
Expand Down Expand Up @@ -153,8 +150,7 @@ def test_declaration_return_location_link_list(client_server):
@ConfiguredLS.decorate()
def test_declaration_return_none(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_DECLARATION,
response = client.text_document_declaration(
DeclarationParams(
text_document=TextDocumentIdentifier(uri="file://return.none"),
position=Position(line=0, character=0),
Expand Down
12 changes: 4 additions & 8 deletions tests/lsp/test_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ def test_capabilities(client_server):
@ConfiguredLS.decorate()
def test_definition_return_location(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_DEFINITION,
response = client.text_document_definition(
DefinitionParams(
text_document=TextDocumentIdentifier(
uri="file://return.location"),
Expand All @@ -104,8 +103,7 @@ def test_definition_return_location(client_server):
@ConfiguredLS.decorate()
def test_definition_return_location_list(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_DEFINITION,
response = client.text_document_definition(
DefinitionParams(
text_document=TextDocumentIdentifier(
uri="file://return.location_list"),
Expand All @@ -124,8 +122,7 @@ def test_definition_return_location_list(client_server):
@ConfiguredLS.decorate()
def test_definition_return_location_link_list(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_DEFINITION,
response = client.text_document_definition(
DefinitionParams(
text_document=TextDocumentIdentifier(
uri="file://return.location_link_list"
Expand Down Expand Up @@ -155,8 +152,7 @@ def test_definition_return_location_link_list(client_server):
@ConfiguredLS.decorate()
def test_definition_return_none(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_DEFINITION,
response = client.text_document_definition(
DefinitionParams(
text_document=TextDocumentIdentifier(uri="file://return.none"),
position=Position(line=0, character=0),
Expand Down
3 changes: 1 addition & 2 deletions tests/lsp/test_document_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ def test_capabilities(client_server):
@ConfiguredLS.decorate()
def test_document_color(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_DOCUMENT_COLOR,
response = client.text_document_document_color(
DocumentColorParams(
text_document=TextDocumentIdentifier(uri="file://return.list")
),
Expand Down
6 changes: 2 additions & 4 deletions tests/lsp/test_document_highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ def test_capabilities(client_server):
@ConfiguredLS.decorate()
def test_document_highlight_return_list(client_server):
client, _ = client_server
response = client.lsp.send_request(
TEXT_DOCUMENT_DOCUMENT_HIGHLIGHT,
response = client.text_document_document_highlight(
DocumentHighlightParams(
text_document=TextDocumentIdentifier(uri="file://return.list"),
position=Position(line=0, character=0),
Expand All @@ -99,8 +98,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(
TEXT_DOCUMENT_DOCUMENT_HIGHLIGHT,
response = client.text_document_document_highlight(
DocumentHighlightParams(
text_document=TextDocumentIdentifier(uri="file://return.none"),
position=Position(line=0, character=0),
Expand Down
Loading

0 comments on commit d164ebf

Please sign in to comment.