refactor(lsp): replace LSPManager with controller-based architecture
- Remove legacy LSPManager dialog implementation - Introduce LSPController as the central LSP entry point - Route UI interactions through lsp_controller.lsp_manager_ui - Move client lifecycle handling out of ProviderResponseCache - Simplify completion cache and matcher filtering - Improve LSP completion item parsing with safer fallbacks - Modernize typing (Python 3.10 union syntax) - Remove unused imports and dead code - Use GLib.idle_add for safe UI scrolling operations - Minor comment and spelling fixes
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
# Python imports
|
||||
import threading
|
||||
from os import path
|
||||
import json
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
@@ -20,17 +22,15 @@ class LSPController(LSPControllerWebsocket):
|
||||
# initialize-params-slim.json was created off of jedi_language_server one
|
||||
# self._init_params = settings_manager.get_lsp_init_data()
|
||||
|
||||
self._language: str = ""
|
||||
self._init_params: dict = {}
|
||||
self._event_history: dict[str] = {}
|
||||
self._language: str = ""
|
||||
self._init_params: dict = {}
|
||||
self._event_history: dict[int, str] = {}
|
||||
|
||||
try:
|
||||
from os import path
|
||||
import json
|
||||
|
||||
_USER_HOME = path.expanduser('~')
|
||||
_SCRIPT_PTH = path.dirname( path.realpath(__file__) )
|
||||
_LSP_INIT_CONFIG = f"{_SCRIPT_PTH}/../configs/initialize-params-slim.json"
|
||||
|
||||
with open(_LSP_INIT_CONFIG) as file:
|
||||
data = file.read().replace("{user.home}", _USER_HOME)
|
||||
self._init_params = json.loads(data)
|
||||
@@ -42,7 +42,7 @@ class LSPController(LSPControllerWebsocket):
|
||||
self.read_lock = threading.Lock()
|
||||
self.write_lock = threading.Lock()
|
||||
|
||||
def set_language(self, language):
|
||||
def set_language(self, language: str):
|
||||
self._language = language
|
||||
|
||||
def set_socket(self, socket: str):
|
||||
@@ -51,15 +51,15 @@ class LSPController(LSPControllerWebsocket):
|
||||
def unset_socket(self):
|
||||
self._socket = None
|
||||
|
||||
def send_notification(self, method: str, params: {} = {}):
|
||||
def send_notification(self, method: str, params: dict = {}):
|
||||
self._send_message( ClientNotification(method, params) )
|
||||
|
||||
def send_request(self, method: str, params: {} = {}):
|
||||
def send_request(self, method: str, params: dict = {}):
|
||||
self._message_id += 1
|
||||
self._event_history[self._message_id] = method
|
||||
self._send_message( ClientRequest(self._message_id, method, params) )
|
||||
|
||||
def get_event_by_id(self, message_id: int):
|
||||
def get_event_by_id(self, message_id: int) -> str:
|
||||
if not message_id in self._event_history: return
|
||||
return self._event_history[message_id]
|
||||
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
# Python imports
|
||||
import traceback
|
||||
import subprocess
|
||||
|
||||
# Lib imports
|
||||
from gi.repository import GLib
|
||||
|
||||
# Application imports
|
||||
# from libs import websockets
|
||||
from libs.dto.code.lsp.lsp_messages import LEN_HEADER, TYPE_HEADER, get_message_str, get_message_obj
|
||||
from libs.dto.code.lsp.lsp_message_structs import \
|
||||
LSPResponseTypes, ClientRequest, ClientNotification, LSPResponseRequest, LSPResponseNotification, LSPIDResponseNotification
|
||||
from libs.dto.code.lsp.lsp_messages import get_message_str, get_message_obj
|
||||
from libs.dto.code.lsp.lsp_message_structs import \
|
||||
LSPResponseTypes, ClientRequest, ClientNotification, \
|
||||
LSPResponseRequest, LSPResponseNotification, LSPIDResponseNotification
|
||||
|
||||
from .lsp_controller_base import LSPControllerBase
|
||||
from .websocket_client import WebsocketClient
|
||||
@@ -17,7 +16,7 @@ from .websocket_client import WebsocketClient
|
||||
|
||||
|
||||
class LSPControllerWebsocket(LSPControllerBase):
|
||||
def _send_message(self, data: ClientRequest or ClientNotification):
|
||||
def _send_message(self, data: ClientRequest | ClientNotification):
|
||||
if not data: return
|
||||
|
||||
message_str = get_message_str(data)
|
||||
@@ -39,7 +38,7 @@ class LSPControllerWebsocket(LSPControllerBase):
|
||||
if not hasattr(self, "ws_client"): return
|
||||
self.ws_client.close_client()
|
||||
|
||||
def _monitor_lsp_response(self, data: None or {}):
|
||||
def _monitor_lsp_response(self, data: dict | None):
|
||||
if not data: return
|
||||
|
||||
message = get_message_obj(data)
|
||||
|
||||
Reference in New Issue
Block a user