Add option to link lsp binaries

pull/2/head
Ensar Sarajčić 2021-10-19 18:22:44 +02:00
parent 5e63c19bc8
commit 2a66d2c673
1 changed files with 103 additions and 3 deletions

View File

@ -13,9 +13,11 @@ usage () {
install) install)
usage_install; exit 0 ;; usage_install; exit 0 ;;
uninstall) uninstall)
usage_uninstal; exit 0 ;; usage_uninstall; exit 0 ;;
status) status)
usage_status; exit 0 ;; usage_status; exit 0 ;;
link)
usage_link; exit 0 ;;
esac esac
if [ ! -z "$1" ]; then if [ ! -z "$1" ]; then
echo -e "Unknown command: $1 \n" echo -e "Unknown command: $1 \n"
@ -46,6 +48,7 @@ usage_install () {
echov " - version is hardcoded and could be outdated" echov " - version is hardcoded and could be outdated"
echo "" echo ""
echo "Options:" echo "Options:"
echo " -l --link - automatically links installed binaries to $HOME/.local/bin"
echo " -h --help - prints this help message" echo " -h --help - prints this help message"
echo " -v --verbose - enables verbose logging" echo " -v --verbose - enables verbose logging"
echov "Examples:" echov "Examples:"
@ -54,6 +57,20 @@ usage_install () {
echov " > lsp install jdtls 1.4.0" echov " > lsp install jdtls 1.4.0"
} }
usage_link () {
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"
}
usage_uninstall () { usage_uninstall () {
echo "LSP Uninstall" echo "LSP Uninstall"
echo "Uninstalls a language server. Silently fails if server is not present." echo "Uninstalls a language server. Silently fails if server is not present."
@ -77,6 +94,8 @@ usage_status () {
echov " - if it does not exist, this tool tries to look for it in every language listed" echov " - if it does not exist, this tool tries to look for it in every language listed"
echo "" echo ""
echo "Options:" 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 " -h --help - prints this help message"
echo " -v --verbose - enables verbose logging" echo " -v --verbose - enables verbose logging"
echov "" echov ""
@ -105,6 +124,8 @@ POSITIONAL=()
HELP=0 HELP=0
VERBOSE=0 VERBOSE=0
ALL=0 ALL=0
KNOWN_ONLY=0
LINK=0
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
key="$1" key="$1"
@ -121,6 +142,14 @@ while [[ $# -gt 0 ]]; do
ALL=1 ALL=1
shift # past argument shift # past argument
;; ;;
-k|--known-only)
KNOWN_ONLY=1
shift # past argument
;;
-l|--link)
LINK=1
shift # past argument
;;
*) # unknown option *) # unknown option
POSITIONAL+=("$1") # save it in an array for later POSITIONAL+=("$1") # save it in an array for later
shift # past argument shift # past argument
@ -159,6 +188,63 @@ declare -A SUPPORTED_SERVERS=(
["kotlin"]="kotlin-language-server" ["kotlin"]="kotlin-language-server"
) )
link_server () {
SERVER=$1
SOURCE=""
TARGET=""
SOURCE_TO_CHECK=""
case $SERVER in
jdtls)
echo "No need to link jdtls. Use 'jdtls-start.sh' instead!"
exit 0
;;
omnisharp)
SOURCE="$HOME/lsp/dotnet/omnisharp/run"
TARGET="$HOME/.local/bin/omnisharp"
;;
hls)
SOURCE_TO_CHECK="$HOME/lsp/haskell/hls/haskell-language-server-wrapper"
SOURCE="$HOME/lsp/haskell/hls/*"
TARGET="$HOME/.local/bin"
;;
solang)
SOURCE="$HOME/lsp/solidity/solang"
TARGET="$HOME/.local/bin/solang"
;;
lemminx)
SOURCE="$HOME/lsp/xml/lemminx"
TARGET="$HOME/.local/bin/lemminx"
;;
kotlin-language-server)
SOURCE="$HOME/lsp/kotlin/kotlin-language-server/bin/kotlin-language-server"
TARGET="$HOME/.local/bin/kotlin-language-server"
;;
*)
echo "Unknown server: $SERVER"
echo "Run 'lsp status' for a list of installed servers"
exit 1
;;
esac
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"
}
install () { install () {
SERVER=$1 SERVER=$1
VERSION=$2 VERSION=$2
@ -267,6 +353,9 @@ install () {
cat /tmp/newlspstatus | awk 'BEGIN { FS = " " } ; {print $2 " " $1}' > "$MY_CONFIG_CACHE_DIR/lspstatus" cat /tmp/newlspstatus | awk 'BEGIN { FS = " " } ; {print $2 " " $1}' > "$MY_CONFIG_CACHE_DIR/lspstatus"
rm /tmp/newlspstatus rm /tmp/newlspstatus
echov "Successfully installed $SERVER, version $VERSION" echov "Successfully installed $SERVER, version $VERSION"
if [ $LINK -eq 1 ]; then
link_server $SERVER
fi
} }
uninstall () { uninstall () {
@ -339,6 +428,9 @@ status () {
fi fi
if [ -z "$EXPECTED_SERVERS" ]; then if [ -z "$EXPECTED_SERVERS" ]; then
HAD_UNKNOWN=1 HAD_UNKNOWN=1
if [ $KNOWN_ONLY -eq 1 ]; then
continue
fi
echo -e "Language $BOLDSTART${lang}$MODEND $ERRORSTART(UNKNOWN)$MODEND:" echo -e "Language $BOLDSTART${lang}$MODEND $ERRORSTART(UNKNOWN)$MODEND:"
else else
echo -e "Language $BOLDSTART${lang}$MODEND:" echo -e "Language $BOLDSTART${lang}$MODEND:"
@ -359,6 +451,9 @@ status () {
fi fi
done done
if [ "$VERSION" == "UNKNOWN" ]; then if [ "$VERSION" == "UNKNOWN" ]; then
if [ $KNOWN_ONLY -eq 1 ]; then
continue
fi
echo -e " Server $BOLDSTART${server}$MODEND $ERRORSTART(UNKNOWN)$MODEND:" echo -e " Server $BOLDSTART${server}$MODEND $ERRORSTART(UNKNOWN)$MODEND:"
HAD_UNKNOWN=1 HAD_UNKNOWN=1
else else
@ -390,9 +485,11 @@ status () {
echo "" echo ""
done done
if [ $HAD_UNKNOWN -eq 1 ]; then if [ $HAD_UNKNOWN -eq 1 ]; then
if [ $KNOWN_ONLY -eq 0 ]; then
echov "Found unknown servers." echov "Found unknown servers."
echov "Make sure $HOME/lsp contains only LSP servers and similar tools." echov "Make sure $HOME/lsp contains only LSP servers and similar tools."
fi fi
fi
} }
get_version () { get_version () {
@ -410,6 +507,9 @@ case $COMMAND in
uninstall) uninstall)
uninstall $SERVER uninstall $SERVER
;; ;;
link)
link_server $SERVER
;;
*) *)
usage $COMMAND; exit 1 ;; usage $COMMAND; exit 1 ;;
esac esac