diff --git a/sphinx_js/__init__.py b/sphinx_js/__init__.py index 431560a1..fb4a9834 100644 --- a/sphinx_js/__init__.py +++ b/sphinx_js/__init__.py @@ -141,7 +141,7 @@ def setup(app: Sphinx) -> None: "js_source_path", default=["../"], rebuild="env", types=[str, list] ) app.add_config_value("jsdoc_config_path", default=None, rebuild="env") - app.add_config_value("ts_xref_formatter", None, "env") + app.add_config_value("ts_type_xref_formatter", None, "env") app.add_config_value("ts_should_destructure_arg", None, "env") app.add_config_value("ts_post_convert", None, "env") diff --git a/sphinx_js/renderers.py b/sphinx_js/renderers.py index f0b5bf6b..c8a58549 100644 --- a/sphinx_js/renderers.py +++ b/sphinx_js/renderers.py @@ -55,7 +55,7 @@ class JsRenderer: _renderer_type: Literal["function", "class", "attribute"] _template: str - _xref_formatter: Callable[[TypeXRef], str] + _type_xref_formatter: Callable[[TypeXRef], str] _partial_path: list[str] _explicit_formal_params: str _content: list[str] @@ -64,17 +64,17 @@ class JsRenderer: def _template_vars(self, name: str, obj: TopLevel) -> dict[str, Any]: raise NotImplementedError - def _set_xref_formatter( + def _set_type_xref_formatter( self, formatter: Callable[[Config, TypeXRef], str] | None ) -> None: if formatter: - self._xref_formatter = partial(formatter, self._app.config) + self._type_xref_formatter = partial(formatter, self._app.config) return - def default_xref_formatter(xref: TypeXRef) -> str: + def default_type_xref_formatter(xref: TypeXRef) -> str: return xref.name - self._xref_formatter = default_xref_formatter + self._type_xref_formatter = default_type_xref_formatter def __init__( self, @@ -90,7 +90,7 @@ def __init__( self._directive = directive self._app = app - self._set_xref_formatter(app.config.ts_xref_formatter) + self._set_type_xref_formatter(app.config.ts_type_xref_formatter) # content, arguments, options, app: all need to be accessible to # template_vars, so we bring them in on construction and stow them away @@ -313,7 +313,7 @@ def strs() -> Iterator[str]: return r"\ ".join(res) def render_xref(self, s: TypeXRef, escape: bool = False) -> str: - result = self._xref_formatter(s) + result = self._type_xref_formatter(s) if escape: result = rst.escape(result) return result diff --git a/tests/test_build_ts/source/docs/conf.py b/tests/test_build_ts/source/docs/conf.py index 0912e003..19ba8f72 100644 --- a/tests/test_build_ts/source/docs/conf.py +++ b/tests/test_build_ts/source/docs/conf.py @@ -13,7 +13,7 @@ from sphinx_js.ir import TypeXRefInternal -def ts_xref_formatter(config, xref): +def ts_type_xref_formatter(config, xref): if isinstance(xref, TypeXRefInternal): name = rst.escape(xref.name) return f":js:class:`{name}`" diff --git a/tests/test_renderers.py b/tests/test_renderers.py index e0b8b512..74c2f843 100644 --- a/tests/test_renderers.py +++ b/tests/test_renderers.py @@ -72,7 +72,7 @@ class _app: renderer._app = _app renderer._explicit_formal_params = None renderer._content = [] - renderer._set_xref_formatter(ts_xref_formatter) + renderer._set_type_xref_formatter(ts_xref_formatter) return renderer @@ -246,7 +246,7 @@ def xref_render(config, val): res.append([config, val]) return val.package + "::" + val.name - function_renderer._set_xref_formatter(xref_render) + function_renderer._set_type_xref_formatter(xref_render) assert function_renderer.render_type([xref_external]) == "blah::A" assert res[0][0] == function_renderer._app.config assert res[0][1] == xref_external