Skip to content

Rename xref_formatter to type_xref_formatter #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sphinx_js/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
14 changes: 7 additions & 7 deletions sphinx_js/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -311,7 +311,7 @@ def strs() -> Iterator[str]:
return "".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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_build_ts/source/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}`"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -240,7 +240,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
Expand Down