feat: improve LSP lifecycle, terminal widget, and code folding support

- LSP:
  - Add shutdown and exit request/notification handling
  - Send initialized notification after initialize response
  - Gracefully close clients with delayed shutdown via GLib timeout
  - Fix LSP WS server ↔ Godot LSP communication flow

- Terminal (VteWidget):
  - Switch to async spawn with full environment inheritance
  - Add PROMPT_COMMAND OSC7 support for cwd tracking
  - Improve UX: scrollback, no audible bell, auto scroll
  - Implement clipboard shortcuts, selection copy, middle-click paste
  - Track cwd changes and update UI label
  - Add proper signal wiring and cleanup on destroy

- Code folding:
  - Add fold support for JS, HTML, CSS, JSON, C, C++, Go
  - Reset fold state safely when AST or filetype is unavailable

- UI (Plugins dialog):
  - Improve dialog behavior (non-modal, centered, transient)
  - Add focus-out auto-hide and Ctrl+Shift+P shortcut

- Misc:
  - Add type hints in VTE widget
  - Update TODOs (remove completed items, add LSP comm fix)
  - Add terminal plugin scaffolding
This commit is contained in:
2026-04-13 00:50:42 -05:00
parent d8e0185d1c
commit 12b5fe7304
15 changed files with 585 additions and 34 deletions
+79 -19
View File
@@ -28,8 +28,8 @@ class VteWidget(Vte.Terminal):
def __init__(self):
super(VteWidget, self).__init__()
self.cd_cmd_prefix = ("cd".encode(), "cd ".encode())
self.dont_process = False
self.cd_cmd_prefix: tuple = ("cd".encode(), "cd ".encode())
self.dont_process: bool = False
self._setup_styling()
self._setup_signals()
@@ -48,9 +48,17 @@ class VteWidget(Vte.Terminal):
self.set_hexpand(True)
self.set_enable_sixel(True)
self.set_cursor_shape( Vte.CursorShape.IBEAM )
self.set_audible_bell(False)
self.set_scroll_on_output(True)
def _setup_signals(self):
self.connect("commit", self._commit)
self.connect("commit", self._handle_commit)
self.connect("current-directory-uri-changed", self._handle_path_change)
self.connect("selection-changed", self._handle_selection)
self.connect("button-press-event", self._on_button_press)
self.connect("key-press-event", self._on_key_press)
self.connect("key-release-event", self._on_key_release)
self.connect("destroy", self._handle_destroy)
def _subscribe_to_events(self):
event_system.subscribe("update_term_path", self.update_term_path)
@@ -59,35 +67,87 @@ class VteWidget(Vte.Terminal):
...
def _do_session_spawn(self):
env = [
"DISPLAY=:0",
"LC_ALL=C",
"TERM='xterm-256color'",
f"HOME='{settings_manager.path_manager.get_home_path()}'",
"XDG_RUNTIME_DIR='/run/user/1000'",
f"XAUTHORITY='{settings_manager.path_manager.get_home_path()}/.Xauthority'",
"HISTFILE=/dev/null",
"HISTSIZE=0",
"HISTFILESIZE=0",
"PS1=\\h@\\u \\W -->: ",
]
env_dict = os.environ.copy()
existing_pc = env_dict.get("PROMPT_COMMAND", "")
# Note: Needed for 'current-directory-uri-changed' to work.
# Make sure user .bashrc doesn't affect it...
osc7 = 'printf "\\033]7;file://%s%s\\007" "$PWD"'
self.spawn_sync(
env_dict.update({
"LC_ALL": "C",
"TERM": "xterm-256color",
"HISTFILE": "/dev/null",
"HISTSIZE": "0",
"HISTFILESIZE": "0",
"PS1": "\\h@\\u \\W -->: ",
"PROMPT_COMMAND": f"{osc7};{existing_pc}" if existing_pc else osc7,
})
env = [f"{k}={v}" for k, v in env_dict.items()]
self.spawn_async(
Vte.PtyFlags.DEFAULT,
settings_manager.path_manager.get_home_path(),
["/bin/bash"],
env,
GLib.SpawnFlags.DEFAULT,
None, None,
None, None, -1, None, None,
)
startup_cmds = [
]
self.set_scrollback_lines(15000)
for i in startup_cmds:
self.run_command(i)
def _commit(self, terminal, text, size):
def _handle_destroy(self, terminal):
logger.debug("Destroying terminal...")
terminal.disconnect_by_func(terminal._handle_commit)
terminal.disconnect_by_func(terminal._handle_path_change)
terminal.disconnect_by_func(terminal._handle_selection)
terminal.disconnect_by_func(terminal._on_button_press)
terminal.disconnect_by_func(terminal._on_key_press)
terminal.disconnect_by_func(terminal._on_key_release)
terminal.disconnect_by_func(terminal._handle_destroy)
def _handle_path_change(self, terminal):
if not hasattr(self, "label"): return
uri = terminal.get_current_directory_uri().replace("file://", "")
terminal.label.set_text(uri)
terminal.label.set_tooltip_text(uri)
def _handle_selection(self, *args):
if self.get_has_selection():
self.copy_primary()
def _on_button_press(self, widget, event):
if event.button == 2: # middle click
self.paste_clipboard()
return True
def _on_key_press(self, widget, event):
ctrl_pressed = event.state & Gdk.ModifierType.CONTROL_MASK
shift_pressed = event.state & Gdk.ModifierType.SHIFT_MASK
if ctrl_pressed:
if shift_pressed:
if event.keyval in [Gdk.KEY_C, Gdk.KEY_V]:
if event.keyval == Gdk.KEY_C:
self.copy_clipboard()
elif event.keyval == Gdk.KEY_V:
self.paste_clipboard()
return True
return False
def _on_key_release(self, widget, event):
...
def _handle_commit(self, terminal, text, size):
if self.dont_process:
self.dont_process = False
return
@@ -127,4 +187,4 @@ class VteWidget(Vte.Terminal):
self.run_command(cmd)
def run_command(self, cmd: str):
self.feed_child_binary(bytes(cmd, 'utf8'))
self.feed_child_binary(bytes(cmd, 'utf8'))
+22 -1
View File
@@ -2,7 +2,10 @@
# Lib imports
import gi
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GLib
# Application imports
@@ -25,6 +28,7 @@ class PluginsUI(Gtk.Dialog):
self.set_title("Plugins")
self.set_size_request(450, 530)
self.set_modal(False)
self.set_deletable(False)
self.set_skip_pager_hint(True)
self.set_skip_taskbar_hint(True)
@@ -35,9 +39,13 @@ class PluginsUI(Gtk.Dialog):
window = widget_registery.get_object("main-window")
self.set_transient_for(window)
self.set_destroy_with_parent(True)
self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
def _setup_signals(self):
...
self.connect("focus-out-event", self._on_focus_out)
self.connect("key-release-event", self._on_key_release)
def _subscribe_to_events(self):
...
@@ -59,6 +67,19 @@ class PluginsUI(Gtk.Dialog):
scrolled_win.show_all()
def _on_key_release(self, widget, event):
ctrl_pressed = event.state & Gdk.ModifierType.CONTROL_MASK
shift_pressed = event.state & Gdk.ModifierType.SHIFT_MASK
if ctrl_pressed:
if shift_pressed:
if event.keyval == Gdk.KEY_P:
self.hide()
def _on_focus_out(self, *args):
self.hide()
GLib.idle_add(self.hide)
def add_row(self, manifest_meta, callback: callable):
box = Gtk.Box()
plugin_lbl = Gtk.Label(label = manifest_meta.manifest.name)