Skip to content

Commit

Permalink
lsp: Report sphinx diagnostics to the client
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Sep 11, 2023
1 parent b4d146d commit bbfaebf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/esbonio/esbonio/server/features/sphinx_manager/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def build_file_map(self) -> Dict[Uri, str]:
"""
...

@property
def diagnostics(self) -> Dict[Uri, List[types.Diagnostic]]:
"""A mapping of source file uris to any diagnostic items."""
...

@property
def conf_uri(self) -> Optional[Uri]:
"""The URI to the Sphinx application's conf dir."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(
self.sphinx_info: Optional[types.SphinxInfo] = None
self._building = False
self._build_file_map: Dict[Uri, str] = {}
self._diagnostics: Dict[Uri, List[types.Diagnostic]] = {}

@property
def id(self) -> Optional[str]:
Expand Down Expand Up @@ -93,8 +94,17 @@ def conf_uri(self) -> Optional[Uri]:

return Uri.for_file(self.sphinx_info.conf_dir)

@property
def diagnostics(self) -> Dict[str, List[types.Diagnostic]]:
"""Any diagnostics associated with the project.
These are automatically updated with each build.
"""
return self._diagnostics

@property
def build_file_map(self) -> Dict[Uri, str]:
"""Mapping of source files to their corresponing output path."""
return self._build_file_map

@property
Expand Down Expand Up @@ -177,8 +187,14 @@ async def build(
)

self._building = True

result = await self.protocol.send_request_async("sphinx/build", params)
self._building = False

self._diagnostics = {
Uri.for_file(fpath): items for fpath, items in result.diagnostics.items()
}

self._build_file_map = {
Uri.for_file(src): out for src, out in result.build_file_map.items()
}
Expand Down
14 changes: 14 additions & 0 deletions lib/esbonio/esbonio/server/features/sphinx_manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ async def trigger_build(self, uri: Uri):

result = await client.build(content_overrides=content_overrides)

# Update diagnostics
source = f"sphinx[{client.id}]"
self.server.clear_diagnostics(source)
for uri, items in client.diagnostics.items():
diagnostics = [
lsp.Diagnostic(
range=d.range, message=d.message, source=source, severity=d.severity
)
for d in items
]
self.server.set_diagnostics(f"sphinx[{client.id}]", uri, diagnostics)

self.server.sync_diagnostics()

# Notify listeners.
for listener in self.handlers.get("build", set()):
try:
Expand Down

0 comments on commit bbfaebf

Please sign in to comment.