Skip to content

Commit f1e146b

Browse files
authored
Send LSP error when GHC cannot be found (#2713)
* Send LSP error when GHC cannot be found * Get rid of `wc -c`
1 parent 96ea854 commit f1e146b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

bindist/wrapper.in

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ 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+
# adjust Content-Length when changing json
29+
json="{\"jsonrpc\":\"2.0\", \"method\":\"window/showMessage\", \"params\": {\"type\": 1, \"message\": \"${msg}\"}}"
30+
printf "%s\r\n" "Content-Length: 203"
31+
printf "%s\r\n"
32+
printf "%s" "${json}"
33+
unset msg json
3034
}
3135

3236
err_ghc_pkg() {
@@ -105,13 +109,13 @@ infer_ghc_pkg() {
105109
# try GHC_LIBDIR from the environment (e.g. user set it, or haskell-language-server-wrapper)
106110
if [ -n "${GHC_LIBDIR}" ] &&
107111
[ -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 ; } ; }
112+
{ 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 ; } ; }
109113
then
110114
:
111115
# try GHC_BIN from the environment (e.g. user set it)
112116
elif [ -n "${GHC_BIN}" ] &&
113117
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 ; } ; }
118+
{ 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 ; } ; }
115119
then
116120
:
117121
# try ghcup
@@ -143,8 +147,7 @@ then
143147
else
144148
HLS_WRAPPER_VERBOSE=1
145149
err_msg "All methods exhausted!"
146-
err_msg "Couldn't find a working/matching GHC installation"
147-
err_fix
150+
err_exit
148151
err_msg "exiting..."
149152
exit 42
150153
fi

0 commit comments

Comments
 (0)