message refactoring; initial event call from client structure

This commit is contained in:
2024-09-09 21:50:52 -05:00
parent 6df84e9f23
commit 13b126ef6e
8 changed files with 206 additions and 114 deletions

View File

@@ -1,6 +1,7 @@
# Python imports
import json
import enum
from dataclasses import dataclass
# Lib imports
@@ -18,11 +19,11 @@ class MessageEncoder(json.JSONEncoder):
return o.__dict__
class LSPRequest(object):
@dataclass
class ClientRequest(object):
def __init__(self, id: int, method: str, params: dict):
"""
Constructs a new LSP Request instance.
Constructs a new Client Request instance.
:param int id: Message id to track instance.
:param str method: The type of lsp request being made.
@@ -33,11 +34,11 @@ class LSPRequest(object):
self.method = method
self.params = params
class LSPNotification(object):
@dataclass
class ClientNotification(object):
def __init__(self, method: str, params: dict):
"""
Constructs a new LSP Notification instance.
Constructs a new Client Notification instance.
:param str method: The type of lsp notification being made.
:param dict params: The arguments of the given method.
@@ -46,15 +47,18 @@ class LSPNotification(object):
self.method = method
self.params = params
@dataclass
class LSPResponse(object):
def __init__(self, id: int or None, result: dict):
"""
Constructs a new LSP Response instance.
:param str method: The type of lsp notification being made.
:param dict params: The arguments of the given method.
:param dict result: The arguments of the given method.
"""
self.jsonrpc = "2.0"
self.id = id
self.result = result
jsonrpc: str
id: int or None
result: {}
class MessageTypes(ClientRequest, ClientNotification, LSPResponse):
...

View File

@@ -0,0 +1,92 @@
# Python imports
import json
# Lib imports
# Application imports
from .lsp_message_structs import MessageEncoder
LEN_HEADER = "Content-Length: "
TYPE_HEADER = "Content-Type: "
def get_message_str(data: dict) -> str:
return json.dumps(data, separators = (',', ':'), indent = 4, cls = MessageEncoder)
def get_message_obj(data: str):
return json.loads(data)
# Request type formatting
# https://github.com/microsoft/multilspy/blob/main/src/multilspy/language_server.py#L417
content_part = {
"method": "textDocument/definition",
"params": {
"textDocument": {
"uri": "file:///",
"languageId": "python3",
"version": 1,
"text": ""
},
"position": {
"line": 5,
"character": 12,
"offset": 0
}
}
}
definition_query = {
"method": "textDocument/definition",
"params": {
"textDocument": {
"uri": "file:///home/abaddon/Coding/Projects/Active/Python_Projects/000_Usable/gtk/LSP-Manager/src/core/widgets/lsp_message_box.py",
"languageId": "python3",
"version": 1,
"text": ""
},
"position": {
"line": 5,
"character": 12,
"offset": 0
}
}
}
references_query = {
"method": "textDocument/references",
"params": {
"context": {
"includeDeclaration": False
},
"textDocument": {
"uri": "file:///home/abaddon/Coding/Projects/Active/Python_Projects/000_Usable/gtk/LSP-Manager/src/core/widgets/lsp_message_box.py",
"languageId": "python3",
"version": 1,
"text": ""
},
"position": {
"line": 30,
"character": 13,
"offset": 0
}
}
}
symbols_query = {
"method": "textDocument/documentSymbol",
"params": {
"textDocument": {
"uri": "file:///home/abaddon/Coding/Projects/Active/Python_Projects/000_Usable/gtk/LSP-Manager/src/core/widgets/lsp_message_box.py",
"languageId": "python3",
"version": 1,
"text": ""
}
}
}

View File

@@ -1,5 +1,10 @@
# Python imports
import enum
# Lib imports
# Application imports
def to_type(o, new_type):