Skip to content

Commit

Permalink
NFC Improve comment getters (#78)
Browse files Browse the repository at this point in the history
This makes a few comment getters return more useful comments from children
rather than their own generally empty comment fields.
  • Loading branch information
hoodmane authored Sep 28, 2023
1 parent 00c17fb commit 4674ff4
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion sphinx_js/typedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ def get_tag_one(self, tag: str) -> Sequence[ir.DescriptionItem]:
return description_to_ir(l[0])


DEFAULT_COMMENT = Comment()


class Flags(BaseModel):
isAbstract: bool = False
isExternal: bool = False
Expand Down Expand Up @@ -525,6 +528,12 @@ class Callable(NodeBase):
]
signatures: list["Signature"] = []

@property
def comment(self) -> Comment:
if self.comment_ != DEFAULT_COMMENT:
return self.comment_
return self.signatures[0].comment_

def _path_segments(self, base_dir: str) -> list[str]:
return [self.name]

Expand Down Expand Up @@ -686,6 +695,14 @@ class TypeLiteral(NodeBase):
indexSignature: "Signature | None" = None
children: Sequence["Member"] = []

@property
def comment(self) -> Comment:
if self.comment_ != DEFAULT_COMMENT:
return self.comment_
if self.signatures:
return self.signatures[0].comment
return DEFAULT_COMMENT

def render(self, converter: Converter) -> Iterator[str | ir.TypeXRef]:
if self.signatures:
yield from self.signatures[0].render(converter)
Expand Down Expand Up @@ -767,7 +784,11 @@ class Param(Base):

@property
def comment(self) -> Comment:
return self.comment_
if self.comment_ != DEFAULT_COMMENT:
return self.comment_
if isinstance(self.type, ReflectionType):
return self.type.declaration.comment
return DEFAULT_COMMENT

defaultValue: str | None
flags: Flags
Expand Down

0 comments on commit 4674ff4

Please sign in to comment.