From 46d358aab73205036ccf186ce3c32942b5443500 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Fri, 20 Sep 2024 01:45:41 -0500 Subject: [PATCH] fixed goto/definition with full text transfer; cleanup --- .../gtksourceview/lsp_client/client_ipc.py | 11 ++++- plugins/gtksourceview/lsp_client/plugin.py | 48 ++++++++++++++----- 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/plugins/gtksourceview/lsp_client/client_ipc.py b/plugins/gtksourceview/lsp_client/client_ipc.py index 795ef28..f511abd 100644 --- a/plugins/gtksourceview/lsp_client/client_ipc.py +++ b/plugins/gtksourceview/lsp_client/client_ipc.py @@ -1,4 +1,5 @@ # Python imports +import traceback import os import threading import time @@ -12,7 +13,9 @@ import gi from gi.repository import GLib # Application imports -from .lsp_message_structs import LSPResponseRequest, LSPResponseNotification, get_message_obj +from .lsp_message_structs import LSPResponseRequest +from .lsp_message_structs import LSPResponseNotification +from .lsp_message_structs import get_message_obj @@ -126,13 +129,17 @@ class ClientIPC: def send_manager_ipc_message(self, message: str) -> None: try: if self._conn_type == "socket": + if not os.path.exists(self._manager_ipc_address): + logger.error(f"Socket: {self._manager_ipc_address} doesn't exist. NOT sending message...") + return + conn = Client(address=self._manager_ipc_address, family="AF_UNIX", authkey=self._manager_ipc_authkey) elif "unsecured" not in self._conn_type: conn = Client((self._ipc_address, self._ipc_port), authkey=self._ipc_authkey) else: conn = Client((self._ipc_address, self._ipc_port)) - conn.send( f"CLIENT|{ base64.b64encode(message.encode("utf-8")).decode("utf-8") }" ) + conn.send( f"CLIENT|{ base64.b64encode(message.encode('utf-8')).decode('utf-8') }" ) conn.close() except ConnectionRefusedError as e: logger.error("Connection refused...") diff --git a/plugins/gtksourceview/lsp_client/plugin.py b/plugins/gtksourceview/lsp_client/plugin.py index 4def8c3..cab6c38 100644 --- a/plugins/gtksourceview/lsp_client/plugin.py +++ b/plugins/gtksourceview/lsp_client/plugin.py @@ -175,17 +175,13 @@ class Plugin(PluginBase): def _lsp_did_change(self, language_id: str, uri: str, buffer): if not self.lsp_client_proc: return - iter = buffer.get_iter_at_mark( buffer.get_insert() ) - line = iter.get_line() - column = iter.get_line_offset() - start = iter.copy() - end = iter.copy() + iter = buffer.get_iter_at_mark( buffer.get_insert() ) + line = iter.get_line() + column = iter.get_line_offset() - start.backward_line() - start.forward_line() - end.forward_to_line_end() + start, end = buffer.get_bounds() - text = buffer.get_text(start, end, include_hidden_chars = False) + text = buffer.get_text(start, end, include_hidden_chars = True) data = { "method": "textDocument/didChange", "language_id": language_id, @@ -199,6 +195,35 @@ class Plugin(PluginBase): self.send_message(data) + +# def _lsp_did_change(self, language_id: str, uri: str, buffer): +# if not self.lsp_client_proc: return + +# iter = buffer.get_iter_at_mark( buffer.get_insert() ) +# line = iter.get_line() +# column = iter.get_line_offset() +# start = iter.copy() +# end = iter.copy() + +# start.backward_line() +# start.forward_line() +# end.forward_line() + +# text = buffer.get_text(start, end, include_hidden_chars = True) +# data = { +# "method": "textDocument/didChange", +# "language_id": language_id, +# "uri": uri, +# "version": buffer.version_id, +# "text": text, +# "line": line, +# "column": column, +# "char": "" +# } + +# self.send_message(data) + + def _lsp_goto(self, language_id: str, uri: str, line: int, column: int): if not self.lsp_client_proc: return @@ -225,12 +250,9 @@ class Plugin(PluginBase): buffer = source_view.get_buffer() iter = buffer.get_iter_at_mark( buffer.get_insert() ) line = iter.get_line() - + column = iter.get_line_offset() char = iter.get_char() - if iter.backward_char(): - char = iter.get_char() - column = iter.get_line_offset() data = { "method": "textDocument/completion", "language_id": source_view.get_filetype(),