mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-03 07:13:33 +00:00
Adds request_document_diagnostic to solidlsp (#347)
This commit is contained in:
1 parent
2909c67d50
commit
0abb8be85a
3 files changed
+75
-1
No files matched your search
+46
-1
@@ -153,7 +153,7 @@ class SolidLanguageServer(ABC):
|
||||
|
||||
ls = CSharpLanguageServer(config, logger, repository_root_path)
|
||||
elif config.code_language == Language.CSHARP_OMNISHARP:
|
||||
from solidlsp.language_servers.omnisharp.omnisharp import OmniSharp
|
||||
from solidlsp.language_servers.omnisharp import OmniSharp
|
||||
|
||||
ls = OmniSharp(config, logger, repository_root_path)
|
||||
elif config.code_language == Language.TYPESCRIPT:
|
||||
@@ -709,6 +709,50 @@ class SolidLanguageServer(ABC):
|
||||
ret.append(ls_types.Location(**new_item))
|
||||
|
||||
return ret
|
||||
|
||||
def request_text_document_diagnostics(
|
||||
self, relative_file_path: str
|
||||
) -> list[ls_types.Diagnostic]:
|
||||
"""
|
||||
Raise a [textDocument/diagnostic](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_diagnostic) request to the Language Server
|
||||
to find diagnostics for the given file. Wait for the response and return the result.
|
||||
|
||||
:param relative_file_path: The relative path of the file to retrieve diagnostics for
|
||||
|
||||
:return: A list of diagnostics for the file
|
||||
"""
|
||||
if not self.server_started:
|
||||
self.logger.log(
|
||||
"request_text_document_diagnostics called before Language Server started",
|
||||
logging.ERROR,
|
||||
)
|
||||
raise LanguageServerException("Language Server not started")
|
||||
|
||||
with self.open_file(relative_file_path):
|
||||
response = self.server.send.text_document_diagnostic(
|
||||
{
|
||||
LSPConstants.TEXT_DOCUMENT: {
|
||||
LSPConstants.URI: pathlib.Path(str(PurePath(self.repository_root_path, relative_file_path))).as_uri()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
if response is None:
|
||||
return []
|
||||
|
||||
assert isinstance(response, dict), f"Unexpected response from Language Server (expected list, got {type(response)}): {response}"
|
||||
ret: list[ls_types.Diagnostic] = []
|
||||
for item in response["items"]:
|
||||
new_item: ls_types.Diagnostic = {
|
||||
"uri": pathlib.Path(str(PurePath(self.repository_root_path, relative_file_path))).as_uri(),
|
||||
"severity": item["severity"],
|
||||
"message": item["message"],
|
||||
"range": item["range"],
|
||||
"code": item["code"]
|
||||
}
|
||||
ret.append(ls_types.Diagnostic(new_item))
|
||||
|
||||
return ret
|
||||
|
||||
def retrieve_full_file_content(self, file_path: str) -> str:
|
||||
"""
|
||||
@@ -1533,6 +1577,7 @@ class SolidLanguageServer(ABC):
|
||||
defining_symbol = self.request_containing_symbol(def_path, def_line, def_col, strict=False, include_body=include_body)
|
||||
|
||||
return defining_symbol
|
||||
|
||||
|
||||
@property
|
||||
def cache_path(self) -> Path:
|
||||
|
||||
@@ -317,3 +317,26 @@ class Hover(TypedDict):
|
||||
range: NotRequired[Range]
|
||||
""" An optional range inside the text document that is used to
|
||||
visualize the hover, e.g. by changing the background color. """
|
||||
|
||||
class DiagnosticsSeverity(IntEnum):
|
||||
ERROR = 1
|
||||
WARNING = 2
|
||||
INFORMATION = 3
|
||||
HINT = 4
|
||||
|
||||
|
||||
class Diagnostic(TypedDict):
|
||||
"""Diagnostic information for a text document."""
|
||||
|
||||
uri: DocumentUri
|
||||
""" The URI of the text document to which the diagnostics apply. """
|
||||
range: Range
|
||||
""" The range of the text document to which the diagnostics apply. """
|
||||
severity: NotRequired[DiagnosticsSeverity]
|
||||
""" The severity of the diagnostic. """
|
||||
message: str
|
||||
""" The diagnostic message. """
|
||||
code: str
|
||||
""" The code of the diagnostic. """
|
||||
source: NotRequired[str]
|
||||
""" The source of the diagnostic, e.g. the name of the tool that produced it. """
|
||||
@@ -61,3 +61,9 @@ class LSPConstants:
|
||||
|
||||
# key used to represent the location in symbols
|
||||
LOCATION = "location"
|
||||
|
||||
# Severity level of the diagnostic
|
||||
SEVERITY = "severity"
|
||||
|
||||
# The message of the diagnostic
|
||||
MESSAGE = "message"
|
||||
Reference in new issue
Block a user