2021-10-19 15:21:57 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2022-05-15 14:35:43 +00:00
|
|
|
. ~/.local/opt/script_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:"
|
2022-05-24 17:29:50 +00:00
|
|
|
echov " > lsp install zls"
|
2021-11-19 16:13:59 +00:00
|
|
|
echov ""
|
2022-05-24 17:29:50 +00:00
|
|
|
echov " > lsp install zls 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:"
|
2022-05-24 17:29:50 +00:00
|
|
|
echov " > lsp link zls"
|
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:"
|
2022-05-24 17:29:50 +00:00
|
|
|
echov " > lsp uninstall zls"
|
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-24 17:29:50 +00:00
|
|
|
echov " > lsp status zig
|
2022-05-09 13:59:26 +00:00
|
|
|
"
|
2022-05-24 17:29:50 +00:00
|
|
|
echov " Language zig:"
|
2021-11-19 16:13:59 +00:00
|
|
|
echov ""
|
2022-05-24 17:29:50 +00:00
|
|
|
echov " > lsp status zig --all
|
2022-05-09 13:59:26 +00:00
|
|
|
"
|
2022-05-24 17:29:50 +00:00
|
|
|
echov " Language zig:"
|
|
|
|
echov " Server zls:"
|
2021-10-19 15:21:57 +00:00
|
|
|
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"
|
|
|
|
|
2022-05-15 14:35:43 +00:00
|
|
|
LSP_HOME="$HOME/.local/opt/lsp"
|
2022-05-15 13:32:26 +00:00
|
|
|
|
2021-10-19 15:21:57 +00:00
|
|
|
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=(
|
2022-05-15 13:32:26 +00:00
|
|
|
["omnisharp"]="$LSP_HOME/dotnet/omnisharp/run"
|
|
|
|
["solang"]="$LSP_HOME/solidity/solang/solang"
|
|
|
|
["lemminx"]="$LSP_HOME/xml/lemminx/lemminx"
|
|
|
|
["kotlin-language-server"]="$LSP_HOME/kotlin/kotlin-language-server/bin/kotlin-language-server"
|
|
|
|
["rust-analyzer"]="$LSP_HOME/rust/rust-analyzer/rust-analyzer"
|
|
|
|
["zls"]="$LSP_HOME/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)
|
2022-05-24 17:29:50 +00:00
|
|
|
echo "No need to link jdtls."
|
2021-11-19 16:13:59 +00:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
hls)
|
2022-05-15 13:32:26 +00:00
|
|
|
SOURCE_TO_CHECK="$LSP_HOME/haskell/hls/haskell-language-server-wrapper"
|
|
|
|
SOURCE="$LSP_HOME/haskell/hls/*"
|
2021-11-19 16:13:59 +00:00
|
|
|
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)
|
2022-05-24 17:29:50 +00:00
|
|
|
echo "jdtls is no longer supported by this!"
|
|
|
|
echo "Use the following: "
|
|
|
|
echo ""
|
|
|
|
echo "curl https://raw.githubusercontent.com/eruizc-dev/jdtls-launcher/master/install.sh | bash"
|
2021-11-19 16:13:59 +00:00
|
|
|
;;
|
|
|
|
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
|
2022-05-15 13:32:26 +00:00
|
|
|
mkdir -p $LSP_HOME/dotnet/omnisharp
|
|
|
|
tar -xf /tmp/omnisharp.tar.gz -C $LSP_HOME/dotnet/omnisharp
|
2021-11-19 16:13:59 +00:00
|
|
|
;;
|
|
|
|
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
|
2022-05-15 13:32:26 +00:00
|
|
|
mkdir -p $LSP_HOME/haskell/hls
|
|
|
|
tar -xf /tmp/hls.tar.gz -C $LSP_HOME/haskell/hls
|
|
|
|
chmod +x $LSP_HOME/haskell/hls/*
|
2021-11-19 16:13:59 +00:00
|
|
|
;;
|
|
|
|
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
|
2022-05-15 13:32:26 +00:00
|
|
|
mkdir -p $LSP_HOME/solidity/solang
|
|
|
|
wget -O - https://github.com/hyperledger-labs/solang/releases/download/$VERSION/$FILE_NAME > $LSP_HOME/solidity/solang/solang
|
|
|
|
chmod +x $LSP_HOME/solidity/solang/solang
|
2021-11-19 16:13:59 +00:00
|
|
|
;;
|
|
|
|
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
|
2022-05-15 13:32:26 +00:00
|
|
|
mkdir -p $LSP_HOME/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
|
2022-05-15 13:32:26 +00:00
|
|
|
unzip -p /tmp/lemminx-download.zip > $LSP_HOME/xml/lemminx/lemminx
|
|
|
|
chmod +x $LSP_HOME/xml/lemminx/lemminx
|
2021-11-19 16:13:59 +00:00
|
|
|
;;
|
|
|
|
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
|
2022-05-15 13:32:26 +00:00
|
|
|
mkdir -p $LSP_HOME/kotlin
|
2021-11-19 16:13:59 +00:00
|
|
|
unzip /tmp/kotlin-language-server.zip -d /tmp/kotlin-language-server
|
2022-05-15 13:32:26 +00:00
|
|
|
mv /tmp/kotlin-language-server/server $LSP_HOME/kotlin/kotlin-language-server
|
2021-11-19 16:13:59 +00:00
|
|
|
;;
|
|
|
|
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
|
2022-05-15 13:32:26 +00:00
|
|
|
mkdir -p $LSP_HOME/rust/rust-analyzer
|
|
|
|
gunzip /tmp/rust-analyzer.gz -c > $LSP_HOME/rust/rust-analyzer/rust-analyzer
|
|
|
|
chmod +x $LSP_HOME/rust/rust-analyzer/rust-analyzer
|
2021-11-19 16:13:59 +00:00
|
|
|
;;
|
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
|
2022-05-15 13:32:26 +00:00
|
|
|
mkdir -p $LSP_HOME/zig/zls
|
|
|
|
tar -xJf /tmp/zls.xz --strip-components=1 -C $LSP_HOME/zig/zls
|
|
|
|
chmod +x $LSP_HOME/zig/zls/zls
|
2022-04-30 21:08:58 +00:00
|
|
|
;;
|
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)
|
2022-05-15 13:32:26 +00:00
|
|
|
rm -rf $LSP_HOME/java/jdtls
|
2021-11-19 16:13:59 +00:00
|
|
|
;;
|
|
|
|
omnisharp)
|
2022-05-15 13:32:26 +00:00
|
|
|
rm -rf $LSP_HOME/dotnet/omnisharp
|
2021-11-19 16:13:59 +00:00
|
|
|
;;
|
|
|
|
hls)
|
2022-05-15 13:32:26 +00:00
|
|
|
rm -rf $LSP_HOME/haskell/hls
|
2021-11-19 16:13:59 +00:00
|
|
|
;;
|
|
|
|
solang)
|
2022-05-15 13:32:26 +00:00
|
|
|
rm -rf $LSP_HOME/solidity/solang
|
2021-11-19 16:13:59 +00:00
|
|
|
;;
|
|
|
|
lemminx)
|
2022-05-15 13:32:26 +00:00
|
|
|
rm -rf $LSP_HOME/xml/lemminx
|
2021-11-19 16:13:59 +00:00
|
|
|
;;
|
|
|
|
kotlin-language-server)
|
2022-05-15 13:32:26 +00:00
|
|
|
rm -rf $LSP_HOME/kotlin/kotlin-language-server
|
2021-11-19 16:13:59 +00:00
|
|
|
;;
|
|
|
|
rust-analyzer)
|
2022-05-15 13:32:26 +00:00
|
|
|
rm -rf $LSP_HOME/rust/rust-analyzer
|
2021-11-19 16:13:59 +00:00
|
|
|
;;
|
2022-04-30 21:08:58 +00:00
|
|
|
zls)
|
2022-05-15 13:32:26 +00:00
|
|
|
rm -rf $LSP_HOME/zig/zls
|
2022-04-30 21:08:58 +00:00
|
|
|
;;
|
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"
|
2022-05-15 13:32:26 +00:00
|
|
|
LANGUAGES=$(ls $LSP_HOME)
|
2021-11-19 16:13:59 +00:00
|
|
|
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
|
2022-05-15 13:32:26 +00:00
|
|
|
if [ -d "$LSP_HOME/$lang" ]; then
|
|
|
|
INSTALLED_SERVERS=$(ls $LSP_HOME/$lang)
|
2021-11-19 16:13:59 +00:00
|
|
|
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"
|
2022-05-15 13:32:26 +00:00
|
|
|
echo " Location: $LSP_HOME/$lang/$server"
|
2021-11-19 16:13:59 +00:00
|
|
|
LINKED=$(is_linked $server)
|
2022-05-15 13:32:26 +00:00
|
|
|
if [[ ":$PATH:" == *":$LSP_HOME/$lang/$server:"* ]]; then
|
2021-11-19 16:13:59 +00:00
|
|
|
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."
|
2022-05-15 13:32:26 +00:00
|
|
|
echov "Make sure $HOME/.local/opt contains only LSP servers and similar tools."
|
2021-11-19 16:13:59 +00:00
|
|
|
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
|