set -eou pipefail
. "$HOME/.ad/lib/ad.sh"
root="$(git rev-parse --show-toplevel)"
if [ -e "$root/Cargo.toml" ]; then
adCtl "echo running 'cargo clippy'..."
cmd="cd $root && cargo clippy -q --message-format=short --color=never --all-targets 2>&1"
line="$(tmux-select -c "$cmd" | cut -d' ' -f1)"
if [ -z "$line" ]; then
exit 0
fi
fname="$(echo "$line" | cut -d':' -f1)"
lnum="$(echo "$line" | cut -d':' -f2)"
col="$(echo "$line" | cut -d':' -f3)"
adCtl "open $root/$fname"
bufid="$(currentBufferId)"
echo -n "$lnum:$col" | bufWrite "$bufid" "addr"
adCtl "viewport-center"
else
adCtl "echo not linters configured for this file/project type"
exit 1
fi