place start-bloop.sh
in /usr/local/bin
make it executable:
chmod 755 /usr/local/bin/start-bloop.sh
Add bloop.json
in project_root_dir/.bsp/bloop.json
{ | |
"name": "Bloop", | |
"version": "1.5.6", | |
"bspVersion": "2.0.0", | |
"languages": [ | |
"scala" | |
], | |
"argv": [ | |
"/usr/local/bin/start-bloop.sh" | |
] | |
} |
#!/bin/bash | |
is_mac() { | |
test "$(uname -s)" = "Darwin" | |
} | |
is_linux() { | |
test "$(uname)" = "Linux" | |
} | |
# Block until the given file appears or the given timeout is reached. | |
# Exit status is 0 iff the file exists. | |
wait_file() { | |
local file="$1"; shift | |
local wait_seconds="${1:-10}"; shift # 10 seconds as default timeout | |
test $wait_seconds -lt 1 && echo "At least 1 second is required" && return 1 | |
until test $((wait_seconds--)) -eq 0 -o -e "$file" ; do sleep 1; done | |
test $wait_seconds -ge 0 # equivalent: let ++wait_seconds | |
} | |
echoerr() { | |
printf "%s\n" "$*" >&2; | |
} | |
if is_mac; then | |
DARWIN_BASE="$HOME/Library/Application Support/Coursier/bin" | |
if [ -f "$DARWIN_BASE/bloop-jvm" ]; then | |
BLOOP="$DARWIN_BASE/bloop-jvm" | |
elif [ -f "$DARWIN_BASE/bloop" ]; then | |
BLOOP="$DARWIN_BASE/bloop" | |
fi | |
if [ "Z$BLOOP" == "Z" ]; then | |
DARWIN_BASE="/usr/local/bin" #homebrew | |
if [ -f "$DARWIN_BASE/bloop" ]; then | |
BLOOP="$DARWIN_BASE/bloop" | |
fi | |
fi | |
elif is_linux; then | |
LINUX_BASE=$HOME/.local/share/coursier/bin | |
if [ -f "$LINUX_BASE/bloop" ]; then | |
BLOOP="$LINUX_BASE/bloop" | |
fi | |
fi | |
if [ "Z$BLOOP" == "Z" ]; then | |
BLOOP_BIN=$HOME/.bloop/bin/bloop | |
if [ -f "$BLOOP_BIN" ]; then | |
BLOOP="$BLOOP_BIN" | |
fi | |
fi | |
if [ "Z$BLOOP" == "Z" ]; then | |
echoerr "bloop is not installed" | |
exit 1 | |
fi | |
echoerr "BLOOP is '$BLOOP'" | |
temp_dir=$(mktemp -d) | |
socketPath="$temp_dir/bsp.socket" | |
if [ -e $socketPath ]; then | |
rm $socketPath | |
fi | |
#default port is 8212, should we support tcp sockets as well? | |
exec "$BLOOP" bsp --protocol local --socket $socketPath --no-color & | |
if [ -e $socketPath ]; then | |
echoerr "socket file exists" | |
fi | |
echoerr "Waiting for connection..." | |
wait_file "$socketPath" 30 || { | |
echoerr "BSP socket file missing after waiting for 30 seconds: '$socketPath'" | |
exit 1 | |
} | |
nc -U $socketPath |