generated from itdominator/Python-With-Gtk-Template
lsp manager plugin updates
This commit is contained in:
parent
b31278e114
commit
693f569d4f
|
@ -24,6 +24,7 @@ class ClientIPC:
|
||||||
self._ipc_authkey = b'' + bytes(f'lsp-client-endpoint-ipc', 'utf-8')
|
self._ipc_authkey = b'' + bytes(f'lsp-client-endpoint-ipc', 'utf-8')
|
||||||
self._manager_ipc_authkey = b'' + bytes(f'lsp-manager-endpoint-ipc', 'utf-8')
|
self._manager_ipc_authkey = b'' + bytes(f'lsp-manager-endpoint-ipc', 'utf-8')
|
||||||
self._ipc_timeout = 15.0
|
self._ipc_timeout = 15.0
|
||||||
|
self._event_system = None
|
||||||
|
|
||||||
if conn_type == "socket":
|
if conn_type == "socket":
|
||||||
self._ipc_address = f'/tmp/lsp-client-endpoint-ipc.sock'
|
self._ipc_address = f'/tmp/lsp-client-endpoint-ipc.sock'
|
||||||
|
@ -37,6 +38,9 @@ class ClientIPC:
|
||||||
self._ipc_authkey = None
|
self._ipc_authkey = None
|
||||||
|
|
||||||
|
|
||||||
|
def set_event_system(self, event_system):
|
||||||
|
self._event_system = event_system
|
||||||
|
|
||||||
def create_ipc_listener(self) -> None:
|
def create_ipc_listener(self) -> None:
|
||||||
if self._conn_type == "socket":
|
if self._conn_type == "socket":
|
||||||
if os.path.exists(self._ipc_address) and settings_manager.is_dirty_start():
|
if os.path.exists(self._ipc_address) and settings_manager.is_dirty_start():
|
||||||
|
@ -68,27 +72,27 @@ class ClientIPC:
|
||||||
def _handle_ipc_message(self, conn, start_time) -> None:
|
def _handle_ipc_message(self, conn, start_time) -> None:
|
||||||
while self.is_ipc_alive:
|
while self.is_ipc_alive:
|
||||||
msg = conn.recv()
|
msg = conn.recv()
|
||||||
logger.debug(msg)
|
|
||||||
|
|
||||||
if "MANAGER|" in msg:
|
if "MANAGER|" in msg:
|
||||||
data = msg.split("MANAGER|")[1].strip()
|
data = msg.split("MANAGER|")[1].strip()
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
data_str = base64.b64decode(data.encode("utf-8")).decode("utf-8")
|
data_str = base64.b64decode(data.encode("utf-8")).decode("utf-8")
|
||||||
lsp_response = None
|
lsp_response = None
|
||||||
keys = None
|
keys = None
|
||||||
|
|
||||||
|
logger.debug(data_str)
|
||||||
try:
|
try:
|
||||||
lsp_response = json.loads(data_str)
|
lsp_response = json.loads(data_str)
|
||||||
keys = lsp_response.keys()
|
keys = lsp_response.keys()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug( repr(e) )
|
raise e
|
||||||
break
|
|
||||||
|
|
||||||
if "result" in keys:
|
if "result" in keys:
|
||||||
lsp_response = LSPResponseRequest(**get_message_obj(data))
|
lsp_response = LSPResponseRequest(**get_message_obj(data_str))
|
||||||
|
|
||||||
if "method" in keys:
|
if "method" in keys:
|
||||||
lsp_response = LSPResponseNotification(**get_message_obj(data))
|
lsp_response = LSPResponseNotification(**get_message_obj(data_str))
|
||||||
|
|
||||||
if "notification" in keys:
|
if "notification" in keys:
|
||||||
...
|
...
|
||||||
|
@ -100,7 +104,7 @@ class ClientIPC:
|
||||||
...
|
...
|
||||||
|
|
||||||
if lsp_response:
|
if lsp_response:
|
||||||
self._event_system.emit("handle-lsp-message"), (lsp_response)
|
self._event_system.emit("handle-lsp-message", (lsp_response,))
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
break
|
break
|
||||||
|
|
|
@ -41,7 +41,7 @@ class Plugin(PluginBase):
|
||||||
box2 = Gtk.Box()
|
box2 = Gtk.Box()
|
||||||
start_btn = Gtk.Button(label = "Start LSP Manager")
|
start_btn = Gtk.Button(label = "Start LSP Manager")
|
||||||
stop_btn = Gtk.Button(label = "Stop LSP Manager")
|
stop_btn = Gtk.Button(label = "Stop LSP Manager")
|
||||||
pid_label = Gtk.Label(label = "LSP PID: ")
|
pid_label = Gtk.Label(label = "LSP PID: ")
|
||||||
|
|
||||||
box1.set_orientation( Gtk.Orientation.VERTICAL )
|
box1.set_orientation( Gtk.Orientation.VERTICAL )
|
||||||
|
|
||||||
|
@ -83,8 +83,8 @@ class Plugin(PluginBase):
|
||||||
self._event_system.subscribe("shutting_down", self._shutting_down)
|
self._event_system.subscribe("shutting_down", self._shutting_down)
|
||||||
|
|
||||||
self._event_system.subscribe("textDocument/didOpen", self._lsp_did_open)
|
self._event_system.subscribe("textDocument/didOpen", self._lsp_did_open)
|
||||||
# self._event_system.subscribe("textDocument/didSave", self._lsp_did_save)
|
self._event_system.subscribe("textDocument/didSave", self._lsp_did_save)
|
||||||
# self._event_system.subscribe("textDocument/didClose", self._lsp_did_close)
|
self._event_system.subscribe("textDocument/didClose", self._lsp_did_close)
|
||||||
self._event_system.subscribe("textDocument/didChange", self._lsp_did_change)
|
self._event_system.subscribe("textDocument/didChange", self._lsp_did_change)
|
||||||
self._event_system.subscribe("textDocument/definition", self._lsp_goto)
|
self._event_system.subscribe("textDocument/definition", self._lsp_goto)
|
||||||
self._event_system.subscribe("textDocument/completion", self._lsp_completion)
|
self._event_system.subscribe("textDocument/completion", self._lsp_completion)
|
||||||
|
@ -97,6 +97,7 @@ class Plugin(PluginBase):
|
||||||
|
|
||||||
def _load_client_ipc_server(self):
|
def _load_client_ipc_server(self):
|
||||||
self.client_ipc = ClientIPC()
|
self.client_ipc = ClientIPC()
|
||||||
|
self.client_ipc.set_event_system(self._event_system)
|
||||||
self._ipc_realization_check(self.client_ipc)
|
self._ipc_realization_check(self.client_ipc)
|
||||||
|
|
||||||
if not self.client_ipc.is_ipc_alive:
|
if not self.client_ipc.is_ipc_alive:
|
||||||
|
@ -123,13 +124,14 @@ class Plugin(PluginBase):
|
||||||
self.client_ipc.is_ipc_alive = False
|
self.client_ipc.is_ipc_alive = False
|
||||||
self.lsp_manager_proc = None
|
self.lsp_manager_proc = None
|
||||||
|
|
||||||
def _lsp_did_open(self, language_id, uri, text):
|
def _lsp_did_open(self, language_id: str, uri: str, text: str):
|
||||||
if not self.lsp_manager_proc: return
|
if not self.lsp_manager_proc: return
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"method": "textDocument/didOpen",
|
"method": "textDocument/didOpen",
|
||||||
"language_id": language_id,
|
"language_id": language_id,
|
||||||
"uri": uri,
|
"uri": uri,
|
||||||
|
"version": -1,
|
||||||
"text": text,
|
"text": text,
|
||||||
"line": -1,
|
"line": -1,
|
||||||
"column": -1,
|
"column": -1,
|
||||||
|
@ -138,13 +140,39 @@ class Plugin(PluginBase):
|
||||||
|
|
||||||
self.send_message(data)
|
self.send_message(data)
|
||||||
|
|
||||||
def _lsp_did_save(self):
|
def _lsp_did_save(self, uri: str, text: str):
|
||||||
if not self.lsp_manager_proc: return
|
if not self.lsp_manager_proc: return
|
||||||
|
|
||||||
def _lsp_did_close(self):
|
data = {
|
||||||
|
"method": "textDocument/didSave",
|
||||||
|
"language_id": "",
|
||||||
|
"uri": uri,
|
||||||
|
"version": -1,
|
||||||
|
"text": text,
|
||||||
|
"line": -1,
|
||||||
|
"column": -1,
|
||||||
|
"char": ""
|
||||||
|
}
|
||||||
|
|
||||||
|
self.send_message(data)
|
||||||
|
|
||||||
|
def _lsp_did_close(self, uri: str):
|
||||||
if not self.lsp_manager_proc: return
|
if not self.lsp_manager_proc: return
|
||||||
|
|
||||||
def _lsp_did_change(self, language_id, uri, buffer):
|
data = {
|
||||||
|
"method": "textDocument/didClose",
|
||||||
|
"language_id": "",
|
||||||
|
"uri": uri,
|
||||||
|
"version": -1,
|
||||||
|
"text": "",
|
||||||
|
"line": -1,
|
||||||
|
"column": -1,
|
||||||
|
"char": ""
|
||||||
|
}
|
||||||
|
|
||||||
|
self.send_message(data)
|
||||||
|
|
||||||
|
def _lsp_did_change(self, language_id: str, uri: str, buffer):
|
||||||
if not self.lsp_manager_proc: return
|
if not self.lsp_manager_proc: return
|
||||||
|
|
||||||
iter = buffer.get_iter_at_mark( buffer.get_insert() )
|
iter = buffer.get_iter_at_mark( buffer.get_insert() )
|
||||||
|
@ -162,6 +190,7 @@ class Plugin(PluginBase):
|
||||||
"method": "textDocument/didChange",
|
"method": "textDocument/didChange",
|
||||||
"language_id": language_id,
|
"language_id": language_id,
|
||||||
"uri": uri,
|
"uri": uri,
|
||||||
|
"version": buffer.version_id,
|
||||||
"text": text,
|
"text": text,
|
||||||
"line": line,
|
"line": line,
|
||||||
"column": column,
|
"column": column,
|
||||||
|
@ -170,13 +199,14 @@ class Plugin(PluginBase):
|
||||||
|
|
||||||
self.send_message(data)
|
self.send_message(data)
|
||||||
|
|
||||||
def _lsp_goto(self, language_id, uri, line, column):
|
def _lsp_goto(self, language_id: str, uri: str, line: int, column: int):
|
||||||
if not self.lsp_manager_proc: return
|
if not self.lsp_manager_proc: return
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"method": "textDocument/definition",
|
"method": "textDocument/definition",
|
||||||
"language_id": language_id,
|
"language_id": language_id,
|
||||||
"uri": uri,
|
"uri": uri,
|
||||||
|
"version": -1,
|
||||||
"text": "",
|
"text": "",
|
||||||
"line": line,
|
"line": line,
|
||||||
"column": column,
|
"column": column,
|
||||||
|
@ -205,6 +235,7 @@ class Plugin(PluginBase):
|
||||||
"method": "textDocument/completion",
|
"method": "textDocument/completion",
|
||||||
"language_id": source_view.get_filetype(),
|
"language_id": source_view.get_filetype(),
|
||||||
"uri": uri,
|
"uri": uri,
|
||||||
|
"version": buffer.version_id,
|
||||||
"text": "",
|
"text": "",
|
||||||
"line": line,
|
"line": line,
|
||||||
"column": column,
|
"column": column,
|
||||||
|
|
Loading…
Reference in New Issue