#!/usr/bin/env bash
set -e

echo "Installing/updating LSPS."
echo

declare -A LSPS=(
	["astro"]="sudo npm i -g @astrojs/language-server"
	["bash"]="sudo npm i -g bash-language-server"
	["css,html,json"]="sudo npm i -g vscode-langservers-extracted"
	["markdown"]="yay -S marksman-bin"
	["rust"]="rustup component add rust-analyzer"
	["tailwindcss"]="sudo npm i -g @tailwindcss/language-server"
	["toml"]="cargo install taplo-cli --locked --features lsp"
	["typescript"]="sudo npm install -g typescript typescript-language-server"
	["yaml"]="sudo npm i -g yaml-language-server@next"
)

for lsp in "${!LSPS[@]}"; do
	echo -n "install/update ${lsp}? (y/n): "
	read -r ans
	if [[ "$ans" =~ ^[Yy]$ ]]; then
		echo "-> updating ${lsp}..."
		eval "${LSPS[$lsp]}"
		echo "-> ${lsp} done"
	else
		echo "-> skipping ${lsp}"
	fi
	echo
done

echo "done"
