Skip to content

Instantly share code, notes, and snippets.

@Loupax
Last active August 14, 2024 09:02
Show Gist options
  • Save Loupax/5f10c2df33d47d1e60af350145d802c0 to your computer and use it in GitHub Desktop.
Save Loupax/5f10c2df33d47d1e60af350145d802c0 to your computer and use it in GitHub Desktop.
Script that lists all the usages of the passed function reference.
#!/usr/bin/env bash
# Example usage: gorefs file.go:10:6
gopls references $1 | while IFS=: read -r file line cols; do
start_col=$(echo $cols | cut -d'-' -f1)
end_col=$(echo $cols | cut -d'-' -f2)
content=$(sed -n "${line}p" "$file")
file="./$(realpath --relative-to="$(pwd)" $file)"
# Extract the part of the line starting from the column position
trimmed_content="${content:start_col-1}"
echo $(echo "$file:$line:$cols $trimmed_content" | awk '{$1=$1; print}')
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment