Skip to content

Send LSP error when GHC cannot be found #2713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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