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._manager_ipc_authkey = b'' + bytes(f'lsp-manager-endpoint-ipc', 'utf-8')
|
||||
self._ipc_timeout = 15.0
|
||||
self._event_system = None
|
||||
|
||||
if conn_type == "socket":
|
||||
self._ipc_address = f'/tmp/lsp-client-endpoint-ipc.sock'
|
||||
@ -37,6 +38,9 @@ class ClientIPC:
|
||||
self._ipc_authkey = None
|
||||
|
||||
|
||||
def set_event_system(self, event_system):
|
||||
self._event_system = event_system
|
||||
|
||||
def create_ipc_listener(self) -> None:
|
||||
if self._conn_type == "socket":
|
||||
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:
|
||||
while self.is_ipc_alive:
|
||||
msg = conn.recv()
|
||||
logger.debug(msg)
|
||||
|
||||
if "MANAGER|" in msg:
|
||||
data = msg.split("MANAGER|")[1].strip()
|
||||
|
||||
if data:
|
||||
data_str = base64.b64decode(data.encode("utf-8")).decode("utf-8")
|
||||
lsp_response = None
|
||||
keys = None
|
||||
|
||||
logger.debug(data_str)
|
||||
try:
|
||||
lsp_response = json.loads(data_str)
|
||||
keys = lsp_response.keys()
|
||||
except Exception as e:
|
||||
logger.debug( repr(e) )
|
||||
break
|
||||
raise e
|
||||
|
||||
if "result" in keys:
|
||||
lsp_response = LSPResponseRequest(**get_message_obj(data))
|
||||
lsp_response = LSPResponseRequest(**get_message_obj(data_str))
|
||||
|
||||
if "method" in keys:
|
||||
lsp_response = LSPResponseNotification(**get_message_obj(data))
|
||||
lsp_response = LSPResponseNotification(**get_message_obj(data_str))
|
||||
|
||||
if "notification" in keys:
|
||||
...
|
||||
@ -100,7 +104,7 @@ class ClientIPC:
|
||||
...
|
||||
|
||||
if lsp_response:
|
||||
self._event_system.emit("handle-lsp-message"), (lsp_response)
|
||||
self._event_system.emit("handle-lsp-message", (lsp_response,))
|
||||
|
||||
conn.close()
|
||||
break
|
||||
@ -165,4 +169,4 @@ class ClientIPC:
|
||||
logger.error("LSP Socket no longer valid.... Removing.")
|
||||
os.unlink(self._ipc_address)
|
||||
except Exception as e:
|
||||
logger.error( repr(e) )
|
||||
logger.error( repr(e) )
|
||||
|
@ -41,7 +41,7 @@ class Plugin(PluginBase):
|
||||
box2 = Gtk.Box()
|
||||
start_btn = Gtk.Button(label = "Start 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 )
|
||||
|
||||
@ -83,8 +83,8 @@ class Plugin(PluginBase):
|
||||
self._event_system.subscribe("shutting_down", self._shutting_down)
|
||||
|
||||
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/didClose", self._lsp_did_close)
|
||||
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/didChange", self._lsp_did_change)
|
||||
self._event_system.subscribe("textDocument/definition", self._lsp_goto)
|
||||
self._event_system.subscribe("textDocument/completion", self._lsp_completion)
|
||||
@ -97,6 +97,7 @@ class Plugin(PluginBase):
|
||||
|
||||
def _load_client_ipc_server(self):
|
||||
self.client_ipc = ClientIPC()
|
||||
self.client_ipc.set_event_system(self._event_system)
|
||||
self._ipc_realization_check(self.client_ipc)
|
||||
|
||||
if not self.client_ipc.is_ipc_alive:
|
||||
@ -123,13 +124,14 @@ class Plugin(PluginBase):
|
||||
self.client_ipc.is_ipc_alive = False
|
||||
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
|
||||
|
||||
data = {
|
||||
"method": "textDocument/didOpen",
|
||||
"language_id": language_id,
|
||||
"uri": uri,
|
||||
"version": -1,
|
||||
"text": text,
|
||||
"line": -1,
|
||||
"column": -1,
|
||||
@ -138,13 +140,39 @@ class Plugin(PluginBase):
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
iter = buffer.get_iter_at_mark( buffer.get_insert() )
|
||||
@ -162,6 +190,7 @@ class Plugin(PluginBase):
|
||||
"method": "textDocument/didChange",
|
||||
"language_id": language_id,
|
||||
"uri": uri,
|
||||
"version": buffer.version_id,
|
||||
"text": text,
|
||||
"line": line,
|
||||
"column": column,
|
||||
@ -170,13 +199,14 @@ class Plugin(PluginBase):
|
||||
|
||||
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
|
||||
|
||||
data = {
|
||||
"method": "textDocument/definition",
|
||||
"language_id": language_id,
|
||||
"uri": uri,
|
||||
"version": -1,
|
||||
"text": "",
|
||||
"line": line,
|
||||
"column": column,
|
||||
@ -205,6 +235,7 @@ class Plugin(PluginBase):
|
||||
"method": "textDocument/completion",
|
||||
"language_id": source_view.get_filetype(),
|
||||
"uri": uri,
|
||||
"version": buffer.version_id,
|
||||
"text": "",
|
||||
"line": line,
|
||||
"column": column,
|
||||
@ -214,4 +245,4 @@ class Plugin(PluginBase):
|
||||
self.send_message(data)
|
||||
|
||||
def send_message(self, data: dict):
|
||||
self.client_ipc.send_manager_ipc_message( json.dumps(data) )
|
||||
self.client_ipc.send_manager_ipc_message( json.dumps(data) )
|
||||
|
Loading…
Reference in New Issue
Block a user