Skip to content

Commit

Permalink
sphinx-agent: Move the set of diagnostics into the Esbonio object
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Oct 20, 2024
1 parent d9466d7 commit 603fe1d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/esbonio/esbonio/sphinx_agent/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def __init__(self, dbpath: pathlib.Path, app: _Sphinx):
self._roles: list[RoleDefinition] = []
"""Roles captured during Sphinx startup."""


self.diagnostics: dict[types.Uri, set[types.Diagnostic]] = {}
"""Recorded diagnostics."""
def add_role(
self,
name: str,
Expand Down Expand Up @@ -162,10 +165,9 @@ def _report_missing_extension(self, extname: str, exc: Exception):
range=range_, message=str(cause), severity=types.DiagnosticSeverity.Error
)

# TODO: Move the set of diagnostics somewhere more central.
uri = types.Uri.for_file(conf_py)
logger.debug("Adding diagnostic %s: %s", uri, diagnostic)
self.esbonio.log.diagnostics.setdefault(uri, set()).add(diagnostic)
self.esbonio.diagnostics.setdefault(uri, set()).add(diagnostic)


def find_extension_declaration(mod: ast.Module, extname: str) -> types.Range | None:
Expand Down
4 changes: 2 additions & 2 deletions lib/esbonio/esbonio/sphinx_agent/handlers/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ def init_db(app: Sphinx, config: Config):
def clear_diagnostics(app: Sphinx, docname: str, source):
"""Clear the diagnostics assocated with the given file."""
uri = Uri.for_file(app.env.doc2path(docname, base=True))
app.esbonio.log.diagnostics.pop(uri, None)
app.esbonio.diagnostics.pop(uri, None)


def sync_diagnostics(app: Sphinx, *args):
app.esbonio.db.clear_table(DIAGNOSTICS_TABLE)

results = []
diagnostics = app.esbonio.log.diagnostics
diagnostics = app.esbonio.diagnostics

for uri, items in diagnostics.items():
for item in items:
Expand Down
3 changes: 1 addition & 2 deletions lib/esbonio/esbonio/sphinx_agent/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def __init__(self, app, *args, **kwargs):
super().__init__(*args, **kwargs)

self.app = app
self.diagnostics: dict[Uri, set[types.Diagnostic]] = {}

def filter(self, record: logging.LogRecord) -> bool:
conditions = [
Expand Down Expand Up @@ -76,7 +75,7 @@ def filter(self, record: logging.LogRecord) -> bool:
),
)

self.diagnostics.setdefault(uri, set()).add(diagnostic)
self.app.esbonio.diagnostics.setdefault(uri, set()).add(diagnostic)
return True


Expand Down

0 comments on commit 603fe1d

Please sign in to comment.