Skip to content

Conversation

@imcelroy
Copy link
Contributor

@imcelroy imcelroy commented Apr 4, 2025

Public API Changes

None

Description

This will add a new namespace called descriptor for each ROS package interface generated by generate-ros-messages. The new namespace is found inside the msg|srv|action namespace for each package. For example:

namespace builtin_interfaces {
    namespace msg {
      export interface Duration {
        sec: number;
        nanosec: number;
      }
      export interface DurationConstructor {
        new(other?: Duration): Duration;
      }
      export interface Time {
        sec: number;
        nanosec: number;
      }
      export interface TimeConstructor {
        new(other?: Time): Time;
      }
      namespace descriptor {
        export interface Duration {
          sec: 'int32';
          nanosec: 'uint32';
        }
        export interface Time {
          sec: 'int32';
          nanosec: 'uint32';
        }
      }
    }
  }

The descriptor interfaces always have the format {field: "<interface_type>"}. For example:

  namespace geometry_msgs {
    namespace msg {
      namespace descriptor {
        export interface PointStamped {
          header: 'std_msgs/msg/Header';
          point: 'geometry_msgs/msg/Point';
        }
      }
    } 
  }  

Here is the discussion: discussions/1091

@imcelroy
Copy link
Contributor Author

imcelroy commented Apr 4, 2025

Hi @minggangw, I would like to add a couple unit tests, but I'm not sure where/how you test the content of the interfaces.d.ts file? If you could point me in the right direction I'll add the unit tests and then open this for review!

@coveralls
Copy link

coveralls commented Apr 4, 2025

Coverage Status

coverage: 85.325% (-0.03%) from 85.355%
when pulling 507c93d on imcelroy:add-descriptor-namespaces
into baba669 on RobotWebTools:develop.

@minggangw
Copy link
Member

Hi @imcelroy thanks for submitting the PR quickly, be honest, currently, we don't have kind of unit test targeting on the generated messages for typescript specifically.

We have https://github.com/RobotWebTools/rclnodejs/blame/develop/test/types/index.test-d.ts that leverages dst to test the type definitions, I think we can add some test cases that verify the generated types under descriptor namespace, we don't need to test each, but one or two at least, how do you think?

@imcelroy
Copy link
Contributor Author

imcelroy commented Apr 7, 2025

Hi @minggangw, yes that sounds good to me! I will take a look and add those asap.

@imcelroy imcelroy marked this pull request as ready for review April 7, 2025 08:38
@imcelroy
Copy link
Contributor Author

imcelroy commented Apr 7, 2025

@minggangw I have added the unit tests and opened this for review, thanks for your help!

@imcelroy
Copy link
Contributor Author

imcelroy commented Apr 7, 2025

@minggangw It's strange, npx tsd is passing for me locally, I'm not sure why it isn't passing in the CI. I'm looking into this, but if you have any ideas let me know.

@imcelroy
Copy link
Contributor Author

imcelroy commented Apr 7, 2025

All seems to be good now! The Windows build that is failing seems to be present on other pull requests as well, and not directly linked to my changes. Will that block us from merging this feature?

@minggangw
Copy link
Member

All seems to be good now! The Windows build that is failing seems to be present on other pull requests as well, and not directly linked to my changes. Will that block us from merging this feature?

I suspect the failure on Windows platform may be caused by env changes, because all tests do pass on ROS2 jazzy build. I will start the review work soon, thanks!

@minggangw minggangw requested a review from Copilot April 8, 2025 02:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

useSamePkg,
descriptorInterfaceType
);
const tmplEnd = indentString('}\n', indentlevel);
Copy link

Copilot AI Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the saveMsgAsTSD function, there is an inconsistency between the variable names 'indentlevel' and 'indentLevel'. This may lead to formatting issues; consider using a consistent variable name throughout the function.

Copilot uses AI. Check for mistakes.
Copy link
Member

@minggangw minggangw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting the PR, the implementation looks good and some comments left.

}

function saveMsgAsTSD(rosMsgInterface, fd, descriptorInterfaceType = false) {
const indentlevel = descriptorInterfaceType ? 8 : 6;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I prefer renaming indentlevel because it confused with indentLevel on L.292

typePrefix = '',
useSamePackageSubFolder = false
useSamePackageSubFolder = false,
descriptorInterfaceType = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer renaming descriptorInterfaceType to willGenerateDescriptionInterface

);
expectAssignable<'action_msgs/msg/GoalInfo'>(
cancelGoalRequestDescriptor.goal_info
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really like these ut 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


// generate descriptor msg/srv/action interfaces
fs.writeSync(fd, ` namespace ${descriptorInterfaceNamespace} {\n`);
const descriptorInterfaceType = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

descriptorInterfaceType => willGenerateDescriptionInterface

isInternalServiceEventMsgInterface(rosMsgInterface);
saveMsgFieldsAsTSD(rosMsgInterface, fd, 8, ';', '', useSamePkg);
fs.writeSync(fd, ' }\n');
const indentLevel = descriptorInterfaceType ? 10 : 8;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to abstract the functionality of getting the value of indent to a separate function in this file?

@minggangw
Copy link
Member

You can add your name into https://github.com/RobotWebTools/rclnodejs/blob/develop/CONTRIBUTORS.md, it's up to you 😄

imcelroy added 2 commits April 8, 2025 09:51
- rename willGenerateDescriptorInterface
- create getIndentSpacing funciton
- avoid similar indentLevel variable names
@imcelroy
Copy link
Contributor Author

imcelroy commented Apr 8, 2025

@minggangw Thank you for the review! I think I have addressed all of your comments, let me know what you think!

Copy link
Member

@minggangw minggangw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@minggangw minggangw merged commit 1b6cf74 into RobotWebTools:develop Apr 8, 2025
10 of 11 checks passed
@minggangw
Copy link
Member

@imcelroy I have merged the PR, if you want to land the change in a new release asap, let me know, I can prepare for it this week.

@imcelroy
Copy link
Contributor Author

imcelroy commented Apr 8, 2025

@minggangw Thank you very much! Yes, if you could add this to a new release asap that would be great! I appreciate it!

@imcelroy imcelroy deleted the add-descriptor-namespaces branch April 8, 2025 08:35
minggangw pushed a commit that referenced this pull request Apr 8, 2025
This will add a new namespace called `descriptor` for each ROS package interface generated by `generate-ros-messages`. The new namespace is found inside the msg|srv|action namespace for each package. For example:

```typescript
namespace builtin_interfaces {
    namespace msg {
      export interface Duration {
        sec: number;
        nanosec: number;
      }
      export interface DurationConstructor {
        new(other?: Duration): Duration;
      }
      export interface Time {
        sec: number;
        nanosec: number;
      }
      export interface TimeConstructor {
        new(other?: Time): Time;
      }
      namespace descriptor {
        export interface Duration {
          sec: 'int32';
          nanosec: 'uint32';
        }
        export interface Time {
          sec: 'int32';
          nanosec: 'uint32';
        }
      }
    }
  }
``` 
The descriptor interfaces always have the format `{field: "<interface_type>"}`. For example:

```typescript
  namespace geometry_msgs {
    namespace msg {
      namespace descriptor {
        export interface PointStamped {
          header: 'std_msgs/msg/Header';
          point: 'geometry_msgs/msg/Point';
        }
      }
    } 
  }  
```

Here is the discussion: [discussions/1091](#1091)
@minggangw
Copy link
Member

@imcelroy https://www.npmjs.com/package/rclnodejs/v/0.33.0 is online 🎉

@imcelroy
Copy link
Contributor Author

imcelroy commented Apr 8, 2025

@minggangw wow! Thank you very much for the speed; that was impressive! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants