diff --git a/phpstorm-url-handler b/phpstorm-url-handler index 7e33fd8..720f61b 100755 --- a/phpstorm-url-handler +++ b/phpstorm-url-handler @@ -20,11 +20,23 @@ file=$(echo "${arg}" | sed -r "s/${pattern}/\2/") # Get the line number. line=$(echo "${arg}" | sed -r "s/${pattern}/\4/") +# Since PhpStorm 2026.2, --line is only accepted when a project directory +# is passed as the first argument. Resolve it from the target file's git root. +project=$(cd "$(dirname "${file}")" 2>/dev/null && git rev-parse --show-toplevel 2>/dev/null) + # Check if phpstorm|pstorm command exist. if type phpstorm > /dev/null; then - /usr/bin/env phpstorm --line "${line}" "${file}" + if [ -n "${project}" ]; then + /usr/bin/env phpstorm "${project}" --line "${line}" "${file}" + else + /usr/bin/env phpstorm --line "${line}" "${file}" + fi elif type pstorm > /dev/null; then - /usr/bin/env pstorm --line "${line}" "${file}" + if [ -n "${project}" ]; then + /usr/bin/env pstorm "${project}" --line "${line}" "${file}" + else + /usr/bin/env pstorm --line "${line}" "${file}" + fi fi if type wmctrl > /dev/null; then