#!/bin/bash
if [ -z "$ROS_DISTRO" ]; then
    if [ -d /opt/ros ]; then
        ROS_DISTRO=$(ls -1 /opt/ros | head -n1)
    fi
fi

if [ -n "$ROS_DISTRO" ] && [ -f /opt/ros/$ROS_DISTRO/setup.bash ]; then
    source /opt/ros/$ROS_DISTRO/setup.bash
fi

if [ -f "$HOME/ros_ws/install/setup.bash" ]; then
    source "$HOME/ros_ws/install/setup.bash"
elif [ -f "$HOME/ros_ws/devel/setup.bash" ]; then
    source "$HOME/ros_ws/devel/setup.bash"
fi

if [ -f /opt/venv/bin/activate ]; then
    source /opt/venv/bin/activate
fi

exec /usr/local/bin/pylsp "$@"
