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": "2", | |
| "bspVersion": "2.0.0", | |
| "languages": [ | |
| "scala" | |
| ], | |
| "argv": [ | |
| "/usr/local/bin/start-bloop.sh" | |
| ] | |
| } |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!-- Put this file in .idea/bsp.xml --> | |
| <project version="4"> | |
| <component name="BspSettings"> | |
| <option name="linkedExternalProjectsSettings"> | |
| <BspProjectSettings> | |
| <option name="externalProjectPath" value="$PROJECT_DIR$" /> | |
| <option name="modules"> | |
| <set> | |
| <option value="$PROJECT_DIR$" /> | |
| </set> | |
| </option> | |
| <option name="runPreImportTask" value="false" /> | |
| </BspProjectSettings> | |
| </option> | |
| </component> | |
| </project> |
| #!/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; | |
| } | |
| BLOOP=$(command -v bloop) | |
| if [ "Z$BLOOP" == "Z" ]; then | |
| 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 | |
| DARWIN_BASE="/opt/homebrew/bin" #homebrew aarch64 | |
| 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 | |
| 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 |
I have built a new version of this which uses bloop-rife under the hood. So you dont really need to install bloop. Please give it a go and test it out: https://github.com/hamnis/embedded-bloop/releases/tag/v0.1.0 . I have made native-images for most useful platforms.
thanks, updated the gist