diff --git a/apps/language_server/lib/language_server/server.ex b/apps/language_server/lib/language_server/server.ex index 9e3221a4d..8236347b2 100644 --- a/apps/language_server/lib/language_server/server.ex +++ b/apps/language_server/lib/language_server/server.ex @@ -1864,7 +1864,9 @@ defmodule ElixirLS.LanguageServer.Server do mix_target = Map.get(settings, "mixTarget") project_dir = Map.get(settings, "projectDir") additional_watched_extensions = Map.get(settings, "additionalWatchedExtensions", []) - stdlib_src_dir = to_string(Map.get(settings, "stdlibSrcDir", "")) + + stdlib_src_dir = + to_string(Map.get(settings, "stdlibSrcDir", System.get_env("ELX_STDLIB_PATH", ""))) if stdlib_src_dir != "" do Application.put_env(:language_server, :elixir_src, stdlib_src_dir) diff --git a/scripts/launch.fish b/scripts/launch.fish index 58e936de1..1363997e1 100644 --- a/scripts/launch.fish +++ b/scripts/launch.fish @@ -8,6 +8,26 @@ # First order of business, see whether we can setup asdf +function readlink_f + cd (dirname $argv[1]) || exit 1 + set filename (basename $argv[1]) + if test -L $filename + readlink_f (readlink $filename) + else + echo (pwd -P)"/$filename" + end +end + +function export_stdlib_path + set -l current_dir (pwd) + + set -l which_elixir_expr $argv[1] + set -gx ELX_STDLIB_PATH (readlink_f (eval $which_elixir_expr) | string replace -r '(.*)\/bin\/elixir' '$1') + # readlink_f changes the current directory (since fish doesn't have + # subshells), so it needs to be restored. + cd $current_dir +end + echo "Looking for asdf install" >&2 # Check if we have the asdf binary for version >= 0.16.0 @@ -25,6 +45,7 @@ if test -n "$asdf" else echo "asdf executable found at $asdf. Using ASDF_DIR=$ASDF_DIR, ASDF_DATA_DIR=$ASDF_DATA_DIR." >&2 end + export_stdlib_path "asdf which elixir" else # Fallback to old method for asdf version <= 0.15.x test -n "$ASDF_DIR"; or set ASDF_DIR "$HOME/.asdf" @@ -33,6 +54,7 @@ else echo "Legacy pre v0.16.0 asdf install found at $ASDF_SH, sourcing" >&2 # Source the old asdf.sh script for versions <= 0.15.0 source "$ASDF_SH" + export_stdlib_path "asdf which elixir" else echo "asdf not found" >&2 echo "Looking for mise executable" >&2 @@ -41,6 +63,7 @@ else if test -n "$mise" echo "mise executable found at $mise, activating" >&2 source ( "$mise" env -s fish ) + export_stdlib_path "mise which elixir" else echo "mise not found" >&2 echo "Looking for rtx executable" >&2 @@ -49,6 +72,7 @@ else if test -n "$rtx" echo "rtx executable found at $rtx, activating" >&2 source ( "$rtx" env -s fish ) + export_stdlib_path "rtx which elixir" else echo "rtx not found" >&2 echo "Looking for vfox executable" >&2 @@ -59,6 +83,7 @@ else source ( "$vfox" activate fish ) else echo "vfox not found" >&2 + export_stdlib_path "which elixir" end end end @@ -84,16 +109,6 @@ end # script so we can correctly configure the Erlang library path to # include the local .ez files, and then do what we were asked to do. -function readlink_f - cd (dirname $argv[1]) || exit 1 - set filename (basename $argv[1]) - if test -L $filename - readlink_f (readlink $filename) - else - echo (pwd -P)"/$filename" - end -end - if test -z "$ELS_INSTALL_PREFIX" set -l current_dir (pwd) set scriptpath (dirname (readlink_f (status -f))) diff --git a/scripts/launch.sh b/scripts/launch.sh index 4d8bd5c1d..21afbb1e6 100755 --- a/scripts/launch.sh +++ b/scripts/launch.sh @@ -38,6 +38,24 @@ esac # First order of business, see whether we can setup asdf echo "Looking for asdf install" >&2 +readlink_f () { + cd "$(dirname "$1")" > /dev/null || exit 1 + filename="$(basename "$1")" + if [ -h "$filename" ]; then + readlink_f "$(readlink "$filename")" + else + echo "$(pwd -P)/$filename" + fi +} + +export_stdlib_path () { + which_elixir_expr=$1 + stdlib_path=$(eval "$which_elixir_expr") + stdlib_real_path=$(readlink_f "$stdlib_path") + ELX_STDLIB_PATH=$(echo "$stdlib_real_path" | sed "s/\(.*\)\/bin\/elixir/\1/") + export ELX_STDLIB_PATH +} + # Check if we have the asdf binary for version >= 0.16.0 if command -v asdf >/dev/null 2>&1; then asdf_version=$(asdf --version 2>/dev/null) @@ -58,6 +76,7 @@ if command -v asdf >/dev/null 2>&1; then else >&2 echo "asdf executable found at $(command -v asdf). Using ASDF_DIR=${ASDF_DIR}, ASDF_DATA_DIR=${ASDF_DATA_DIR}." fi + export_stdlib_path "asdf which elixir" else # Fallback to old method for version <= 0.15.x ASDF_DIR=${ASDF_DIR:-"${HOME}/.asdf"} @@ -66,6 +85,7 @@ else >&2 echo "Legacy pre v0.16.0 asdf install found at $ASDF_SH, sourcing" # Source the old asdf.sh script for versions <= 0.15.0 . "$ASDF_SH" + export_stdlib_path "asdf which elixir" else >&2 echo "asdf not found" >&2 echo "Looking for mise executable" @@ -74,6 +94,7 @@ else if command -v mise >/dev/null 2>&1; then >&2 echo "mise executable found at $(command -v mise), activating" eval "$($(command -v mise) env -s "$preferred_shell")" + export_stdlib_path "mise which elixir" else >&2 echo "mise not found" >&2 echo "Looking for rtx executable" @@ -82,6 +103,7 @@ else if command -v rtx >/dev/null 2>&1; then >&2 echo "rtx executable found at $(command -v rtx), activating" eval "$($(command -v rtx) env -s "$preferred_shell")" + export_stdlib_path "rtx which elixir" else >&2 echo "rtx not found" >&2 echo "Looking for vfox executable" @@ -92,6 +114,7 @@ else eval "$($(command -v vfox) activate "$preferred_shell")" else >&2 echo "vfox not found" + export_stdlib_path "which elixir" fi fi fi @@ -115,16 +138,6 @@ fi # script so we can correctly configure the Erlang library path to # include the local .ez files, and then do what we were asked to do. -readlink_f () { - cd "$(dirname "$1")" > /dev/null || exit 1 - filename="$(basename "$1")" - if [ -h "$filename" ]; then - readlink_f "$(readlink "$filename")" - else - echo "$(pwd -P)/$filename" - fi -} - if [ -z "${ELS_INSTALL_PREFIX}" ]; then SCRIPT=$(readlink_f "$0") SCRIPTPATH=$(dirname "$SCRIPT")