Skip to content

Commit

Permalink
PoC package with Mix.install
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Apr 5, 2023
1 parent e549f7d commit c5ccab5
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 21 deletions.
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
10 changes: 10 additions & 0 deletions elixir-ls-release/debugger.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@echo off & setlocal enabledelayedexpansion

SET ELS_MODE=debugger
IF EXIST "%APPDATA%\elixir_ls\setup.bat" (
CALL "%APPDATA%\elixir_ls\setup.bat" > nul
)

SET MIX_ENV=prod
elixir "%~dp0\quiet_install.exs" > nul
elixir --erl "+sbwt none +sbwtdcpu none +sbwtdio none" "%~dp0\debugger.exs"
21 changes: 21 additions & 0 deletions elixir-ls-release/debugger.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Mix.install([
# {:elixir_ls, github: "elixir-lsp/elixir-ls", ref: "7f7ba8ac7ad518945f7622369d13c16f48568b30"}
# ])

Mix.install(
[
{:elixir_ls, path: "#{__DIR__}/../elixir-ls"},
],
config_path: "#{__DIR__}/../elixir-ls/config/config.exs",
lockfile: "#{__DIR__}/../elixir-ls/mix.lock"
)

# Mix.install(
# [
# {:elixir_ls_debugger, path: "#{__DIR__}/../elixir-ls/apps/elixir_ls_debugger"},
# ],
# config_path: "#{__DIR__}/../elixir-ls/config/config.exs",
# lockfile: "#{__DIR__}/../elixir-ls/mix.lock"
# )

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"
10 changes: 10 additions & 0 deletions elixir-ls-release/language_server.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@echo off & setlocal enabledelayedexpansion

SET ELS_MODE=language_server
IF EXIST "%APPDATA%\elixir_ls\setup.bat" (
CALL "%APPDATA%\elixir_ls\setup.bat" > nul
)

SET MIX_ENV=prod
elixir "%~dp0\quiet_install.exs" > nul
elixir --erl "+sbwt none +sbwtdcpu none +sbwtdio none" "%~dp0\language_server.exs"
21 changes: 21 additions & 0 deletions elixir-ls-release/language_server.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Mix.install([
# {:elixir_ls, github: "elixir-lsp/elixir-ls", ref: "7f7ba8ac7ad518945f7622369d13c16f48568b30"}
# ])

Mix.install(
[
{:elixir_ls, path: "#{__DIR__}/../elixir-ls"},
],
config_path: "#{__DIR__}/../elixir-ls/config/config.exs",
lockfile: "#{__DIR__}/../elixir-ls/mix.lock"
)

# Mix.install(
# [
# {:language_server, path: "#{__DIR__}/../elixir-ls/apps/language_server"},
# ],
# config_path: "#{__DIR__}/../elixir-ls/config/config.exs",
# lockfile: "#{__DIR__}/../elixir-ls/mix.lock"
# )

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"
76 changes: 76 additions & 0 deletions elixir-ls-release/launch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/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

# 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"
19 changes: 19 additions & 0 deletions elixir-ls-release/quiet_install.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Mix.install([
# {:elixir_ls, github: "elixir-lsp/elixir-ls", ref: "7f7ba8ac7ad518945f7622369d13c16f48568b30"}
# ])

Mix.install(
[
{:elixir_ls, path: "#{__DIR__}/../elixir-ls"},
],
config_path: "#{__DIR__}/../elixir-ls/config/config.exs",
lockfile: "#{__DIR__}/../elixir-ls/mix.lock"
)

# Mix.install(
# [
# {:language_server, path: "#{__DIR__}/../elixir-ls/apps/language_server"},
# ],
# config_path: "#{__DIR__}/../elixir-ls/config/config.exs",
# lockfile: "#{__DIR__}/../elixir-ls/mix.lock"
# )
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

0 comments on commit c5ccab5

Please sign in to comment.