Last active
June 9, 2020 13:49
-
-
Save greydot/4e8b05a699437623fb0e53e2e92aff3c to your computer and use it in GitHub Desktop.
Wraps around Haskell LSP servers and runs one in nix-shell if available. Requires yq if hie.yaml is present.
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 | |
SERVERS=( haskell-language-server-wrapper hie-wrapper haskell-language-server hie ghcide ) | |
SERVER= | |
SERVER_PATH= | |
NIX_FILES=( shell.nix default.nix nix/shell.nix nix/default.nix ) | |
NIX_CMD= | |
HIE_CRADLE= | |
for srv in ${SERVERS[@]}; do | |
if hash "$srv"; then | |
SERVER="$srv" | |
SERVER_PATH="$(which "$srv")" | |
SERVER_PATH="$(dirname "$SERVER_PATH")" | |
break | |
fi | |
done | |
if [ -z "$SERVER" ]; then | |
echo "Unable to locate any Haskell LSP servers. Exiting." | |
exit 1 | |
fi | |
for f in ${NIX_FILES[@]}; do | |
if test -f "$f"; then | |
NIX_CMD="nix-shell $f --run bash" | |
break | |
fi | |
done | |
SHELL_CMD=$(cat <<- EOF | |
export PATH="$SERVER_PATH:$PATH" | |
$SERVER $@ | |
EOF | |
) | |
if test -f hie.yaml; then | |
HIE_CRADLE=$(cat hie.yaml | yq ".cradle | keys | .[0]" | tr -d '"') | |
fi | |
# Stack doesn't work inside nix-shell, so we don't wanna run it that way. | |
# Hence, if nix-shell is available, run anything but stack there. | |
# Otherwise run without nix-shell. | |
if [ "$HIE_CRADLE" != "stack" ] && [ ! -z "$NIX_CMD" ]; then | |
$NIX_CMD <<< "$SHELL_CMD" | |
else | |
$SERVER $@ | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment