More wiring of lsp manager calls and responses

This commit is contained in:
2024-09-14 16:39:21 -05:00
parent e0664123da
commit bc52f62982
7 changed files with 125 additions and 84 deletions

View File

@@ -1,5 +1,4 @@
# Python imports
import os
import signal
import subprocess
import threading
@@ -9,7 +8,7 @@ import json
from gi.repository import GLib
# Application imports
from libs.dto.lsp_messages import LEN_HEADER, TYPE_HEADER, get_message_str, get_message_obj, definition_query, references_query, symbols_query
from libs.dto.lsp_messages import LEN_HEADER, TYPE_HEADER, get_message_str, get_message_obj
from libs.dto.lsp_message_structs import \
LSPResponseTypes, ClientRequest, ClientNotification, LSPResponseRequest, LSPResponseNotification
from .lsp_controller_events import LSPControllerEvents
@@ -48,9 +47,6 @@ class LSPController(LSPControllerEvents):
def _subscribe_to_events(self):
# event_system.subscribe("client-send-request", self._client_send_request)
# event_system.subscribe("client-send-notification", self._client_send_notification)
event_system.subscribe("textDocument/didOpen", self._lsp_did_open)
# event_system.subscribe("textDocument/didSave", self._lsp_did_save)
# event_system.subscribe("textDocument/didClose", self._lsp_did_close)
@@ -58,26 +54,6 @@ class LSPController(LSPControllerEvents):
event_system.subscribe("textDocument/definition", self._lsp_goto)
event_system.subscribe("textDocument/completion", self._lsp_completion)
def _client_send_request(self, method: str, uri: str, line: int, character: int):
if not method: return
if "textDocument/definition":
params = symbols_query
elif "textDocument/references":
params = symbols_query
elif "textDocument/documentSymbol":
params = symbols_query
params["textDocument"]["uri"] = uri
params["textDocument"]["languageId"] = self._language
params["position"]["line"] = line
params["position"]["character"] = character
self.send_request(method, params)
def _client_send_notification(self, method: str, line: int, char: int):
if not method: return
self.send_notification(method, params)
def set_language(self, language):
self._language = language
@@ -91,25 +67,6 @@ class LSPController(LSPControllerEvents):
def unset_start_command(self):
self._start_command = None
def send_initialize_message(self, init_ops: str, workspace_file: str, workspace_uri: str):
folder_name = os.path.basename(workspace_file)
self._init_params["processId"] = settings_manager.get_app_pid()
self._init_params["rootPath"] = workspace_file
self._init_params["rootUri"] = workspace_uri
self._init_params["workspaceFolders"] = [
{
"name": folder_name,
"uri": workspace_uri
}
]
self._init_params["initializationOptions"] = get_message_obj(init_ops)
self.send_request("initialize", self._init_params)
def send_initialized_message(self):
self.send_notification("initialized")
def send_notification(self, method: str, params: {} = {}):
self._send_message( ClientNotification(method, params) )
@@ -237,4 +194,4 @@ class LSPController(LSPControllerEvents):
def handle_lsp_response(self, lsp_response: LSPResponseTypes):
self.log_list.add_log_entry("LSP Response", lsp_response)
event_system.emit("respond-to-client", (get_message_str(lsp_response),))
event_system.emit("respond-to-client", (get_message_str(lsp_response),))

View File

@@ -1,15 +1,34 @@
# Python imports
import os
# Lib imports
from gi.repository import GLib
# Application imports
# from libs.dto.lsp_messages import LEN_HEADER, TYPE_HEADER, get_message_str, get_message_obj, definition_query, references_query, symbols_query
from libs.dto.lsp_messages import didopen_notification
from libs.dto.lsp_messages import get_message_obj, didopen_notification, completion_request, didchange_notification
class LSPControllerEvents:
def send_initialize_message(self, init_ops: str, workspace_file: str, workspace_uri: str):
folder_name = os.path.basename(workspace_file)
self._init_params["processId"] = settings_manager.get_app_pid()
self._init_params["rootPath"] = workspace_file
self._init_params["rootUri"] = workspace_uri
self._init_params["workspaceFolders"] = [
{
"name": folder_name,
"uri": workspace_uri
}
]
self._init_params["initializationOptions"] = get_message_obj(init_ops)
self.send_request("initialize", self._init_params)
def send_initialized_message(self):
self.send_notification("initialized")
def _lsp_did_open(self, data: dict):
method = data["method"]
params = didopen_notification["params"]
@@ -21,23 +40,30 @@ class LSPControllerEvents:
GLib.idle_add( self.send_notification, method, params )
def _lsp_did_save(self, data: dict):
# self.send_notification(method, params)
# GLib.idle_add( self.send_notification, method, params )
...
def _lsp_did_close(self, data: dict):
# self.send_notification(method, params)
# GLib.idle_add( self.send_notification, method, params )
...
def _lsp_did_change(self, data: dict):
method = data["method"]
language_id = data["language_id"]
uri = data["uri"]
text = data["text"]
line = data["line"]
column = data["column"]
method = data["method"]
params = didchange_notification["params"]
self.send_notification(method, params)
# return "{'notification':'some kind of response'}"
params["textDocument"]["uri"] = data["uri"]
params["textDocument"]["languageId"] = data["language_id"]
params["textDocument"]["version"] = data["version"]
contentChanges = params["contentChanges"][0]
start = contentChanges["range"]["start"]
end = contentChanges["range"]["end"]
start["line"] = data["line"]
start["character"] = 0
end["line"] = data["line"]
end["character"] = data["column"]
GLib.idle_add( self.send_notification, method, params )
def _lsp_goto(self, data: dict):
method = data["method"]
@@ -46,14 +72,17 @@ class LSPControllerEvents:
line = data["line"]
column = data["column"]
self._client_send_request(method, uri, line, column)
# return "{'response':'some kind of response'}"
GLib.idle_add( self.send_request, method, params )
def _lsp_completion(self, data: dict):
method = data["method"]
language_id = data["language_id"]
uri = data["uri"]
line = data["line"]
column = data["column"]
method = data["method"]
params = completion_request["params"]
# self._client_send_request(method, uri, line, column)
params["textDocument"]["uri"] = data["uri"]
params["textDocument"]["languageId"] = data["language_id"]
params["textDocument"]["version"] = data["version"]
params["position"]["line"] = data["line"]
params["position"]["character"] = data["column"]
GLib.idle_add( self.send_request, method, params )

View File

@@ -28,7 +28,8 @@ class WorkspaceFolderChoserButton(Gtk.FileChooserButton):
self.set_title("Chose Workspace")
self.set_action( Gtk.FileChooserAction.SELECT_FOLDER )
# self.set_uri("file:///home/abaddon/Coding/Projects/Active/Python_Projects/testing/lsp_manager")
self.set_uri("file:///home/abaddon/Coding/Projects/Active/Python_Projects/000_Usable/gtk/LSP-Manager")
# self.set_uri("file:///home/abaddon/Coding/Projects/Active/Python_Projects/000_Usable/gtk/LSP-Manager")
self.set_uri("file:///home/abaddon/Coding/Projects/Active/Python_Projects/000_Usable/gtk/Newton_Editor")
def _setup_signals(self):