2021-10-19 15:21:57 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2022-05-09 13:59:26 +00:00
|
|
|
. ~/.config/sh-utils/echo.sh
|
2021-10-19 15:21:57 +00:00
|
|
|
|
|
|
|
usage () {
|
2021-11-19 16:13:59 +00:00
|
|
|
case $1 in
|
|
|
|
install)
|
|
|
|
usage_install; exit 0 ;;
|
|
|
|
uninstall)
|
|
|
|
usage_uninstall; exit 0 ;;
|
|
|
|
status)
|
|
|
|
usage_status; exit 0 ;;
|
|
|
|
link)
|
|
|
|
usage_link; exit 0 ;;
|
|
|
|
esac
|
|
|
|
if [ ! -z "$1" ]; then
|
|
|
|
echo -e "Unknown command: $1 \n"
|
|
|
|
fi
|
|
|
|
echo "Basic LSP (Language Server Protocol) manager."
|
|
|
|
echo "Manages installations of language servers."
|
|
|
|
echo -e "\nUsage: lsp COMMAND [options] [arguments] \n"
|
|
|
|
echo "Commands:"
|
|
|
|
echo " install - installs a new language server (or a new version of already installed one)"
|
|
|
|
echo " link - links previously installed language server to $HOME/.local/bin"
|
|
|
|
echo " status - prints status of servers installed (if server name is passed, prints status of that server)"
|
|
|
|
echo " uninstall - uninstalls a language server"
|
|
|
|
echo ""
|
|
|
|
echo "Options:"
|
|
|
|
echo " -h --help - prints this help message (if one of commands is passed, prints help message for that command)"
|
|
|
|
echo " -v --verbose - enables verbose logging"
|
|
|
|
if [ ! -z "$1" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-10-19 15:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
usage_install () {
|
2021-11-19 16:13:59 +00:00
|
|
|
echo "LSP Install"
|
|
|
|
echo "Installs a new language server. If language server is already installed, this overwrites that installation."
|
|
|
|
echo -e "\nUsage: lsp install [options] <server> [<version>] \n"
|
|
|
|
echo "Arguments:"
|
|
|
|
echo " server - name of server to install ('status --all' can be used to get a list of all)"
|
|
|
|
echo " version - optional argument representing version of server (otherwise default is used)"
|
|
|
|
echov " - version is hardcoded and could be outdated"
|
|
|
|
echo ""
|
|
|
|
echo "Options:"
|
|
|
|
echo " -l --link - automatically links installed binaries to $HOME/.local/bin"
|
|
|
|
echo " -h --help - prints this help message"
|
|
|
|
echo " -v --verbose - enables verbose logging"
|
|
|
|
echov "Examples:"
|
|
|
|
echov " > lsp install jdtls"
|
|
|
|
echov ""
|
|
|
|
echov " > lsp install jdtls 1.4.0"
|
2021-10-19 15:21:57 +00:00
|
|
|
}
|
|
|
|
|
2021-10-19 16:22:44 +00:00
|
|
|
usage_link () {
|
2021-11-19 16:13:59 +00:00
|
|
|
echo "LSP Link"
|
|
|
|
echo "Links installed language server. This can be automatically done when installing by passing -l flag."
|
|
|
|
echo -e "\nUsage: lsp link [options] <server> \n"
|
|
|
|
echo "Arguments:"
|
|
|
|
echo " server - name of server to link ('status' can be used to get a list of installed servers)"
|
|
|
|
echo ""
|
|
|
|
echo "Options:"
|
|
|
|
echo " -h --help - prints this help message"
|
|
|
|
echo " -v --verbose - enables verbose logging"
|
|
|
|
echov "Examples:"
|
|
|
|
echov " > lsp link jdtls"
|
2021-10-19 16:22:44 +00:00
|
|
|
}
|
|
|
|
|
2021-10-19 15:21:57 +00:00
|
|
|
usage_uninstall () {
|
2021-11-19 16:13:59 +00:00
|
|
|
echo "LSP Uninstall"
|
|
|
|
echo "Uninstalls a language server. Silently fails if server is not present."
|
|
|
|
echo -e "\nUsage: lsp uninstall [options] <server> \n"
|
|
|
|
echo "Arguments:"
|
|
|
|
echo " server - name of server to uninstall ('status' can be used to get a list of installed servers)"
|
|
|
|
echo ""
|
|
|
|
echo "Options:"
|
|
|
|
echo " -h --help - prints this help message"
|
|
|
|
echo " -v --verbose - enables verbose logging"
|
|
|
|
echov "Examples:"
|
|
|
|
echov " > lsp uninstall jdtls"
|
2021-10-19 15:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
usage_status () {
|
2021-11-19 16:13:59 +00:00
|
|
|
echo "LSP Status"
|
|
|
|
echo "Prints status of installed servers"
|
|
|
|
echo -e "\nUsage: lsp status [options] [<server>] \n"
|
|
|
|
echo "Arguments:"
|
|
|
|
echo " server - name of server or language to show status for"
|
|
|
|
echov " - if it does not exist, this tool tries to look for it in every language listed"
|
|
|
|
echo ""
|
|
|
|
echo "Options:"
|
|
|
|
echo " -k --known-only - shows only known servers"
|
|
|
|
echo " -a --all - shows servers which are not installed too"
|
|
|
|
echo " -h --help - prints this help message"
|
|
|
|
echo " -v --verbose - enables verbose logging"
|
|
|
|
echov ""
|
|
|
|
echov "Examples:"
|
2022-05-09 13:59:26 +00:00
|
|
|
echov " > lsp status java
|
|
|
|
"
|
2021-11-19 16:13:59 +00:00
|
|
|
echov " Language java:"
|
|
|
|
echov " Server google-java-format (UNKNOWN):"
|
2021-10-19 15:21:57 +00:00
|
|
|
echov " Installed: true"
|
|
|
|
echov " Version: UNKNOWN"
|
|
|
|
echov " Location: /Users/ensar.sarajcic/lsp/java/google-java-format"
|
|
|
|
echov " On path: false"
|
2021-11-19 16:13:59 +00:00
|
|
|
echov ""
|
2022-05-09 13:59:26 +00:00
|
|
|
echov " > lsp status java --all
|
|
|
|
"
|
2021-11-19 16:13:59 +00:00
|
|
|
echov " Language java:"
|
|
|
|
echov " Server google-java-format (UNKNOWN):"
|
2021-10-19 15:21:57 +00:00
|
|
|
echov " Installed: true"
|
|
|
|
echov " Version: UNKNOWN"
|
|
|
|
echov " Location: /Users/ensar.sarajcic/lsp/java/google-java-format"
|
|
|
|
echov " On path: false"
|
2021-11-19 16:13:59 +00:00
|
|
|
echov ""
|
2021-10-19 15:21:57 +00:00
|
|
|
echov " Server jdtls:"
|
|
|
|
echov " Installed: false"
|
|
|
|
}
|
|
|
|
|
|
|
|
POSITIONAL=()
|
|
|
|
HELP=0
|
|
|
|
VERBOSE=0
|
|
|
|
ALL=0
|
2021-10-19 16:22:44 +00:00
|
|
|
KNOWN_ONLY=0
|
|
|
|
LINK=0
|
2021-10-19 15:21:57 +00:00
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
key="$1"
|
|
|
|
|
|
|
|
case $key in
|
|
|
|
-h|--help)
|
|
|
|
HELP=1
|
|
|
|
shift # past argument
|
|
|
|
;;
|
|
|
|
-v|--verbose)
|
|
|
|
VERBOSE=1
|
|
|
|
shift # past argument
|
|
|
|
;;
|
|
|
|
-a|--all)
|
|
|
|
ALL=1
|
|
|
|
shift # past argument
|
|
|
|
;;
|
2021-10-19 16:22:44 +00:00
|
|
|
-k|--known-only)
|
|
|
|
KNOWN_ONLY=1
|
|
|
|
shift # past argument
|
|
|
|
;;
|
|
|
|
-l|--link)
|
|
|
|
LINK=1
|
|
|
|
shift # past argument
|
|
|
|
;;
|
2021-10-19 15:21:57 +00:00
|
|
|
*) # unknown option
|
|
|
|
POSITIONAL+=("$1") # save it in an array for later
|
|
|
|
shift # past argument
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
COMMAND="${POSITIONAL[0]}"
|
|
|
|
|
|
|
|
echov "Detected command: $COMMAND"
|
|
|
|
|
|
|
|
if [ $HELP -eq 1 ]; then
|
2021-11-19 16:13:59 +00:00
|
|
|
usage $COMMAND
|
|
|
|
exit 0
|
2021-10-19 15:21:57 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
UNAME=$(sh -c 'uname 2>/dev/null || echo Unknown')
|
|
|
|
if [[ "$UNAME" == "Windows_NT" ]]; then
|
2021-11-19 16:13:59 +00:00
|
|
|
UNAME="Windows"
|
2021-10-19 15:21:57 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echov "Detected host: $UNAME"
|
|
|
|
|
|
|
|
SERVER="${POSITIONAL[1]}"
|
|
|
|
VERSION="${POSITIONAL[2]}"
|
|
|
|
|
|
|
|
echov "Detected server: $SERVER"
|
|
|
|
echov "Detected version: $VERSION"
|
|
|
|
|
|
|
|
declare -A SUPPORTED_SERVERS=(
|
2021-11-19 16:13:59 +00:00
|
|
|
["java"]="jdtls"
|
|
|
|
["dotnet"]="omnisharp"
|
|
|
|
["haskell"]="hls"
|
|
|
|
["solidity"]="solang"
|
|
|
|
["xml"]="lemminx"
|
|
|
|
["kotlin"]="kotlin-language-server",
|
|
|
|
["rust"]="rust-analyzer"
|
2022-04-30 21:08:58 +00:00
|
|
|
["zig"]="zls"
|
2021-10-19 15:21:57 +00:00
|
|
|
)
|
2021-10-19 16:41:44 +00:00
|
|
|
declare -A LINK_SOURCES=(
|
2021-11-19 16:13:59 +00:00
|
|
|
["omnisharp"]="$HOME/lsp/dotnet/omnisharp/run"
|
|
|
|
["solang"]="$HOME/lsp/solidity/solang/solang"
|
|
|
|
["lemminx"]="$HOME/lsp/xml/lemminx/lemminx"
|
|
|
|
["kotlin-language-server"]="$HOME/lsp/kotlin/kotlin-language-server/bin/kotlin-language-server"
|
|
|
|
["rust-analyzer"]="$HOME/lsp/rust/rust-analyzer/rust-analyzer"
|
2022-04-30 21:08:58 +00:00
|
|
|
["zls"]="$HOME/lsp/zig/zls/zls"
|
2021-10-19 16:41:44 +00:00
|
|
|
)
|
|
|
|
declare -A LINK_TARGETS=(
|
2021-11-19 16:13:59 +00:00
|
|
|
["omnisharp"]="$HOME/.local/bin/omnisharp"
|
|
|
|
["solang"]="$HOME/.local/bin/solang"
|
|
|
|
["lemminx"]="$HOME/.local/bin/lemminx"
|
|
|
|
["kotlin-language-server"]="$HOME/.local/bin/kotlin-language-server"
|
|
|
|
["rust-analyzer"]="$HOME/.local/bin/rust-analyzer"
|
2022-04-30 21:08:58 +00:00
|
|
|
["zls"]="$HOME/.local/bin/zls"
|
2021-10-19 16:41:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
is_linked () {
|
2021-11-19 16:13:59 +00:00
|
|
|
SERVER=$1
|
|
|
|
SOURCE_TO_CHECK="${LINK_SOURCES[$SERVER]}"
|
|
|
|
TARGET_TO_CHECK="${LINK_TARGETS[$SERVER]}"
|
|
|
|
if [ -z "$SOURCE_TO_CHECK" ]; then
|
|
|
|
case $SERVER in
|
|
|
|
jdtls)
|
|
|
|
echo 1
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
hls)
|
2021-10-19 16:41:44 +00:00
|
|
|
echo 1
|
2021-11-19 16:13:59 +00:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo 0
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
if [ ! -f "$TARGET_TO_CHECK" ]; then
|
|
|
|
echo 0
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
if [ ! -f "$SOURCE_TO_CHECK" ]; then
|
|
|
|
echo 0
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
if [ "$SOURCE_TO_CHECK" != "$(readlink $TARGET_TO_CHECK)" ]; then
|
|
|
|
echo 0
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echo 1
|
2021-10-19 16:41:44 +00:00
|
|
|
}
|
2021-10-19 15:21:57 +00:00
|
|
|
|
2021-10-19 16:22:44 +00:00
|
|
|
link_server () {
|
2021-11-19 16:13:59 +00:00
|
|
|
SERVER=$1
|
|
|
|
SOURCE=""
|
|
|
|
TARGET=""
|
|
|
|
SOURCE_TO_CHECK="${LINK_SOURCES[$SERVER]}"
|
|
|
|
SOURCE=$SOURCE_TO_CHECK
|
|
|
|
TARGET="${LINK_TARGETS[$SERVER]}"
|
|
|
|
if [ -z "$SOURCE" ]; then
|
|
|
|
case $SERVER in
|
|
|
|
jdtls)
|
|
|
|
echo "No need to link jdtls. Use 'jdtls-start.sh' instead!"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
hls)
|
|
|
|
SOURCE_TO_CHECK="$HOME/lsp/haskell/hls/haskell-language-server-wrapper"
|
|
|
|
SOURCE="$HOME/lsp/haskell/hls/*"
|
|
|
|
TARGET="$HOME/.local/bin"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown server: $SERVER"
|
|
|
|
echo "Run 'lsp status' for a list of installed servers"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
IS_LINKED=$(is_linked $SERVER)
|
|
|
|
if [ $IS_LINKED -eq 1 ]; then
|
|
|
|
echo "Server $SERVER is already linked. Nothing to do."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
if [ -z "$SOURCE_TO_CHECK" ]; then
|
|
|
|
SOURCE_TO_CHECK="$SOURCE"
|
|
|
|
fi
|
|
|
|
if [ ! -f "$SOURCE_TO_CHECK" ]; then
|
|
|
|
echo "File not found!"
|
|
|
|
echo "Make sure $SERVER is installed. Check status with 'lsp status'."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -f "$TARGET" ]; then
|
|
|
|
echo "File already exists at $TARGET"
|
|
|
|
echo "Aborting..."
|
|
|
|
echo ""
|
|
|
|
echo "File info:"
|
|
|
|
ls -lahF "$TARGET"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
ln -s "$SOURCE" "$TARGET"
|
|
|
|
echov "Successfully linked $SERVER from $SOURCE to $TARGET"
|
2021-10-19 16:22:44 +00:00
|
|
|
}
|
|
|
|
|
2021-10-19 15:21:57 +00:00
|
|
|
install () {
|
2021-11-19 16:13:59 +00:00
|
|
|
SERVER=$1
|
|
|
|
VERSION=$2
|
|
|
|
case $SERVER in
|
|
|
|
jdtls)
|
|
|
|
if [ -z "$VERSION" ]; then
|
|
|
|
VERSION="1.4.0"
|
|
|
|
fi
|
|
|
|
FILE_NAME=$(curl https://download.eclipse.org/jdtls/milestones/$VERSION/latest.txt)
|
|
|
|
wget -O - https://download.eclipse.org/jdtls/milestones/$VERSION/$FILE_NAME > /tmp/jdtls.tar.gz
|
|
|
|
mkdir -p $HOME/lsp/java/jdtls
|
|
|
|
tar -xf /tmp/jdtls.tar.gz -C $HOME/lsp/java/jdtls
|
|
|
|
;;
|
|
|
|
omnisharp)
|
|
|
|
if [ -z "$VERSION" ]; then
|
|
|
|
VERSION="v1.37.16"
|
|
|
|
fi
|
|
|
|
case $UNAME in
|
|
|
|
Linux)
|
|
|
|
FILE_NAME="omnisharp-linux-x64.tar.gz"
|
|
|
|
;;
|
|
|
|
Darwin)
|
|
|
|
FILE_NAME="omnisharp-osx.tar.gz"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
wget -O - https://github.com/OmniSharp/omnisharp-roslyn/releases/download/$VERSION/$FILE_NAME > /tmp/omnisharp.tar.gz
|
|
|
|
mkdir -p $HOME/lsp/dotnet/omnisharp
|
|
|
|
tar -xf /tmp/omnisharp.tar.gz -C $HOME/lsp/dotnet/omnisharp
|
|
|
|
;;
|
|
|
|
hls)
|
|
|
|
if [ -z "$VERSION" ]; then
|
|
|
|
VERSION="1.4.0"
|
|
|
|
fi
|
|
|
|
case $UNAME in
|
|
|
|
Linux)
|
|
|
|
FILE_NAME="haskell-language-server-Linux-${VERSION}.tar.gz"
|
|
|
|
;;
|
|
|
|
Darwin)
|
|
|
|
FILE_NAME="haskell-language-server-macOS-${VERSION}.tar.gz"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
wget -O - https://github.com/haskell/haskell-language-server/releases/download/$VERSION/$FILE_NAME > /tmp/hls.tar.gz
|
|
|
|
mkdir -p $HOME/lsp/haskell/hls
|
|
|
|
tar -xf /tmp/hls.tar.gz -C $HOME/lsp/haskell/hls
|
|
|
|
chmod +x $HOME/lsp/haskell/hls/*
|
|
|
|
;;
|
|
|
|
solang)
|
|
|
|
if [ -z "$VERSION" ]; then
|
|
|
|
VERSION="v0.1.8"
|
|
|
|
fi
|
|
|
|
case $UNAME in
|
|
|
|
Linux)
|
|
|
|
FILE_NAME="solang-linux"
|
|
|
|
;;
|
|
|
|
Windows)
|
|
|
|
FILE_NAME="solang.exe"
|
|
|
|
;;
|
|
|
|
Darwin)
|
|
|
|
FILE_NAME="solang-mac-intel"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
mkdir -p $HOME/lsp/solidity/solang
|
|
|
|
wget -O - https://github.com/hyperledger-labs/solang/releases/download/$VERSION/$FILE_NAME > $HOME/lsp/solidity/solang/solang
|
|
|
|
chmod +x $HOME/lsp/solidity/solang/solang
|
|
|
|
;;
|
|
|
|
lemminx)
|
|
|
|
if [ -z "$VERSION" ]; then
|
|
|
|
VERSION="0.18.0-400"
|
|
|
|
fi
|
|
|
|
case $UNAME in
|
|
|
|
Linux)
|
|
|
|
FILE_NAME="lemminx-linux.zip"
|
|
|
|
;;
|
|
|
|
Windows)
|
|
|
|
FILE_NAME="lemminx-win32.zip"
|
|
|
|
;;
|
|
|
|
Darwin)
|
|
|
|
FILE_NAME="lemminx-osx-x86_64.zip"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
mkdir -p $HOME/lsp/xml/lemminx
|
2021-10-19 15:21:57 +00:00
|
|
|
|
2021-11-19 16:13:59 +00:00
|
|
|
wget -O - https://download.jboss.org/jbosstools/vscode/stable/lemminx-binary/$VERSION/$FILE_NAME > /tmp/lemminx-download.zip
|
|
|
|
unzip -p /tmp/lemminx-download.zip > $HOME/lsp/xml/lemminx/lemminx
|
|
|
|
chmod +x $HOME/lsp/xml/lemminx/lemminx
|
|
|
|
;;
|
|
|
|
kotlin-language-server)
|
|
|
|
if [ -z "$VERSION" ]; then
|
|
|
|
VERSION="1.1.2"
|
|
|
|
fi
|
|
|
|
FILE_NAME="server.zip"
|
|
|
|
wget -O - https://github.com/fwcd/kotlin-language-server/releases/download/$VERSION/$FILE_NAME > /tmp/kotlin-language-server.zip
|
|
|
|
mkdir -p $HOME/lsp/kotlin
|
|
|
|
unzip /tmp/kotlin-language-server.zip -d /tmp/kotlin-language-server
|
|
|
|
mv /tmp/kotlin-language-server/server $HOME/lsp/kotlin/kotlin-language-server
|
|
|
|
;;
|
|
|
|
rust-analyzer)
|
|
|
|
if [ -z "$VERSION" ]; then
|
|
|
|
VERSION="2021-11-15"
|
|
|
|
fi
|
|
|
|
BASE_FILE_NAME="rust-analyzer-x86_64"
|
|
|
|
case $UNAME in
|
|
|
|
Linux)
|
|
|
|
FILE_NAME="${BASE_FILE_NAME}-unknown-linux-gnu.gz"
|
|
|
|
;;
|
|
|
|
Windows)
|
|
|
|
FILE_NAME="${BASE_FILE_NAME}-pc-windows-msvc.gz"
|
|
|
|
;;
|
|
|
|
Darwin)
|
|
|
|
FILE_NAME="${BASE_FILE_NAME}-apple-darwin.gz"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
wget -O - https://github.com/rust-analyzer/rust-analyzer/releases/download/$VERSION/$FILE_NAME > /tmp/rust-analyzer.gz
|
|
|
|
mkdir -p $HOME/lsp/rust/rust-analyzer
|
|
|
|
gunzip /tmp/rust-analyzer.gz -c > $HOME/lsp/rust/rust-analyzer/rust-analyzer
|
|
|
|
chmod +x $HOME/lsp/rust/rust-analyzer/rust-analyzer
|
|
|
|
;;
|
2022-04-30 21:08:58 +00:00
|
|
|
zls)
|
|
|
|
if [ -z "$VERSION" ]; then
|
|
|
|
VERSION="0.9.0"
|
|
|
|
fi
|
|
|
|
case $UNAME in
|
|
|
|
Linux)
|
|
|
|
FILE_NAME="x86_64-linux.tar.xz"
|
|
|
|
;;
|
|
|
|
Windows)
|
|
|
|
FILE_NAME="x86_64-windows.tar.xz"
|
|
|
|
;;
|
|
|
|
Darwin)
|
|
|
|
FILE_NAME="x86_64-macos.tar.xz"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
wget -O - https://github.com/zigtools/zls/releases/download/$VERSION/$FILE_NAME > /tmp/zls.xz
|
|
|
|
mkdir -p $HOME/lsp/zig/zls
|
|
|
|
tar -xJf /tmp/zls.xz --strip-components=1 -C $HOME/lsp/zig/zls
|
|
|
|
chmod +x $HOME/lsp/zig/zls/zls
|
|
|
|
;;
|
2021-11-19 16:13:59 +00:00
|
|
|
*)
|
|
|
|
echo "Unknown server: $SERVER"
|
|
|
|
echo "Run 'lsp status --all' for a list of available servers"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
echo "$SERVER $VERSION" >> "$MY_CONFIG_CACHE_DIR/lspstatus"
|
|
|
|
echo "" >> "$MY_CONFIG_CACHE_DIR/lspstatus"
|
|
|
|
tac "$MY_CONFIG_CACHE_DIR/lspstatus" | awk 'BEGIN { FS = " " } ; {print $2 " " $1}' | uniq -f 1 > /tmp/newlspstatus
|
|
|
|
cat /tmp/newlspstatus | awk 'BEGIN { FS = " " } ; {print $2 " " $1}' > "$MY_CONFIG_CACHE_DIR/lspstatus"
|
|
|
|
rm /tmp/newlspstatus
|
|
|
|
echov "Successfully installed $SERVER, version $VERSION"
|
|
|
|
if [ $LINK -eq 1 ]; then
|
|
|
|
link_server $SERVER
|
|
|
|
fi
|
2021-10-19 15:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uninstall () {
|
2021-11-19 16:13:59 +00:00
|
|
|
SERVER=$1
|
|
|
|
case $SERVER in
|
|
|
|
jdtls)
|
|
|
|
rm -rf $HOME/lsp/java/jdtls
|
|
|
|
;;
|
|
|
|
omnisharp)
|
|
|
|
rm -rf $HOME/lsp/dotnet/omnisharp
|
|
|
|
;;
|
|
|
|
hls)
|
|
|
|
rm -rf $HOME/lsp/haskell/hls
|
|
|
|
;;
|
|
|
|
solang)
|
|
|
|
rm -rf $HOME/lsp/solidity/solang
|
|
|
|
;;
|
|
|
|
lemminx)
|
|
|
|
rm -rf $HOME/lsp/xml/lemminx
|
|
|
|
;;
|
|
|
|
kotlin-language-server)
|
|
|
|
rm -rf $HOME/lsp/kotlin/kotlin-language-server
|
|
|
|
;;
|
|
|
|
rust-analyzer)
|
|
|
|
rm -rf $HOME/lsp/rust/rust-analyzer
|
|
|
|
;;
|
2022-04-30 21:08:58 +00:00
|
|
|
zls)
|
|
|
|
rm -rf $HOME/lsp/zig/zls
|
|
|
|
;;
|
2021-11-19 16:13:59 +00:00
|
|
|
*)
|
|
|
|
echo "Unknown server: $SERVER"
|
|
|
|
echo "Run 'lsp status' for a list of installed servers"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
sed -i -e "/$SERVER/d" "$MY_CONFIG_CACHE_DIR/lspstatus"
|
|
|
|
echov "Successfully removed $SERVER"
|
2021-10-19 15:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status () {
|
2021-11-19 16:13:59 +00:00
|
|
|
SERVER=$1
|
|
|
|
HAD_UNKNOWN=0
|
|
|
|
TREAT_SERVER_AS_LANGUAGE=0
|
|
|
|
BOLDSTART="\033[1m"
|
|
|
|
ERRORSTART="\033[91m"
|
|
|
|
INFOSTART="\033[34m"
|
|
|
|
MODEND="\033[0m"
|
|
|
|
LANGUAGES=$(ls $HOME/lsp)
|
|
|
|
echov "Found languages: $LANGUAGES"
|
|
|
|
if [ $ALL -eq 1 ]; then
|
|
|
|
echov "Adding all supported languages"
|
|
|
|
LANGUAGES+=" ${!SUPPORTED_SERVERS[@]}"
|
|
|
|
LANGUAGES=$(echo $LANGUAGES | tr ' ' '\n' | sort | uniq -)
|
|
|
|
fi
|
|
|
|
echov "Checking languages: $LANGUAGES"
|
|
|
|
if [ ! -z "$SERVER" ]; then
|
|
|
|
EXPECTED_SERVERS="${SUPPORTED_SERVERS[$SERVER]}"
|
|
|
|
if [ ! -z "$EXPECTED_SERVERS" ]; then
|
|
|
|
echov "Passed server name: $SERVER was recognized as a language"
|
|
|
|
TREAT_SERVER_AS_LANGUAGE=1
|
|
|
|
LANGUAGES="$SERVER"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echov ""
|
|
|
|
for lang in $LANGUAGES; do
|
|
|
|
if [ -d "$HOME/lsp/$lang" ]; then
|
|
|
|
INSTALLED_SERVERS=$(ls $HOME/lsp/$lang)
|
|
|
|
else
|
|
|
|
INSTALLED_SERVERS=""
|
|
|
|
fi
|
|
|
|
SERVERS="$INSTALLED_SERVERS"
|
|
|
|
EXPECTED_SERVERS="${SUPPORTED_SERVERS[$lang]}"
|
|
|
|
if [ $ALL -eq 1 ]; then
|
|
|
|
SERVERS+=" $EXPECTED_SERVERS"
|
|
|
|
SERVERS=$(echo $SERVERS | tr ' ' '\n' | sort | uniq -)
|
|
|
|
fi
|
|
|
|
if [ -z "$EXPECTED_SERVERS" ]; then
|
|
|
|
HAD_UNKNOWN=1
|
|
|
|
if [ $KNOWN_ONLY -eq 1 ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
echo -e "Language $BOLDSTART${lang}$MODEND $ERRORSTART(UNKNOWN)$MODEND:"
|
|
|
|
else
|
|
|
|
echo -e "Language $BOLDSTART${lang}$MODEND:"
|
|
|
|
fi
|
|
|
|
if [ ! -z "$SERVER" ]; then
|
|
|
|
if [ $TREAT_SERVER_AS_LANGUAGE -eq 0 ]; then
|
|
|
|
if [ ! -z "$INSTALLED_SERVERS" ]; then
|
|
|
|
SERVERS="$SERVER"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
for server in $SERVERS; do
|
|
|
|
VERSION="UNKNOWN"
|
|
|
|
for available_server in "${EXPECTED_SERVERS[@]}"; do
|
|
|
|
if [ "$server" == "$available_server" ]; then
|
|
|
|
VERSION=$(get_version $server)
|
|
|
|
break
|
2021-10-19 15:21:57 +00:00
|
|
|
fi
|
2021-11-19 16:13:59 +00:00
|
|
|
done
|
|
|
|
if [ "$VERSION" == "UNKNOWN" ]; then
|
|
|
|
if [ $KNOWN_ONLY -eq 1 ]; then
|
|
|
|
continue
|
2021-10-19 15:21:57 +00:00
|
|
|
fi
|
2021-11-19 16:13:59 +00:00
|
|
|
echo -e " Server $BOLDSTART${server}$MODEND $ERRORSTART(UNKNOWN)$MODEND:"
|
|
|
|
HAD_UNKNOWN=1
|
|
|
|
else
|
|
|
|
echo -e " Server $BOLDSTART${server}$MODEND:"
|
|
|
|
fi
|
|
|
|
INSTALLED=0
|
|
|
|
for installed_server in ${INSTALLED_SERVERS}; do
|
|
|
|
if [ "$server" == "$installed_server" ]; then
|
|
|
|
INSTALLED=1
|
|
|
|
if [ -z "$VERSION" ]; then
|
|
|
|
VERSION="UNKNOWN"
|
|
|
|
fi
|
|
|
|
echo -e " Installed: ${INFOSTART}true${MODEND}"
|
|
|
|
echo " Version: $VERSION"
|
|
|
|
echo " Location: $HOME/lsp/$lang/$server"
|
|
|
|
LINKED=$(is_linked $server)
|
|
|
|
if [[ ":$PATH:" == *":$HOME/lsp/$lang/$server:"* ]]; then
|
|
|
|
echo -e " On path: ${INFOSTART}true${MODEND}"
|
|
|
|
elif [ $LINKED -eq 1 ]; then
|
|
|
|
echo -e " On path: ${INFOSTART}${BOLDSTART}linked${MODEND}${MODEND}"
|
|
|
|
echo " Linked to: ${LINK_TARGETS[$server]}"
|
|
|
|
else
|
|
|
|
echo " On path: false"
|
|
|
|
fi
|
|
|
|
break
|
2021-10-19 15:21:57 +00:00
|
|
|
fi
|
2021-11-19 16:13:59 +00:00
|
|
|
done
|
|
|
|
if [ $INSTALLED -eq 0 ]; then
|
|
|
|
echo -e " Installed: ${ERRORSTART}false${MODEND}"
|
|
|
|
fi
|
|
|
|
echo ""
|
|
|
|
done
|
|
|
|
echo ""
|
|
|
|
done
|
|
|
|
if [ $HAD_UNKNOWN -eq 1 ]; then
|
|
|
|
if [ $KNOWN_ONLY -eq 0 ]; then
|
|
|
|
echov "Found unknown servers."
|
|
|
|
echov "Make sure $HOME/lsp contains only LSP servers and similar tools."
|
|
|
|
fi
|
|
|
|
fi
|
2021-10-19 15:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get_version () {
|
2021-11-19 16:13:59 +00:00
|
|
|
SERVER=$1
|
|
|
|
cat "$MY_CONFIG_CACHE_DIR/lspstatus" | grep "$SERVER" | cut -f 2 -d ' '
|
2021-10-19 15:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case $COMMAND in
|
2021-11-19 16:13:59 +00:00
|
|
|
install)
|
|
|
|
install $SERVER $VERSION
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
status $SERVER
|
|
|
|
;;
|
|
|
|
uninstall)
|
|
|
|
uninstall $SERVER
|
|
|
|
;;
|
|
|
|
link)
|
|
|
|
link_server $SERVER
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage $COMMAND; exit 1 ;;
|
2021-10-19 15:21:57 +00:00
|
|
|
esac
|