Announcing GitHub syntax highlighting for ROS msg files

Hi folks – wanted to share that msg/srv/action files are now highlighted with pretty colors on GitHub! :tada::rainbow: This works via a new ROS tmLanguage grammar that I added to GitHub Linguist.

For example, Imu.msg now looks like this:

You can also get highlighting in multi-line code blocks by tagging them with ```rosmsg.

The same syntax highlighting support is also available for Visual Studio Code via the Robotics Development Extensions maintained by @ooeygui.

Enjoy! I hope this makes your life just a little bit easier :smiling_face:

24 Likes

This is amazing and much appreciated!

I love that such a small change can have such a big impact on the entire ROS community.

2 Likes

@jtbandes really cool Jacob!! didn’t even realise that this could be done.

although, that the file extensions were at risk of over-matching was a concern that came to my mind, too, once learning it could be added upstream… nice work adding the negative pattern to filter out non-ros .msgs :smiling_face: :raising_hands:

just for my curiosity, do you remember why you included digits, underscores, and @ symbols in the “allowed” start of line characters for the negative match? haven’t seen them aroudn much in my idls, but by this point you’ve probably dug into the idl syntax a fair amount :face_with_tongue:

Yep, I think the GitHub folks are very sensitive to this since Linguist is a critical service used on most source files. I don’t think they would have accepted this patch without the negative patterns. And luckily ROS is widespread enough to meet the popularity requirements for adding new languages :flexed_biceps::turtle:

:eyes: great question! Digits and underscores might not actually be necessary there…I think I just didn’t find it important to exclude those in order to successfully filter out the non-ROS msg files (or just wrote \w out of habit). The @ is for the brand new @optional feature — I actually only learned about this feature when I was working on this project, but thought I might as well get ahead of it asap!

1 Like

@optional is quite cool but, I sadly have gotten busy with other issues so currently only the parsing and generating of the .idl is complete with it. Trying with a naive approach with std::optional breaks several assumptions that live in various rmws e.g. the size of a bool field is always 1 byte but a optional bool field would be 2 bytes due to how std::optional is implemented for example.