Rename Error -> LSPError

This commit is contained in:
Dominik Jain authored and Dominik Jain committed 2025-07-27 23:07:54 +02:00
1 parent a15833b22d
commit 9368ce446c
3 files changed
+13 -13

No files matched your search

+2 -2
View File
@@ -30,7 +30,7 @@ from solidlsp.lsp_protocol_handler import lsp_types as LSPTypes
from solidlsp.lsp_protocol_handler.lsp_constants import LSPConstants
from solidlsp.lsp_protocol_handler.lsp_types import Definition, DefinitionParams, LocationLink, SymbolKind
from solidlsp.lsp_protocol_handler.server import (
Error,
LSPError,
ProcessLaunchInfo,
StringDict,
)
@@ -672,7 +672,7 @@ class SolidLanguageServer(ABC):
response = self._send_references_request(relative_file_path, line=line, column=column)
except Exception as e:
# Catch LSP internal error (-32603) and raise a more informative exception
if isinstance(e, Error) and getattr(e, "code", None) == -32603:
if isinstance(e, LSPError) and getattr(e, "code", None) == -32603:
raise RuntimeError(
f"LSP internal error (-32603) when requesting references for {relative_file_path}:{line}:{column}. "
"This often occurs when requesting references for a symbol not referenced in the expected way. "
+7 -7
View File
@@ -20,7 +20,7 @@ from solidlsp.lsp_protocol_handler.lsp_requests import LspNotification
from solidlsp.lsp_protocol_handler.lsp_types import ErrorCodes
from solidlsp.lsp_protocol_handler.server import (
ENCODING,
Error,
LSPError,
MessageType,
PayloadLike,
ProcessLaunchInfo,
@@ -414,7 +414,7 @@ class SolidLanguageServerHandler:
"""
self._send_payload(make_response(request_id, params))
def send_error_response(self, request_id: Any, err: Error) -> None:
def send_error_response(self, request_id: Any, err: LSPError) -> None:
"""
Send error response to the given request id to the server with the given error
"""
@@ -501,9 +501,9 @@ class SolidLanguageServerHandler:
if "result" in response and "error" not in response:
request.on_result(response["result"])
elif "result" not in response and "error" in response:
request.on_error(Error.from_lsp(response["error"]))
request.on_error(LSPError.from_lsp(response["error"]))
else:
request.on_error(Error(ErrorCodes.InvalidRequest, ""))
request.on_error(LSPError(ErrorCodes.InvalidRequest, ""))
def _request_handler(self, response: StringDict) -> None:
"""
@@ -516,7 +516,7 @@ class SolidLanguageServerHandler:
if not handler:
self.send_error_response(
request_id,
Error(
LSPError(
ErrorCodes.MethodNotFound,
f"method '{method}' not handled on client.",
),
@@ -524,10 +524,10 @@ class SolidLanguageServerHandler:
return
try:
self.send_response(request_id, handler(params))
except Error as ex:
except LSPError as ex:
self.send_error_response(request_id, ex)
except Exception as ex:
self.send_error_response(request_id, Error(ErrorCodes.InternalError, str(ex)))
self.send_error_response(request_id, LSPError(ErrorCodes.InternalError, str(ex)))
def _notification_handler(self, response: StringDict) -> None:
"""
+4 -4
View File
@@ -59,7 +59,7 @@ class ProcessLaunchInfo:
cwd: str = os.getcwd()
class Error(Exception):
class LSPError(Exception):
def __init__(self, code: ErrorCodes, message: str) -> None:
super().__init__(message)
self.code = code
@@ -68,8 +68,8 @@ class Error(Exception):
return {"code": self.code, "message": super().__str__()}
@classmethod
def from_lsp(cls, d: StringDict) -> "Error":
return Error(d["code"], d["message"])
def from_lsp(cls, d: StringDict) -> "LSPError":
return LSPError(d["code"], d["message"])
def __str__(self) -> str:
return f"{super().__str__()} ({self.code})"
@@ -79,7 +79,7 @@ def make_response(request_id: Any, params: PayloadLike) -> StringDict:
return {"jsonrpc": "2.0", "id": request_id, "result": params}
def make_error_response(request_id: Any, err: Error) -> StringDict:
def make_error_response(request_id: Any, err: LSPError) -> StringDict:
return {"jsonrpc": "2.0", "id": request_id, "error": err.to_lsp()}