Created
October 28, 2023 19:50
-
-
Save matheusfillipe/1d907272717201501eafe0e91b858176 to your computer and use it in GitHub Desktop.
Unreal Engine nvim wrapper for ue4cli (Completion + Debugger with vimspect)
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
# #!/usr/bin/env bash | |
# Based on https://gist.github.com/chillpert/1a76ae8e9cfafb36d3bf9e343d32fedc | |
# Expand ue4cli | |
ue() { | |
ue4cli=$(which ue4) | |
engine_path=$($ue4cli root) | |
UPROJECT_PATH=$(realpath $(find . -name *.uproject)) | |
DEBUG_BINARY_PATH="/Users/Shared/Epic Games/UE_5.3/Engine/Binaries/Mac/UnrealEditor-Mac-DebugGame.app/Contents/MacOS/UnrealEditor-Mac-DebugGame" | |
project_name=$(basename "$UPROJECT_PATH" | sed 's/.uproject//') | |
if [[ -z "$UPROJECT_PATH" ]]; then | |
echo "Please run this script from the root of your project." | |
echo "No uproject file found in current directory" | |
return 1 | |
fi | |
# cd to ue location | |
if [[ "$1" == "engine" ]]; then | |
cd $engine_path | |
# combine clean and build in one command | |
elif [[ "$1" == "rebuild" ]]; then | |
$ue4cli clean | |
$ue4cli build | |
if [[ "$2" == "run" ]]; then | |
$ue4cli run | |
fi | |
# build and optionally run while respecting build flags | |
elif [[ "$1" == "build" ]]; then | |
if [[ "${@: -1}" == "run" ]]; then | |
length="$(($# - 2))" # Get length without last param because of 'run' | |
$ue4cli build ${@:2:$length} | |
$ue4cli run | |
else | |
shift 1 | |
$ue4cli build "$@" | |
fi | |
# Build debug version | |
elif [[ "$1" == "debug" ]]; then | |
$ue4cli build DebugGame -waitmutex | |
# Run project files generation, create a symlink for the compile database and fix-up the compile database | |
elif [[ "$1" == "gen" ]]; then | |
$ue4cli gen | |
project=${PWD##*/} | |
rm compile_commands.json | |
ln -s ".vscode/compileCommands_${project}.json" compile_commands.json | |
# write cflags to file | |
cat <<EOF > clang-flags.txt | |
-std=c++20 | |
-ferror-limit=0 | |
-Wall | |
-Wextra | |
-Wpedantic | |
-Wshadow-all | |
-Wno-unused-parameter | |
EOF | |
cat <<EOF > .vimspector.json | |
{ | |
"configurations": { | |
"Launch": { | |
"adapter": "vscode-cpptools", | |
"configuration": { | |
"request": "launch", | |
"program": "$DEBUG_BINARY_PATH", | |
"args": [ "$UPROJECT_PATH" ], | |
"cwd": "$engine_path", | |
"externalConsole": false, | |
"MIDebuggerPath": "/usr/bin/lldb", | |
"targetArchitecture": "arm64", | |
"MIMode": "lldb" | |
} | |
} | |
} | |
} | |
EOF | |
replace_string="clang++\"\,\n\t\t\t\"@$(pwd)/clang-flags.txt\"\," | |
gsed -i -e "s,clang++\"\,,$replace_string,g" compile_commands.json | |
# Generate ctags for project and optionally the engine itself with `ue ctags` and `ue ctags engine` respectively. | |
elif [[ "$1" == "ctags" ]]; then | |
if [[ "$2" == "engine" ]]; then | |
echo "Generating ctags database for unreal engine" | |
`brew --prefix`/bin/ctags -R --c++-kinds=+p --fields=+iaS --extras=+q --languages=C++ "$engine_path/Engine/Source" | |
echo "Generation completed." | |
fi | |
echo "Generating ctags database in current directory ..." | |
`brew --prefix`/bin/ctags -R Source | |
echo "Generation completed." | |
# Pass through all other commands to ue4 | |
else | |
$ue4cli "$@" | |
fi | |
} | |
ue $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment