Skip to content

Commit 7eac7cf

Browse files
authored
Add shell specific launch execution (#982)
* Add shell-specific opts handling * Add Dockerfile to be able testing different shells * Add docs for docker based test environment
1 parent cca1096 commit 7eac7cf

File tree

5 files changed

+69
-17
lines changed

5 files changed

+69
-17
lines changed

DEVELOPMENT.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,36 @@ cd path/to/my_project
3333
ELS_LOCAL=1 /path/to/elixir-ls/scripts/language_server.sh
3434
```
3535

36+
#### Docker based test environment
37+
38+
You are able to run the project in a container (based on Elixir Alpine) to quickly try different platforms or shells.
39+
40+
To build and run the container (tagged `els` to make docker operations easier) run:
41+
42+
```shell
43+
docker build -t els .
44+
docker run -it els
45+
```
46+
Please keep in mind that in this will take the current project contents and copy it into the container once when the
47+
container is being built.
48+
49+
Since the container contains its own little Linux os the project content is copied into the `/app` directory to avoid
50+
interference with the surrounding system, when you enter the container using the interactive terminal (with the command
51+
above) you will start in that `/app` directory. The following examples expect you being in that project directory.
52+
53+
The following example runs the language server in the default shell of Alpine Linux, which is the Almquist shell (`ash`):
54+
55+
```shell
56+
ELS_LOCAL=1 SHELL=ash scripts/language_server.sh
57+
```
58+
Since `ash` is already the default shell for Alpine Linux we don't need to explicitly call a shell to run the script with.
59+
60+
To run the same command with the `bash` you need to actually pass the shell as well:
61+
62+
```shell
63+
ELS_LOCAL=1 SHELL=bash bash scripts/language_server.sh
64+
```
65+
3666
### Formatting
3767

3868
You may need to separately run `mix format` in the ElixirLS root and in `apps/language_server` directory.

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM index.docker.io/elixir:alpine
2+
3+
ARG ELIXIR_LS_VERSION=v0.16.0
4+
ARG MIX_ENV=prod
5+
6+
ADD . /app
7+
8+
WORKDIR /app
9+
10+
# Add build and test dependencies
11+
RUN apk add --no-cache \
12+
git \
13+
zsh \
14+
bash \
15+
fish
16+
17+
CMD sh

scripts/exec.bash

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# we need to make sure ELS_ELIXIR_OPTS gets splitted by word
2+
# parse it as bash array
3+
# shellcheck disable=SC3045
4+
# shellcheck disable=SC3011
5+
IFS=' ' read -ra elixir_opts <<< "$ELS_ELIXIR_OPTS"
6+
# shellcheck disable=SC3054
7+
# shellcheck disable=SC2068
8+
exec elixir ${elixir_opts[@]} --erl "$default_erl_opts $ELS_ERL_OPTS" "$SCRIPTPATH/launch.exs"

scripts/exec.zsh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# we need to make sure ELS_ELIXIR_OPTS gets splitted by word
2+
# parse it as zsh array
3+
# shellcheck disable=SC3030
4+
# shellcheck disable=SC2296
5+
elixir_opts=("${(z)ELS_ELIXIR_OPTS}")
6+
# shellcheck disable=SC2128
7+
# shellcheck disable=SC2086
8+
exec elixir $elixir_opts --erl "$default_erl_opts $ELS_ERL_OPTS" "$SCRIPTPATH/launch.exs"

scripts/launch.sh

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ did_relaunch=$1
1313
# Get the user's preferred shell
1414
preferred_shell=$(basename "$SHELL")
1515

16+
# Get current dirname
17+
dirname=$(dirname "$0")
18+
1619
case "${did_relaunch}" in
1720
"")
1821
if [ "$preferred_shell" = "bash" ]; then
@@ -23,7 +26,7 @@ case "${did_relaunch}" in
2326
exec "$(which zsh)" "$0" relaunch
2427
elif [ "$preferred_shell" = "fish" ]; then
2528
>&2 echo "Preferred shell is fish, launching launch.fish"
26-
exec "$(which fish)" "$(dirname "$0")/launch.fish"
29+
exec "$(which fish)" "$dirname/launch.fish"
2730
else
2831
>&2 echo "Preffered shell $preferred_shell is not supported, continuing in POSIX shell"
2932
fi
@@ -98,23 +101,9 @@ echo "" | elixir "$SCRIPTPATH/quiet_install.exs" >/dev/null || exit 1
98101
default_erl_opts="-kernel standard_io_encoding latin1 +sbwt none +sbwtdcpu none +sbwtdio none"
99102

100103
if [ "$preferred_shell" = "bash" ]; then
101-
# we need to make sure ELS_ELIXIR_OPTS gets splitted by word
102-
# parse it as bash array
103-
# shellcheck disable=SC3045
104-
# shellcheck disable=SC3011
105-
IFS=' ' read -ra elixir_opts <<< "$ELS_ELIXIR_OPTS"
106-
# shellcheck disable=SC3054
107-
# shellcheck disable=SC2068
108-
exec elixir ${elixir_opts[@]} --erl "$default_erl_opts $ELS_ERL_OPTS" "$SCRIPTPATH/launch.exs"
104+
source "$dirname/exec.bash"
109105
elif [ "$preferred_shell" = "zsh" ]; then
110-
# we need to make sure ELS_ELIXIR_OPTS gets splitted by word
111-
# parse it as zsh array
112-
# shellcheck disable=SC3030
113-
# shellcheck disable=SC2296
114-
elixir_opts=("${(z)ELS_ELIXIR_OPTS}")
115-
# shellcheck disable=SC2128
116-
# shellcheck disable=SC2086
117-
exec elixir $elixir_opts --erl "$default_erl_opts $ELS_ERL_OPTS" "$SCRIPTPATH/launch.exs"
106+
source "$dirname/exec.zsh"
118107
else
119108
if [ -z "$ELS_ELIXIR_OPTS" ]
120109
then

0 commit comments

Comments
 (0)