Last active
August 14, 2024 09:02
-
-
Save Loupax/5f10c2df33d47d1e60af350145d802c0 to your computer and use it in GitHub Desktop.
Script that lists all the usages of the passed function reference.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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