From 79718bcd370671d425cc42ca930abbb06c7f81ea Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Fri, 18 Aug 2023 17:33:06 +0200 Subject: [PATCH] split ELS_ELIXIR_OPTS Fixes https://github.com/elixir-lsp/elixir-ls/issues/966 --- apps/elixir_ls_utils/priv/launch.sh | 36 +++++++++++++++++++++++++---- scripts/launch.sh | 36 +++++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/apps/elixir_ls_utils/priv/launch.sh b/apps/elixir_ls_utils/priv/launch.sh index 0708dcd72..0026a80e1 100755 --- a/apps/elixir_ls_utils/priv/launch.sh +++ b/apps/elixir_ls_utils/priv/launch.sh @@ -10,10 +10,11 @@ did_relaunch=$1 +# Get the user's preferred shell +preferred_shell=$(basename "$SHELL") + case "${did_relaunch}" in "") - # Get the user's preferred shell - preferred_shell=$(basename "$SHELL") if [ "$preferred_shell" = "bash" ]; then >&2 echo "Preffered shell is bash, relaunching" exec "$(which bash)" "$0" relaunch @@ -46,7 +47,6 @@ else if which rtx >/dev/null then >&2 echo "rtx executable found in $(which rtx), activating" - preferred_shell=$(basename "$SHELL") eval "$($(which rtx) activate "$preferred_shell")" else >&2 echo "rtx not found" @@ -89,5 +89,31 @@ fi export ERL_LIBS="$SCRIPTPATH:$ERL_LIBS" -# shellcheck disable=SC2086 -exec elixir $ELS_ELIXIR_OPTS --erl "-kernel standard_io_encoding latin1 +sbwt none +sbwtdcpu none +sbwtdio none $ELS_ERL_OPTS" -e "$ELS_SCRIPT" +default_erl_opts="-kernel standard_io_encoding latin1 +sbwt none +sbwtdcpu none +sbwtdio none" + +if [ "$preferred_shell" = "bash" ]; then + # we need to make sure ELS_ELIXIR_OPTS gets splitted by word + # parse it as bash array + # shellcheck disable=SC3045 + # shellcheck disable=SC3011 + IFS=' ' read -ra elixir_opts <<< "$ELS_ELIXIR_OPTS" + # shellcheck disable=SC3054 + # shellcheck disable=SC2068 + exec elixir ${elixir_opts[@]} --erl "$default_erl_opts $ELS_ERL_OPTS" -e "$ELS_SCRIPT" +elif [ "$preferred_shell" = "zsh" ]; then + # we need to make sure ELS_ELIXIR_OPTS gets splitted by word + # parse it as zsh array + # shellcheck disable=SC3030 + # shellcheck disable=SC2296 + elixir_opts=("${(z)ELS_ELIXIR_OPTS}") + # shellcheck disable=SC2128 + # shellcheck disable=SC2086 + exec elixir $elixir_opts --erl "$default_erl_opts $ELS_ERL_OPTS" -e "$ELS_SCRIPT" +else + if [ -z "$ELS_ELIXIR_OPTS" ] + then + # in posix shell does not support arrays + >&2 echo "ELS_ELIXIR_OPTS is not supported in current shell" + fi + exec elixir --erl "$default_erl_opts $ELS_ERL_OPTS" -e "$ELS_SCRIPT" +fi diff --git a/scripts/launch.sh b/scripts/launch.sh index 8c2a92a76..5e47aec2e 100755 --- a/scripts/launch.sh +++ b/scripts/launch.sh @@ -10,10 +10,11 @@ did_relaunch=$1 +# Get the user's preferred shell +preferred_shell=$(basename "$SHELL") + case "${did_relaunch}" in "") - # Get the user's preferred shell - preferred_shell=$(basename "$SHELL") if [ "$preferred_shell" = "bash" ]; then >&2 echo "Preffered shell is bash, relaunching" exec "$(which bash)" "$0" relaunch @@ -46,7 +47,6 @@ else if which rtx >/dev/null then >&2 echo "rtx executable found in $(which rtx), activating" - preferred_shell=$(basename "$SHELL") eval "$($(which rtx) activate "$preferred_shell")" else >&2 echo "rtx not found" @@ -92,5 +92,31 @@ export MIX_ENV=prod # we need to make sure it doesn't interfere with LSP/DAP echo "" | elixir "$SCRIPTPATH/quiet_install.exs" >/dev/null || exit 1 -# shellcheck disable=SC2086 -exec elixir $ELS_ELIXIR_OPTS --erl "-kernel standard_io_encoding latin1 +sbwt none +sbwtdcpu none +sbwtdio none $ELS_ERL_OPTS" "$SCRIPTPATH/launch.exs" +default_erl_opts="-kernel standard_io_encoding latin1 +sbwt none +sbwtdcpu none +sbwtdio none" + +if [ "$preferred_shell" = "bash" ]; then + # we need to make sure ELS_ELIXIR_OPTS gets splitted by word + # parse it as bash array + # shellcheck disable=SC3045 + # shellcheck disable=SC3011 + IFS=' ' read -ra elixir_opts <<< "$ELS_ELIXIR_OPTS" + # shellcheck disable=SC3054 + # shellcheck disable=SC2068 + exec elixir ${elixir_opts[@]} --erl "$default_erl_opts $ELS_ERL_OPTS" "$SCRIPTPATH/launch.exs" +elif [ "$preferred_shell" = "zsh" ]; then + # we need to make sure ELS_ELIXIR_OPTS gets splitted by word + # parse it as zsh array + # shellcheck disable=SC3030 + # shellcheck disable=SC2296 + elixir_opts=("${(z)ELS_ELIXIR_OPTS}") + # shellcheck disable=SC2128 + # shellcheck disable=SC2086 + exec elixir $elixir_opts --erl "$default_erl_opts $ELS_ERL_OPTS" "$SCRIPTPATH/launch.exs" +else + if [ -z "$ELS_ELIXIR_OPTS" ] + then + # in posix shell does not support arrays + >&2 echo "ELS_ELIXIR_OPTS is not supported in current shell" + fi + exec elixir --erl "$default_erl_opts $ELS_ERL_OPTS" "$SCRIPTPATH/launch.exs" +fi