Add link support for lsp script

pull/2/head
Ensar Sarajčić 2021-10-19 18:41:44 +02:00
parent 2a66d2c673
commit 053eab872f
1 changed files with 79 additions and 33 deletions

View File

@ -27,6 +27,7 @@ usage () {
echo -e "\nUsage: lsp COMMAND [options] [arguments] \n" echo -e "\nUsage: lsp COMMAND [options] [arguments] \n"
echo "Commands:" echo "Commands:"
echo " install - installs a new language server (or a new version of already installed one)" 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 " status - prints status of servers installed (if server name is passed, prints status of that server)"
echo " uninstall - uninstalls a language server" echo " uninstall - uninstalls a language server"
echo "" echo ""
@ -187,44 +188,85 @@ declare -A SUPPORTED_SERVERS=(
["xml"]="lemminx" ["xml"]="lemminx"
["kotlin"]="kotlin-language-server" ["kotlin"]="kotlin-language-server"
) )
declare -A LINK_SOURCES=(
["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"
)
declare -A LINK_TARGETS=(
["omnisharp"]="$HOME/.local/bin/omnisharp"
["solang"]="$HOME/.local/bin/solang"
["lemminx"]="$HOME/.local/bin/lemminx"
["kotlin-language-server"]="$HOME/.local/bin/kotlin-language-server"
)
is_linked () {
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)
echo 1
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
}
link_server () { link_server () {
SERVER=$1 SERVER=$1
SOURCE="" SOURCE=""
TARGET="" TARGET=""
SOURCE_TO_CHECK="" SOURCE_TO_CHECK="${LINK_SOURCES[$SERVER]}"
case $SERVER in SOURCE=$SOURCE_TO_CHECK
jdtls) TARGET="${LINK_TARGETS[$SERVER]}"
echo "No need to link jdtls. Use 'jdtls-start.sh' instead!" if [ -z "$SOURCE" ]; then
exit 0 case $SERVER in
;; jdtls)
omnisharp) echo "No need to link jdtls. Use 'jdtls-start.sh' instead!"
SOURCE="$HOME/lsp/dotnet/omnisharp/run" exit 0
TARGET="$HOME/.local/bin/omnisharp" ;;
;; hls)
hls) SOURCE_TO_CHECK="$HOME/lsp/haskell/hls/haskell-language-server-wrapper"
SOURCE_TO_CHECK="$HOME/lsp/haskell/hls/haskell-language-server-wrapper" SOURCE="$HOME/lsp/haskell/hls/*"
SOURCE="$HOME/lsp/haskell/hls/*" TARGET="$HOME/.local/bin"
TARGET="$HOME/.local/bin" ;;
;; *)
solang) echo "Unknown server: $SERVER"
SOURCE="$HOME/lsp/solidity/solang" echo "Run 'lsp status' for a list of installed servers"
TARGET="$HOME/.local/bin/solang" exit 1
;; ;;
lemminx) esac
SOURCE="$HOME/lsp/xml/lemminx" fi
TARGET="$HOME/.local/bin/lemminx" IS_LINKED=$(is_linked $SERVER)
;; if [ $IS_LINKED -eq 1 ]; then
kotlin-language-server) echo "Server $SERVER is already linked. Nothing to do."
SOURCE="$HOME/lsp/kotlin/kotlin-language-server/bin/kotlin-language-server" exit 0
TARGET="$HOME/.local/bin/kotlin-language-server" fi
;;
*)
echo "Unknown server: $SERVER"
echo "Run 'lsp status' for a list of installed servers"
exit 1
;;
esac
if [ -z "$SOURCE_TO_CHECK" ]; then if [ -z "$SOURCE_TO_CHECK" ]; then
SOURCE_TO_CHECK="$SOURCE" SOURCE_TO_CHECK="$SOURCE"
fi fi
@ -469,8 +511,12 @@ status () {
echo -e " Installed: ${INFOSTART}true${MODEND}" echo -e " Installed: ${INFOSTART}true${MODEND}"
echo " Version: $VERSION" echo " Version: $VERSION"
echo " Location: $HOME/lsp/$lang/$server" echo " Location: $HOME/lsp/$lang/$server"
LINKED=$(is_linked $server)
if [[ ":$PATH:" == *":$HOME/lsp/$lang/$server:"* ]]; then if [[ ":$PATH:" == *":$HOME/lsp/$lang/$server:"* ]]; then
echo -e " On path: ${INFOSTART}true${MODEND}" 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 else
echo " On path: false" echo " On path: false"
fi fi