Files
Python-With-Gtk-Template/plugins/code/language_server_clients/lsp_manager/plugin.py
itdominator a8ad015e05 Refactor LSP manager architecture and event + completion pipeline
- Replace legacy LSPManagerClient + LSPManagerUI with ClientManager and UIManager
- Remove WebsocketClient in favor of unified Websocket implementation
- Move LSP initialization config loading into centralized config module
- Update LSPClient to support dynamic socket, improved init params, and doc version tracking
- Introduce range-based didChange notifications and add implementation + references requests
- Expand LSPClientEvents to support implementation/references and structured range edits
- Simplify websocket response handling and normalize LSP response parsing flow
- Decouple UI from LSP manager core; UI now emits address/port for client creation
- Refactor completion provider pipeline:
  - Split TextChangedEvent into TextInsertedEvent and DeleteRangeEvent
  - Update ProviderResponseCacheBase and controller dispatch paths accordingly
- Improve SourceBuffer and SourceFile event tracking with delete-range support
- Update plugin system:
  - Centralize command/provider registration via helper methods
  - Add LSP commands: definition, references, implementation, toggle UI
- Enhance response handlers to support references and implementation hooks
- Improve Python LSP config (jedi completion, signatures, references enabled)
- Fix minor GTK lifecycle and buffer signal handling issues
- Clean up unused imports, dead code, and outdated JSON server configs
2026-04-11 15:36:59 -05:00

119 lines
3.2 KiB
Python

# Python imports
# Lib imports
import gi
from gi.repository import GLib
# Application imports
from libs.event_factory import Event_Factory, Code_Event_Types
from libs.dto.states import SourceViewStates
from plugins.plugin_types import PluginCode
from .dto.code import events as lsp_events
from .commands import Commands
from .lsp_manager import LSPManager
lsp_manager = LSPManager()
class Plugin(PluginCode):
def __init__(self):
super(Plugin, self).__init__()
def _controller_message(self, event: Code_Event_Types.CodeEvent):
...
def load(self):
Event_Factory.register_events( lsp_events.__dict__.items() )
self.register_controller("lsp_manager", lsp_manager)
window = self.request_ui_element("main-window")
lsp_manager.ui_manager.map_parent_resize_event(window)
self._manage_signals("register_command")
self._manage_provider("register_provider")
event = Event_Factory.create_event(
"create_source_view",
state = SourceViewStates.INDEPENDENT
)
self.emit_to("source_views", event)
scrolled_win, source_view = event.response
lsp_manager.ui_manager.set_source_view(scrolled_win, source_view)
def unload(self):
Event_Factory.unregister_events( lsp_events.__dict__.items() )
self.unregister_controller("lsp_manager")
window = self.request_ui_element("main-window")
lsp_manager.ui_manager.unmap_parent_resize_event(window)
self._manage_signals("unregister_command")
self._manage_provider("unregister_provider")
lsp_manager.handle_destroy()
def _manage_signals(self, action: str):
_commands = Commands
_commands.lsp_manager = lsp_manager
event = Event_Factory.create_event(action,
command_name = "lsp_manager_toggle",
command = _commands.lsp_manager_toggle,
binding_mode = "released",
binding = "<Shift><Control>l"
)
self.emit_to("source_views", event)
event = Event_Factory.create_event(action,
command_name = "lsp_references",
command = _commands.lsp_references,
binding_mode = "released",
binding = "<Control>i"
)
self.emit_to("source_views", event)
event = Event_Factory.create_event(action,
command_name = "lsp_implementation",
command = _commands.lsp_implementation,
binding_mode = "released",
binding = "<Shift><Control>i"
)
self.emit_to("source_views", event)
event = Event_Factory.create_event(action,
command_name = "lsp_definition",
command = _commands.lsp_definition,
binding_mode = "released",
binding = "<Control>g"
)
self.emit_to("source_views", event)
def _manage_provider(self, action: str):
event = Event_Factory.create_event(
action,
provider_name = "LSP Completer",
provider = lsp_manager.provider,
language_ids = []
)
self.emit_to("completion", event)
def run(self):
...
def generate_plugin_element(self):
...