Created
September 13, 2024 02:27
-
-
Save nightcycle/6f6d194d522d358454d0c3b2ab6e8413 to your computer and use it in GitHub Desktop.
Create selene inspired more readable errors for whenever you use luau-lsp analyze
This file contains 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
#!/bin/sh | |
# make a temp file | |
lsp_results=$(mktemp) | |
set +e | |
luau-lsp analyze "src" 2> "$lsp_results" #obvs swap this out to your actual lsp call | |
set -e | |
# iterate through the results | |
is_error=false | |
while IFS= read -r line; do | |
# if the line is empty, skip it | |
if [ -z "$line" ]; then | |
continue | |
fi | |
# create a variable called path_line which is the line up until the first "(" or "[" | |
path_line=$(echo "$line" | cut -d "(" -f 1) | |
# create a variable called min_path_line which is the line up to the first whitespace character | |
min_path_line=$(echo "$path_line" | cut -d " " -f 1) | |
echo "" | |
# get the contents of the first two colons in line | |
error_type=$(echo "$line" | sed -n 's/.*:\([^:]*\):.*/\1/p') | |
# remove whitespace from error_type | |
error_type=$(echo "$error_type" | tr -d '[:space:]') | |
# get the contents after the second colon in line | |
error_message=$(echo "$line" | sed -n 's/.*:.*: \(.*\)/\1/p') | |
echo -e "\e[31merror[$error_type]\e[0m: \"$error_message\"" | |
# get the contents of the first parentheses pair in line | |
line_numbers=$(echo "$line" | sed -n 's/.*(\([^)]*\)).*/\1/p') | |
echo " $min_path_line:($line_numbers)" | |
is_error=true | |
done < "$lsp_results" | |
if [ "$is_error" = true ]; then | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment