Skip to content

Commit

Permalink
Send LSP error when GHC cannot be found (#2713)
Browse files Browse the repository at this point in the history
* Send LSP error when GHC cannot be found

* Get rid of `wc -c`
  • Loading branch information
hasufell committed Feb 18, 2022
1 parent 96ea854 commit f1e146b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions bindist/wrapper.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ instruction_msg() {
(>&2 printf "\\033[0;35m%s\\033[0m\\n" "$1")
}

err_fix() {
instruction_msg ""
instruction_msg "Consider installing ghc-${GHC_VERSION} via ghcup"
instruction_msg "or build HLS from source."
err_exit() {
msg="Couldn't find a working/matching GHC installation. Consider installing ghc-${GHC_VERSION} via ghcup or build HLS from source."
# adjust Content-Length when changing json
json="{\"jsonrpc\":\"2.0\", \"method\":\"window/showMessage\", \"params\": {\"type\": 1, \"message\": \"${msg}\"}}"
printf "%s\r\n" "Content-Length: 203"
printf "%s\r\n"
printf "%s" "${json}"
unset msg json
}

err_ghc_pkg() {
Expand Down Expand Up @@ -105,13 +109,13 @@ infer_ghc_pkg() {
# try GHC_LIBDIR from the environment (e.g. user set it, or haskell-language-server-wrapper)
if [ -n "${GHC_LIBDIR}" ] &&
[ -n "${GHC_BIN}" ] &&
{ debug_msg "Trying method: GHC_LIBDIR and GHC_BIN from env" ; HLS_WRAPPER_VERBOSE=1 ; check_ghc "${GHC_LIBDIR}" "${GHC_BIN}" "$(infer_ghc_pkg "${GHC_BIN}")" || { err_fix ; exit 1 ; } ; }
{ debug_msg "Trying method: GHC_LIBDIR and GHC_BIN from env" ; HLS_WRAPPER_VERBOSE=1 ; check_ghc "${GHC_LIBDIR}" "${GHC_BIN}" "$(infer_ghc_pkg "${GHC_BIN}")" || { err_exit ; exit 1 ; } ; }
then
:
# try GHC_BIN from the environment (e.g. user set it)
elif [ -n "${GHC_BIN}" ] &&
GHC_LIBDIR="$("${GHC_BIN}" --print-libdir)" &&
{ debug_msg "Trying method: GHC_BIN from env" ; HLS_WRAPPER_VERBOSE=1 ; check_ghc "${GHC_LIBDIR}" "${GHC_BIN}" "$(infer_ghc_pkg "${GHC_BIN}")" || { err_fix ; exit 2 ; } ; }
{ debug_msg "Trying method: GHC_BIN from env" ; HLS_WRAPPER_VERBOSE=1 ; check_ghc "${GHC_LIBDIR}" "${GHC_BIN}" "$(infer_ghc_pkg "${GHC_BIN}")" || { err_exit ; exit 2 ; } ; }
then
:
# try ghcup
Expand Down Expand Up @@ -143,8 +147,7 @@ then
else
HLS_WRAPPER_VERBOSE=1
err_msg "All methods exhausted!"
err_msg "Couldn't find a working/matching GHC installation"
err_fix
err_exit
err_msg "exiting..."
exit 42
fi
Expand Down

0 comments on commit f1e146b

Please sign in to comment.