Skip to content

Commit

Permalink
Bugfix/#967 fish shell support (#968)
Browse files Browse the repository at this point in the history
* Add support for fish shell

* Simplify ELS_ELIXIR_OPTS

* Refactor ELS_ELIXIR_OPTS and ELS_ERL_OPTS argument builder

* Escape strings in test calls

* Remove unnecessary quotes in set els_dir

* Fix asdf detection

* Replace . with source
  • Loading branch information
Defman21 authored Aug 21, 2023
1 parent 2d5d531 commit 9607796
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
89 changes: 89 additions & 0 deletions scripts/launch.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env fish
# Actual launcher. This does the hard work of figuring out the best way
# to launch the language server or the debugger.

# Running this script is a one-time action per project launch, so we opt for
# code simplicity instead of performance. Hence some potentially redundant
# moves here.

# First order of business, see whether we can setup asdf-vm

set asdf_dir $ASDF_DIR

test -z "$asdf_dir"; and set asdf_dir "$HOME/.asdf"

set asdf_vm "$asdf_dir/asdf.fish"

echo "Looking for ASDF install" >&2

if test -f "$asdf_vm"
echo "ASDF install found in $asdf_vm, sourcing" >&2
source "$asdf_vm"
else
echo "ASDF not found" >&2
echo "Looking for rtx executable" >&2

set rtx (which rtx)
if test -n "$rtx"
echo "rtx executable found in $rtx, activating" >&2
"$rtx" activate fish | source
else
echo "rtx not found" >&2
end
end

# In case that people want to tweak the path, which Elixir to use, or
# whatever prior to launching the language server or the debugger, we
# give them the chance here. ELS_MODE will be set for
# the really complex stuff. Use an XDG compliant path.

set els_dir $XDG_CONFIG_HOME
test -z "$els_dir"; and set els_dir "$HOME/.config"

set els_setup "$els_dir/elixir_ls/setup.fish"

if test -f "$els_setup"
echo "Running setup script $els_setup" >&2
source "$els_setup"
end

# Setup done. Make sure that we have the proper actual path to this
# 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 scriptpath (dirname (readlink_f (status -f)))
else
set scriptpath $ELS_INSTALL_PREFIX
end

set -x MIX_ENV prod
# Mix.install prints to stdout and reads from stdin
# we need to make sure it doesn't interfere with LSP/DAP
echo "" | elixir "$scriptpath/quiet_install.exs" >/dev/null || exit 1

set erl_opts -kernel standard_io_encoding latin1 +sbwt none +sbwtdcpu none +sbwtdio none

if test -n "$ELS_ELIXIR_OPTS"
set elixir_opts (string join ' ' -- $ELS_ELIXIR_OPTS)
else
set elixir_opts
end

if test -n "$ELS_ERL_OPTS"
set erl_opts -a $ELS_ERL_OPTS
end

set erl_opts (string join ' ' -- $erl_opts)

eval elixir $elixir_opts --erl \"$erl_opts \" "$scriptpath/launch.exs"
3 changes: 3 additions & 0 deletions scripts/launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ case "${did_relaunch}" in
elif [ "$preferred_shell" = "zsh" ]; then
>&2 echo "Preffered shell is zsh, relaunching"
exec "$(which zsh)" "$0" relaunch
elif [ "$preferred_shell" = "fish" ]; then
>&2 echo "Preferred shell is fish, launching launch.fish"
exec "$(which fish)" "$(dirname "$0")/launch.fish"
else
>&2 echo "Preffered shell $preferred_shell is not supported, continuing in POSIX shell"
fi
Expand Down

0 comments on commit 9607796

Please sign in to comment.