Noam-Dori / ros-integrate

Extends IntelliJ-Based IDEs with ROS specific development tools
Apache License 2.0
22 stars 3 forks source link

Ignore assigned but unused error for subscriptions and service servers #65

Open jukindle opened 3 years ago

jukindle commented 3 years ago

Feature: Customized inspector which ignores assigned but unused errors for ROS communication inputs.

Background When writing a node in c++, subscriptions (ros::Subscriber) and service servers (ros::ServiceServer) are quite often assigned but not used afterwards since the callback is directly registered in the constructor. This leads to the problem that IntelliJ marks those members as "Field MEMBER_NAME is assigned but never accessed" .

Details I do not know how flexible IntelliJ is in sense of writing custom inspectors, but it would be a great addition to exclude subscribers and service servers from that check since when using ROS, it seems to be quite common to never access the subscriber after initialization - however, the variable to which it is assigned to needs to remain existing for the callback function to work.

Noam-Dori commented 3 years ago

Hi jukindle,

IntelliJ (or in this case, CLion) is flexible in terms of modifying inspections, and it should be possible to disable the inspection automatically via the plugin.

I do plan on implementing this feature in the future, but it requires C++ specific features, something the plugin doesn't know how to deal with yet. For now, it is possible to suppress the warning manually, via

#pragma clang diagnostic push
#pragma ide diagnostic ignored "UnusedLocalVariable"
    // ... subscriber init code
#pragma clang diagnostic pop