Skip to content

Instantly share code, notes, and snippets.

@hamnis
Last active July 31, 2023 05:12
Show Gist options
  • Save hamnis/64f16a34c29975586d9416723ddeeca7 to your computer and use it in GitHub Desktop.
Save hamnis/64f16a34c29975586d9416723ddeeca7 to your computer and use it in GitHub Desktop.
place start-bloop.sh in /usr/local/bin and bloop.json in project_root_dir/.bsp/bloop.json

Installation

place start-bloop.sh in /usr/local/bin

make it executable:

chmod 755 /usr/local/bin/start-bloop.sh

Project installation

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment