Skip to content
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

[ros2interface] Fixes inline comments for constants #548

Merged
merged 1 commit into from
Jul 1, 2020
Merged
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
19 changes: 18 additions & 1 deletion ros2interface/ros2interface/verb/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from ros2interface.verb import VerbExtension
from rosidl_adapter.parser import \
ACTION_REQUEST_RESPONSE_SEPARATOR, \
Constant, \
Field, \
MessageSpecification, \
parse_message_string, \
Expand Down Expand Up @@ -56,8 +57,17 @@ def is_comment(self) -> bool:
return self._msg_spec and self._msg_spec.annotations['comment']

def is_trailing_comment(self) -> bool:
return (
self._is_field_trailing_comment()
or self._is_constant_trailing_comment()
)

def _is_field_trailing_comment(self) -> bool:
return self._field and self._field.annotations['comment']

def _is_constant_trailing_comment(self) -> bool:
return self._constant and self._constant.annotations['comment']

@property
def nested_type(self) -> typing.Optional[str]:
if self._field and self._is_nested():
Expand All @@ -68,8 +78,10 @@ def nested_type(self) -> typing.Optional[str]:

@property
def trailing_comment(self) -> typing.Optional[str]:
dirk-thomas marked this conversation as resolved.
Show resolved Hide resolved
if self.is_trailing_comment():
if self._is_field_trailing_comment():
return self._field.annotations['comment'][0]
elif self._is_constant_trailing_comment():
return self._constant.annotations['comment'][0]
else:
return None

Expand All @@ -78,6 +90,11 @@ def _field(self) -> typing.Optional[Field]:
if self._msg_spec and self._msg_spec.fields:
return self._msg_spec.fields[0]

@property
def _constant(self) -> typing.Optional[Constant]:
if self._msg_spec and self._msg_spec.constants:
return self._msg_spec.constants[0]

def _is_nested(self) -> bool:
if self._msg_spec and self._msg_spec.fields:
return '/' in str(self._field.type)
Expand Down