From a20aefd54bfe89a3df232be47058feb934658b08 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 14 Feb 2022 18:55:33 +0100 Subject: [PATCH 1/2] Send LSP error when GHC cannot be found --- bindist/wrapper.in | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/bindist/wrapper.in b/bindist/wrapper.in index e29edac128..21c593a22f 100644 --- a/bindist/wrapper.in +++ b/bindist/wrapper.in @@ -23,10 +23,13 @@ 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." + json="{\"jsonrpc\":\"2.0\", \"method\":\"window/showMessage\", \"params\": {\"type\": 1, \"message\": \"${msg}\"}}" + printf "%s\r\n" "Content-Length: $(printf "%s" "${json}" | wc -c)" + printf "%s\r\n" + printf "%s" "${json}" + unset msg json } err_ghc_pkg() { @@ -105,13 +108,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 @@ -143,8 +146,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 From 65ac0fe6c175be47d4d165ce21ef50dab580e331 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 14 Feb 2022 19:08:38 +0100 Subject: [PATCH 2/2] Get rid of `wc -c` --- bindist/wrapper.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bindist/wrapper.in b/bindist/wrapper.in index 21c593a22f..71804d40ec 100644 --- a/bindist/wrapper.in +++ b/bindist/wrapper.in @@ -25,8 +25,9 @@ instruction_msg() { 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: $(printf "%s" "${json}" | wc -c)" + printf "%s\r\n" "Content-Length: 203" printf "%s\r\n" printf "%s" "${json}" unset msg json