Skip to content

Commit a20aefd

Browse files
committed
Send LSP error when GHC cannot be found
1 parent 96ea854 commit a20aefd

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

bindist/wrapper.in

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ instruction_msg() {
2323
(>&2 printf "\\033[0;35m%s\\033[0m\\n" "$1")
2424
}
2525

26-
err_fix() {
27-
instruction_msg ""
28-
instruction_msg "Consider installing ghc-${GHC_VERSION} via ghcup"
29-
instruction_msg "or build HLS from source."
26+
err_exit() {
27+
msg="Couldn't find a working/matching GHC installation. Consider installing ghc-${GHC_VERSION} via ghcup or build HLS from source."
28+
json="{\"jsonrpc\":\"2.0\", \"method\":\"window/showMessage\", \"params\": {\"type\": 1, \"message\": \"${msg}\"}}"
29+
printf "%s\r\n" "Content-Length: $(printf "%s" "${json}" | wc -c)"
30+
printf "%s\r\n"
31+
printf "%s" "${json}"
32+
unset msg json
3033
}
3134

3235
err_ghc_pkg() {
@@ -105,13 +108,13 @@ infer_ghc_pkg() {
105108
# try GHC_LIBDIR from the environment (e.g. user set it, or haskell-language-server-wrapper)
106109
if [ -n "${GHC_LIBDIR}" ] &&
107110
[ -n "${GHC_BIN}" ] &&
108-
{ 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 ; } ; }
111+
{ 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 ; } ; }
109112
then
110113
:
111114
# try GHC_BIN from the environment (e.g. user set it)
112115
elif [ -n "${GHC_BIN}" ] &&
113116
GHC_LIBDIR="$("${GHC_BIN}" --print-libdir)" &&
114-
{ 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 ; } ; }
117+
{ 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 ; } ; }
115118
then
116119
:
117120
# try ghcup
@@ -143,8 +146,7 @@ then
143146
else
144147
HLS_WRAPPER_VERBOSE=1
145148
err_msg "All methods exhausted!"
146-
err_msg "Couldn't find a working/matching GHC installation"
147-
err_fix
149+
err_exit
148150
err_msg "exiting..."
149151
exit 42
150152
fi

0 commit comments

Comments
 (0)