Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Mix.install instead of packaging ez archives #317

Merged
merged 6 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
run: |
cd elixir-ls
mix deps.get
MIX_ENV=prod mix compile
- name: Resolve vscode-elixir-ls dependencies
run: |
npm install
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,9 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
submodules: 'true'
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Setup Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: 1.12.x
otp-version: 22.x
- name: install jq
run: |
sudo apt-get install jq
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@ out
node_modules
.vscode-test/
*.vsix

# We store the build artifacts from ElixirLS here
/elixir-ls-release
17 changes: 17 additions & 0 deletions elixir-ls-release/debugger.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@echo off & setlocal enabledelayedexpansion

SET ELS_MODE=debugger
SET ELS_RELEASE="v0.14.0"
@REM SET ELS_LOCAL="1"
IF EXIST "%APPDATA%\elixir_ls\setup.bat" (
ECHO "" | CALL "%APPDATA%\elixir_ls\setup.bat" > nul 2>&1
IF %ERRORLEVEL% NEQ 0 EXIT 1
)

SET MIX_ENV=prod
@REM pipe echo to avoid passing protocol messages to quiet install command
@REM intercept stdout and stderr
@REM elixir is a batch script and needs to be called
ECHO "" | CALL elixir "%~dp0quiet_install.exs" > nul 2>&1
IF %ERRORLEVEL% NEQ 0 EXIT 1
elixir --erl "+sbwt none +sbwtdcpu none +sbwtdio none" "%~dp0debugger.exs"
16 changes: 16 additions & 0 deletions elixir-ls-release/debugger.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
if System.get_env("ELS_LOCAL") == "1" do
Mix.install(
[
{:elixir_ls, path: "#{__DIR__}/../elixir-ls"},
],
config_path: "#{__DIR__}/../elixir-ls/config/config.exs",
lockfile: "#{__DIR__}/../elixir-ls/mix.lock"
)
else
Mix.install([
{:elixir_ls, github: "elixir-lsp/elixir-ls", tag: System.get_env("ELS_RELEASE")}
])
end


ElixirLS.Debugger.CLI.main()
21 changes: 21 additions & 0 deletions elixir-ls-release/debugger.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
# Launches the debugger. This script must be in the same directory as mix install launch script.

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
dir="$(dirname "$(readlink_f "$0")")"
else
dir=${ELS_INSTALL_PREFIX}
fi

export ELS_MODE=debugger
exec "${dir}/launch.sh"
17 changes: 17 additions & 0 deletions elixir-ls-release/language_server.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@echo off & setlocal enabledelayedexpansion

SET ELS_MODE=language_server
SET ELS_RELEASE="v0.14.0"
@REM SET ELS_LOCAL="1"
IF EXIST "%APPDATA%\elixir_ls\setup.bat" (
ECHO "" | CALL "%APPDATA%\elixir_ls\setup.bat" > nul 2>&1
IF %ERRORLEVEL% NEQ 0 EXIT 1
)

SET MIX_ENV=prod
@REM pipe echo to avoid passing protocol messages to quiet install command
@REM intercept stdout and stderr
@REM elixir is a batch script and needs to be called
ECHO "" | CALL elixir "%~dp0quiet_install.exs" > nul 2>&1
IF %ERRORLEVEL% NEQ 0 EXIT 1
elixir --erl "+sbwt none +sbwtdcpu none +sbwtdio none" "%~dp0language_server.exs"
16 changes: 16 additions & 0 deletions elixir-ls-release/language_server.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
if System.get_env("ELS_LOCAL") == "1" do
Mix.install(
[
{:elixir_ls, path: "#{__DIR__}/../elixir-ls"},
],
config_path: "#{__DIR__}/../elixir-ls/config/config.exs",
lockfile: "#{__DIR__}/../elixir-ls/mix.lock"
)
else
Mix.install([
{:elixir_ls, github: "elixir-lsp/elixir-ls", tag: System.get_env("ELS_RELEASE")}
])
end


ElixirLS.LanguageServer.CLI.main()
21 changes: 21 additions & 0 deletions elixir-ls-release/language_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
# Launches the language server. This script must be in the same directory as mix install launch script.

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
dir="$(dirname "$(readlink_f "$0")")"
else
dir=${ELS_INSTALL_PREFIX}
fi

export ELS_MODE=language_server
exec "${dir}/launch.sh"
79 changes: 79 additions & 0 deletions elixir-ls-release/launch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/sh
# 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

did_relaunch=$1

ASDF_DIR=${ASDF_DIR:-"${HOME}/.asdf"}

asdf_vm="${ASDF_DIR}/asdf.sh"
if test -f "${asdf_vm}"
then
# asdf-vm does not support the plain posix shell. Figure out
# which one we need and relaunch ourselves with that.
case "${did_relaunch}" in
"")
if which bash >/dev/null
then
exec "$(which bash)" "$0" relaunch
elif which zsh >/dev/null
then
exec "$(which zsh)" "$0" relaunch
fi
;;
*)
# We have an arg2, so we got relaunched. Therefore, we're running in a
# shell that supports asdf-vm.
. "${asdf_vm}"
;;
esac
fi

export ELS_RELEASE="v0.14.0"
# export ELS_LOCAL="1"

# 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.

els_setup="${XDG_CONFIG_HOME:-$HOME/.config}/elixir_ls/setup.sh"
if test -f "${els_setup}"
then
. "${els_setup}"
fi

# 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.

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")
else
SCRIPTPATH=${ELS_INSTALL_PREFIX}
fi

export MIX_ENV=prod
# Mix.install prints to stdout and stderr and reads from stdin
# we need to make sure it doesn't interfere with LSP/DAP
elixir "$SCRIPTPATH/quiet_install.exs" 1> /dev/null 2> /dev/null < /dev/zero || exit 1

exec elixir --erl "+sbwt none +sbwtdcpu none +sbwtdio none" "$SCRIPTPATH/$ELS_MODE.exs"
13 changes: 13 additions & 0 deletions elixir-ls-release/quiet_install.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if System.get_env("ELS_LOCAL") == "1" do
Mix.install(
[
{:elixir_ls, path: "#{__DIR__}/../elixir-ls"},
],
config_path: "#{__DIR__}/../elixir-ls/config/config.exs",
lockfile: "#{__DIR__}/../elixir-ls/mix.lock"
)
else
Mix.install([
{:elixir_ls, github: "elixir-lsp/elixir-ls", tag: System.get_env("ELS_RELEASE")}
])
end
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,9 @@
]
},
"scripts": {
"vscode:prepublish": "./prepublish.bash",
"compile": "tsc -b && cd elixir-ls && MIX_ENV=prod mix elixir_ls.release -o ../elixir-ls-release",
"watch": "cd elixir-ls && MIX_ENV=prod mix elixir_ls.release -o ../elixir-ls-release && cd .. && tsc -b -w",
"vscode:prepublish": "npm run compile",
"compile": "tsc -b",
"watch": "tsc -b -w",
"update-vscode": "node ./node_modules/vscode/bin/install",
"test": "node ./out/test/runTest.js",
"lint": "eslint . --ext .js,.ts",
Expand Down
7 changes: 0 additions & 7 deletions prepublish.bash

This file was deleted.

3 changes: 2 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as path from "path";

import { workspace, ExtensionContext, WorkspaceFolder, Uri } from "vscode";
import {
Executable,
ExecuteCommandParams,
LanguageClient,
LanguageClientOptions,
Expand Down Expand Up @@ -453,7 +454,7 @@ function startClient(
.getConfiguration("elixirLS", clientOptions.workspaceFolder)
.get("languageServerOverridePath")!;

const serverOpts = {
const serverOpts: Executable = {
command: lsOverridePath
? path.join(lsOverridePath, command)
: context.asAbsolutePath("./elixir-ls-release/" + command),
Expand Down