Skip to content

Commit

Permalink
this file is needed
Browse files Browse the repository at this point in the history
  • Loading branch information
predragnikolic committed Mar 21, 2024
1 parent df2f3d4 commit d8d941f
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions tests/test_mocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from LSP.plugin.core.logging import debug
from LSP.plugin.core.protocol import Notification
from LSP.plugin.core.protocol import Request
from LSP.plugin.core.protocol import Response
from LSP.plugin.core.types import ClientConfig
from LSP.plugin.core.typing import List, Any, Callable


TEST_CONFIG = ClientConfig(name="test", command=[], selector="text.plain", tcp_port=None)
DISABLED_CONFIG = ClientConfig("test", command=[], selector="text.plain", tcp_port=None, enabled=False)

basic_responses = {
'initialize': {
'capabilities': {
'testing': True,
'hoverProvider': True,
'completionProvider': {
'triggerCharacters': ['.'],
'resolveProvider': True
},
'textDocumentSync': {
"openClose": True,
"change": 2,
"save": True
},
'definitionProvider': True,
'typeDefinitionProvider': True,
'declarationProvider': True,
'implementationProvider': True,
'documentFormattingProvider': True,
'selectionRangeProvider': True,
'renameProvider': True,
'workspace': {
'workspaceFolders': {
'supported': True
}
}
}
}
}


class MockSession(object):
def __init__(self, async_response=None) -> None:
self.responses = basic_responses
self._notifications = [] # type: List[Notification]
self._async_response_callback = async_response

def send_request(self, request: Request, on_success: Callable, on_error: Callable = None) -> None:
response = self.responses.get(request.method)
debug("TEST: responding to", request.method, "with", response)
if self._async_response_callback:
self._async_response_callback(lambda: on_success(response))
else:
on_success(response)

def execute_request(self, request: Request) -> Any:
return self.responses.get(request.method)

def send_notification(self, notification: Notification) -> None:
self._notifications.append(notification)

def on_notification(self, name, handler: Callable) -> None:
pass

def on_request(self, name, handler: Callable) -> None:
pass

def set_error_display_handler(self, handler: Callable) -> None:
pass

def set_crash_handler(self, handler: Callable) -> None:
pass

def set_log_payload_handler(self, handler: Callable) -> None:
pass

def exit(self) -> None:
pass

def send_response(self, response: Response) -> None:
pass

0 comments on commit d8d941f

Please sign in to comment.