Skip to content

Commit

Permalink
Rename xref_formatter to type_xref_formatter to be a bit more specific
Browse files Browse the repository at this point in the history
  • Loading branch information
hoodmane committed Sep 28, 2023
1 parent 7d9916b commit edbda80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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

0 comments on commit edbda80

Please sign in to comment.