athackst / vscode_ros2_workspace

A template for using VSCode as an IDE for ROS2 development.
https://althack.dev/vscode_ros2_workspace
Apache License 2.0
857 stars 177 forks source link

Question about sourcing ROS #73

Closed vik748 closed 7 months ago

vik748 commented 9 months ago

Hi, thanks for this great set of tools and settings, it is tremendously useful. I am trying to use this on my local machine and running into a couple issues. All the tasks that are type 'shell' seem to be working fine. However, I run into an issue with the 'ament' type tasks.

eg. when I run the flake8 task, it says ament_flake8 command not found. Is there a way to add a 'source /opt/ros/humble/setup.bash' before the tasks run?

athackst commented 7 months ago

It should be doing that already - I'll see if I can reproduce. What docker image ar you using?

vik748 commented 7 months ago

I am using it without docker.

athackst commented 7 months ago

That's probably the issue, the workspace was made to run with a docker. I'll look into updating the plugin to source before running itself.

In the meantime you can try either of the following:

  1. Source the terminal you're in before starting vscode
source /opt/ros/humble/setup.bash
code .
  1. Add a dedicated source task and add it as a dependency of the ament tasks

tasks.json

        {
            "label": "source",
            "detail": "Source workspace",
            "type": "shell",
            "command": "source /opt/ros/humble/setup.bash",
            "problemMatcher": []
        },
        {
            "label": "cpplint",
            "detail": "Lint files with cpplint.",
            "type": "ament",
            "task": "cpplint",
            "path": "src/",
            "problemMatcher": "$ament_cpplint",
            "presentation": {
                "reveal": "silent",
                "clear": true
            },
            "dependsOn": ["source"],
            "dependsOrder": "sequence"
        },
athackst commented 7 months ago

Ok, I updated the ament task provider extension so you can specify a pre-run command. Update that plugin and pull the latest.

vik748 commented 7 months ago

@athackst thanks for the PRs. This helps make everything work smoothly.