added basic lsp message logging view

This commit is contained in:
itdominator 2024-09-06 22:57:10 -05:00
parent 4b07816777
commit 6b99c5c0d7
9 changed files with 104 additions and 26 deletions

View File

@ -26,6 +26,8 @@ class TopButtonBox(Gtk.ButtonBox):
ctx = self.get_style_context()
ctx.add_class("top-button-box")
self.set_homogeneous(True)
def _setup_signals(self):
...
@ -33,13 +35,15 @@ class TopButtonBox(Gtk.ButtonBox):
...
def _load_widgets(self):
box = Gtk.Box()
self.message_id_lbl = Gtk.Label(label = "Message ID: 0")
self.folder_choser_lbl = Gtk.Label(label = "Workspace Folder:")
self.folder_choser_lbl = Gtk.Label(label = "Workspace Folder: ")
self.folder_choser_btn = FolderChoserButton()
self.add(self.message_id_lbl)
self.add(self.folder_choser_lbl)
self.add(self.folder_choser_btn)
box.add(self.folder_choser_lbl)
box.add(self.folder_choser_btn)
self.add(box)
def update_message_id_lbl(self, id: int):
self.message_id_lbl.set_label(f"Message ID: {id}")

View File

@ -27,7 +27,6 @@ class AltCommandEntry(Gtk.Entry):
ctx = self.get_style_context()
ctx.add_class("alt-command-entry")
self.set_hexpand(True)
self.set_placeholder_text("Alt Command:")
def _setup_signals(self):
@ -38,4 +37,3 @@ class AltCommandEntry(Gtk.Entry):
def _load_widgets(self):
...

View File

@ -27,7 +27,6 @@ class CommandEntry(Gtk.Entry):
ctx = self.get_style_context()
ctx.add_class("command-entry")
self.set_hexpand(True)
self.set_placeholder_text("Command:")
def _setup_signals(self):
@ -38,4 +37,3 @@ class CommandEntry(Gtk.Entry):
def _load_widgets(self):
...

View File

@ -34,7 +34,6 @@ class InitOptionsSourceView(GtkSource.View):
ctx = self.get_style_context()
self.set_vexpand(True)
self.set_hexpand(True)
self.set_indent_width(4)
self.set_tab_width(4)
self.set_insert_spaces_instead_of_tabs(True)

View File

@ -88,7 +88,6 @@ class LspMessageSourceView(GtkSource.View):
ctx = self.get_style_context()
self.set_vexpand(True)
self.set_hexpand(True)
self.set_indent_width(4)
self.set_tab_width(4)
self.set_insert_spaces_instead_of_tabs(True)

View File

@ -27,7 +27,6 @@ class SocketEntry(Gtk.Entry):
ctx = self.get_style_context()
ctx.add_class("socket-entry")
self.set_hexpand(True)
self.set_placeholder_text("Socket:")
def _setup_signals(self):
@ -38,4 +37,3 @@ class SocketEntry(Gtk.Entry):
def _load_widgets(self):
...

View File

@ -0,0 +1,65 @@
# Python imports
import json
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
class LogList(Gtk.ListBox):
def __init__(self):
super(LogList, self).__init__()
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
self.show_all()
def _setup_styling(self):
ctx = self.get_style_context()
ctx.add_class("log-list-listbox")
self.set_placeholder( Gtk.Label(label="Empty Log List...") )
self.set_selection_mode(Gtk.SelectionMode.NONE)
def _setup_signals(self):
# self.connect("row-activated", sink_call)
# self.connect("row-selected", sink_call)
...
def _subscribe_to_events(self):
...
def _load_widgets(self):
...
def add_log_entry(self, data: str or dict):
message = None
if isinstance(data, str):
parts = data.split("\n", 2)
jsonStr = parts[2]
messageStr = json.dumps(json.loads(jsonStr), separators = (',', ':'), indent = 4)
message = f"{parts[0]}\r\n\r\n{messageStr}"
if isinstance(data, dict):
message = json.dumps(data, separators = (',', ':'), indent = 4)
box = Gtk.Frame()
label = Gtk.Label(label=message)
label.set_xalign(0.010)
box.set_label(">")
box.set_label_align(0.010, 0.5)
box.add(label)
self.add(box)
box.show_all()

View File

@ -154,6 +154,9 @@ class LSPMessageBox(Gtk.Box):
message_size = len(message_str)
message = f"Content-Length: {message_size}\r\n\r\n{message_str}"
self.get_parent().log_list.add_log_entry(message)
event_system.subscribe("add-log-entry", message)
with self.write_lock:
self.lsp_process.stdin.write( message.encode("utf-8") )
self.lsp_process.stdin.flush()
@ -258,6 +261,8 @@ class LSPMessageBox(Gtk.Box):
GLib.idle_add(self.handle_lsp_response, response_id, lsp_result)
def handle_lsp_response(self, id: int, lsp_result: {}):
self.get_parent().log_list.add_log_entry(lsp_result)
keys = lsp_result.keys()
if "error" in keys:
lsp_result = lsp_result["error"]

View File

@ -12,6 +12,7 @@ from .enteries.command_entry import CommandEntry
from .enteries.socket_entry import SocketEntry
from .enteries.init_options_source_view import InitOptionsSourceView
from .buttons.info_link_button import InfoLinkButton
from .log_list import LogList
@ -48,12 +49,16 @@ class LSPUI(Gtk.Grid):
...
def _load_widgets(self):
scrolled_win = Gtk.ScrolledWindow()
scrolled_win1 = Gtk.ScrolledWindow()
scrolled_win2 = Gtk.ScrolledWindow()
self.log_list = LogList()
alt_command_lbl = Gtk.Label(label="Alt Command:")
command_lbl = Gtk.Label(label="Command:")
socket_lbl = Gtk.Label(label="Socket:")
init_options_lbl = Gtk.Label(label="Initialization Options:")
message_box_lbl = Gtk.Label(label="Message Box:")
init_options_lbl = Gtk.Label(label="Initialization Options")
message_box_lbl = Gtk.Label(label="Message Box")
log_list_lbl = Gtk.Label(label="Logs")
self.link_btn = InfoLinkButton(self._language.title(), self._data["info"])
self.alt_command_entry = AltCommandEntry( self._data["alt-command"] )
@ -64,22 +69,29 @@ class LSPUI(Gtk.Grid):
init_options_lbl.set_margin_top(10)
message_box_lbl.set_margin_top(10)
log_list_lbl.set_margin_top(10)
log_list_lbl.set_margin_bottom(10)
scrolled_win2.set_size_request(320, -1)
scrolled_win.add(self.init_ops_src_vw)
scrolled_win1.add(self.init_ops_src_vw)
scrolled_win2.add(self.log_list)
# child, left, top, width, height
self.attach(self.link_btn, 0, 0, 3, 1)
self.attach(self.link_btn, 0, 0, 3, 1)
self.attach(alt_command_lbl, 0, 1, 1, 1)
self.attach(command_lbl, 0, 2, 1, 1)
self.attach(socket_lbl, 0, 3, 1, 1)
self.attach(alt_command_lbl, 0, 1, 1, 1)
self.attach(command_lbl, 0, 2, 1, 1)
self.attach(socket_lbl, 0, 3, 1, 1)
self.attach(self.alt_command_entry, 1, 1, 2, 1)
self.attach(self.command_entry, 1, 2, 2, 1)
self.attach(self.socket_entry, 1, 3, 2, 1)
self.attach(self.command_entry, 1, 2, 2, 1)
self.attach(self.socket_entry, 1, 3, 2, 1)
self.attach(init_options_lbl, 0, 4, 3, 1)
self.attach(scrolled_win, 0, 5, 3, 1)
self.attach(init_options_lbl, 0, 4, 3, 1)
self.attach(scrolled_win1, 0, 5, 3, 1)
self.attach(message_box_lbl, 0, 6, 3, 1)
self.attach(self.message_box, 0, 7, 3, 1)
self.attach(message_box_lbl, 0, 6, 3, 1)
self.attach(self.message_box, 0, 7, 3, 1)
self.attach(log_list_lbl, 3, 0, 3, 1)
self.attach(scrolled_win2, 3, 1, 3, 11)