Initial wiring of client calls and responses
This commit is contained in:
@@ -67,4 +67,3 @@ class BaseController(IPCSignalsMixin, KeyboardSignalsMixin, BaseControllerData):
|
||||
self.base_container = BaseContainer()
|
||||
|
||||
settings_manager.register_signals_to_builder([self, self.base_container])
|
||||
|
||||
|
@@ -3,13 +3,16 @@ import os
|
||||
import signal
|
||||
import subprocess
|
||||
import threading
|
||||
import json
|
||||
|
||||
# Lib imports
|
||||
from gi.repository import GLib
|
||||
|
||||
# Application imports
|
||||
from libs.dto.lsp_messages import LEN_HEADER, TYPE_HEADER, get_message_str, get_message_obj, definition_query, references_query, symbols_query
|
||||
from libs.dto.lsp_message_structs import ClientRequest, ClientNotification, LSPResponse
|
||||
from libs.dto.lsp_message_structs import \
|
||||
LSPResponseTypes, ClientRequest, ClientNotification, LSPResponseRequest, LSPResponseNotification
|
||||
from .lsp_controller_events import LSPControllerEvents
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +25,7 @@ def _log_list():
|
||||
|
||||
|
||||
|
||||
class LSPController:
|
||||
class LSPController(LSPControllerEvents):
|
||||
def __init__(self):
|
||||
super(LSPController).__init__()
|
||||
|
||||
@@ -45,8 +48,15 @@ class LSPController:
|
||||
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("client-send-request", self._client_send_request)
|
||||
event_system.subscribe("client-send-notification", self._client_send_notification)
|
||||
# event_system.subscribe("client-send-request", self._client_send_request)
|
||||
# event_system.subscribe("client-send-notification", self._client_send_notification)
|
||||
|
||||
event_system.subscribe("textDocument/didOpen", self._lsp_did_open)
|
||||
# event_system.subscribe("textDocument/didSave", self._lsp_did_save)
|
||||
# event_system.subscribe("textDocument/didClose", self._lsp_did_close)
|
||||
event_system.subscribe("textDocument/didChange", self._lsp_did_change)
|
||||
event_system.subscribe("textDocument/definition", self._lsp_goto)
|
||||
event_system.subscribe("textDocument/completion", self._lsp_completion)
|
||||
|
||||
def _client_send_request(self, method: str, uri: str, line: int, character: int):
|
||||
if not method: return
|
||||
@@ -148,7 +158,8 @@ class LSPController:
|
||||
except Exception as e:
|
||||
self.log_list.add_log_entry(
|
||||
"LSP Client Error",
|
||||
LSPResponse(
|
||||
LSPResponseRequest(
|
||||
"2.0",
|
||||
None,
|
||||
{
|
||||
"error": repr(e)
|
||||
@@ -177,7 +188,7 @@ class LSPController:
|
||||
message_size = None
|
||||
while True:
|
||||
line = self.lsp_process.stdout.readline()
|
||||
if not line: return None # Quit listener...
|
||||
if not line: return None # Quit listener...
|
||||
|
||||
line = line.decode("utf-8")
|
||||
if not line.endswith("\r\n"):
|
||||
@@ -207,41 +218,23 @@ class LSPController:
|
||||
|
||||
if not message_size: return
|
||||
|
||||
data = self.lsp_process.stdout.read(message_size)
|
||||
jsonrpc_res = data.decode("utf-8")
|
||||
lsp_response = LSPResponse(**get_message_obj(jsonrpc_res))
|
||||
_data = self.lsp_process.stdout.read(message_size)
|
||||
data = _data.decode("utf-8")
|
||||
message = get_message_obj(data)
|
||||
keys = message.keys()
|
||||
lsp_response = None
|
||||
|
||||
if "result" in keys:
|
||||
lsp_response = LSPResponseRequest(**get_message_obj(data))
|
||||
|
||||
if "method" in keys:
|
||||
lsp_response = LSPResponseNotification(**get_message_obj(data))
|
||||
|
||||
response_id = -1
|
||||
|
||||
if not lsp_response: return
|
||||
GLib.idle_add(self.handle_lsp_response, lsp_response)
|
||||
|
||||
def handle_lsp_response(self, lsp_response: LSPResponse):
|
||||
method = self.request_list[lsp_response.id]
|
||||
result = lsp_response.result
|
||||
|
||||
def handle_lsp_response(self, lsp_response: LSPResponseTypes):
|
||||
self.log_list.add_log_entry("LSP Response", lsp_response)
|
||||
self.process_lsp_response(method, result)
|
||||
|
||||
def process_lsp_response(self, method, result):
|
||||
if isinstance(result, dict):
|
||||
keys = result.keys()
|
||||
return
|
||||
if "error" in keys:
|
||||
error = result["error"]
|
||||
logger.debug(f"LSP Error Code: {error['code']}")
|
||||
logger.debug(f"LSP Error Message:\n{error['message']}")
|
||||
return
|
||||
|
||||
if "result" in keys:
|
||||
result = result["result"]
|
||||
|
||||
if isinstance(result, dict):
|
||||
keys = result.keys()
|
||||
if "capabilities" in keys:
|
||||
...
|
||||
|
||||
if isinstance(result, list):
|
||||
...
|
||||
|
||||
if isinstance(result, tuple):
|
||||
...
|
||||
event_system.emit("respond-to-client", (get_message_str(lsp_response),))
|
||||
|
59
src/core/controllers/lsp_controller_events.py
Normal file
59
src/core/controllers/lsp_controller_events.py
Normal file
@@ -0,0 +1,59 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
from gi.repository import GLib
|
||||
|
||||
# Application imports
|
||||
# from libs.dto.lsp_messages import LEN_HEADER, TYPE_HEADER, get_message_str, get_message_obj, definition_query, references_query, symbols_query
|
||||
from libs.dto.lsp_messages import didopen_notification
|
||||
|
||||
|
||||
|
||||
class LSPControllerEvents:
|
||||
def _lsp_did_open(self, data: dict):
|
||||
method = data["method"]
|
||||
params = didopen_notification["params"]
|
||||
|
||||
params["textDocument"]["uri"] = data["uri"]
|
||||
params["textDocument"]["languageId"] = data["language_id"]
|
||||
params["textDocument"]["text"] = data["text"]
|
||||
|
||||
GLib.idle_add( self.send_notification, method, params )
|
||||
|
||||
def _lsp_did_save(self, data: dict):
|
||||
# self.send_notification(method, params)
|
||||
...
|
||||
|
||||
def _lsp_did_close(self, data: dict):
|
||||
# self.send_notification(method, params)
|
||||
...
|
||||
|
||||
def _lsp_did_change(self, data: dict):
|
||||
method = data["method"]
|
||||
language_id = data["language_id"]
|
||||
uri = data["uri"]
|
||||
text = data["text"]
|
||||
line = data["line"]
|
||||
column = data["column"]
|
||||
|
||||
self.send_notification(method, params)
|
||||
# return "{'notification':'some kind of response'}"
|
||||
|
||||
def _lsp_goto(self, data: dict):
|
||||
method = data["method"]
|
||||
language_id = data["language_id"]
|
||||
uri = data["uri"]
|
||||
line = data["line"]
|
||||
column = data["column"]
|
||||
|
||||
self._client_send_request(method, uri, line, column)
|
||||
# return "{'response':'some kind of response'}"
|
||||
|
||||
def _lsp_completion(self, data: dict):
|
||||
method = data["method"]
|
||||
language_id = data["language_id"]
|
||||
uri = data["uri"]
|
||||
line = data["line"]
|
||||
column = data["column"]
|
||||
|
||||
# self._client_send_request(method, uri, line, column)
|
Reference in New Issue
Block a user