elixir-lsp/elixir-ls

v0.21.1 can not find hex under debian12.5

Closed this issue · 6 comments

I have debian and manjaro linux for daily use, Hex can not be found only appeared under debian, it can be found under manjaro. They have the same networking configuation, i use git proxy and hex.pm mirror for both.

Precheck

  • Do a quick search and make sure the issue has not yet been reported
    yes, i searched, but not working.

  • Do not use the issues tracker for guidance, questions or support (try Elixir Forum, Stack Overflow, Slack, etc. instead)
    yes, not working.

  • If using a client other than VS Code, please try VSCode's "ElixirLS: Elixir support and debugger" extension. Does it reproduce your failure?
    yes.

Environment

  • Elixir & Erlang versions (elixir --version):

elixir was installed by apt, not asdf

$ elixir --version
Erlang/OTP 25 [erts-13.1.5] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit:ns]

Elixir 1.14.0 (compiled with Erlang/OTP 24)
  • Elixir Language Server version:

i am not sure, accoring the logs, i think maybe is v0.21.1

Installing ElixirLS release v0.21.1
  • Operating system:
$ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

$ cat /etc/debian_version 
12.5

$ neofetch 
       _,met$$$$$gg.          mmc@deb-kvm 
    ,g$$$$$$$$$$$$$$$P.       ----------- 
  ,g$$P"     """Y$$.".        OS: Debian GNU/Linux 12 (bookworm) x86_64 
 ,$$P'              `$$$.     Host: KVM/QEMU (Standard PC (Q35 + ICH9, 2009) pc-q35-8 
',$$P       ,ggs.     `$$b:   Kernel: 6.1.0-9-amd64 
`d$$'     ,$P"'   .    $$$    Uptime: 14 mins 
 $$P      d$'     ,    $$P    Packages: 2092 (dpkg) 
 $$:      $$.   -    ,d$$'    Shell: zsh 5.9 
 $$;      Y$b._   _,d$P'      Resolution: 1280x800 
 Y$$.    `.`"Y$$$$P"'         DE: Xfce 4.18 
 `$$b      "-.__              WM: Xfwm4 
  `Y$$                        WM Theme: JacWin10 
   `Y$$.                      Theme: Windows10 [GTK2] 
     `$$b.                    Icons: Faenza [GTK2] 
       `Y$$b.                 Terminal: terminator 
          `"Y$b._             CPU: Intel i5-9500 (2) @ 3.000GHz 
              `"""            GPU: 00:01.0 Red Hat, Inc. Virtio 1.0 GPU 
                              Memory: 1171MiB / 1967MiB
  • Editor or IDE name (e.g. Emacs/VSCode):

vscode

Version: 1.89.1
Commit: dc96b837cf6bb4af9cd736aa3af08cf8279f7685
Date: 2024-05-07T05:16:23.416Z
Electron: 28.2.8
ElectronBuildId: 27744544
Chromium: 120.0.6099.291
Node.js: 18.18.2
V8: 12.0.267.19-electron.0
OS: Linux x64 6.1.0-9-amd64
  • Editor Plugin/LSP Client name and version:
JakeBecker.elixir-ls v0.21

Current behavior

can not find hex under debian12.5

due to gfw, i need to use mirror to access repo.hex.pm, and also i need to use proxy for git.

my hexpm mirror, according https://hex.pm/docs/mirrors

export HEX_UNSAFE_HTTPS=1
export HEX_MIRROR="http://hexpm.upyun.com"

my git mirror

git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080

i download hex manually

https://hexpm.upyun.com/installs/1.14.0/hex-2.0.6.ez
https://repo.hex.pm/installs/1.14.0/hex-2.0.6.ez

then

mmc at deb-kvm in ~
$ mix archive.install ./hex-2.0.6.ez
Are you sure you want to install "./hex-2.0.6.ez"? [Yn]
* creating .mix/archives/hex-2.0.6
$ mix hex.info                      
Hex:    2.0.6
Elixir: 1.14.0
OTP:    25.2.3

Built with: Elixir 1.14.2 and OTP 23.3

aaa

when i create demo project

mix new demo

open with vscode, then check the elixirls output

Running /home/mmc/.vscode/extensions/jakebecker.elixir-ls-0.21.1/elixir-ls-release/launch.sh
Preferred shell is zsh, relaunching
Looking for ASDF install
ASDF install found in /home/mmc/.asdf/asdf.sh, sourcing
Installing ElixirLS release v0.21.1
Running in /home/mmc/downloads/demo
* Getting elixir_ls (https://github.com/elixir-lsp/elixir-ls.git - v0.21.1)
==> language_server
Could not find Hex, which is needed to build dependency :stream_data
Shall I install Hex? (if running non-interactively, use "mix local.hex --force")

i had installed hex, but plugin can not find it.

Expected behavior

hex can be found by elixir-ls

same behavior for astronvim

mason

nvim demo.ex
mmc at deb-kvm in ~/.local/state/nvim
$ cat lsp.log
[START][2024-05-17 09:35:08] LSP logging initiated
[ERROR][2024-05-17 09:35:08] .../vim/lsp/rpc.lua:770	"rpc"	"elixir-ls"	"stderr"	"Running /home/mmc/.local/share/nvim/mason/packages/elixir-ls/launch.sh\nPreferred shell is zsh, relaunching\nLooking for ASDF install\nASDF install found in /home/mmc/.asdf/asdf.sh, sourcing\n"
[ERROR][2024-05-17 09:35:09] .../vim/lsp/rpc.lua:770	"rpc"	"elixir-ls"	"stderr"	"Installing ElixirLS release v0.21.1\n"
[ERROR][2024-05-17 09:35:09] .../vim/lsp/rpc.lua:770	"rpc"	"elixir-ls"	"stderr"	"Running in /home/mmc/downloads/demo\n"
[ERROR][2024-05-17 09:35:09] .../vim/lsp/rpc.lua:770	"rpc"	"elixir-ls"	"stderr"	"* Updating elixir_ls (https://github.com/elixir-lsp/elixir-ls.git - v0.21.1)\n"
[ERROR][2024-05-17 09:35:11] .../vim/lsp/rpc.lua:770	"rpc"	"elixir-ls"	"stderr"	'==> language_server\nCould not find Hex, which is needed to build dependency :stream_data\nShall I install Hex? (if running non-interactively, use "mix local.hex --force")\n'

i checked the code of elixir-ls

Mix.Hex.ensure_installed?(true)

but i don't know where is the definition, how it works, i need to know it to check my configuration.

This code calls a function in elixir standard lib

Mix.Hex.ensure_installed? seems to be like this

@spec ensure_installed?(boolean) :: boolean
  def ensure_installed?(force?) do
    cond do
      Code.ensure_loaded?(Hex) -> true
      force? or install_hex?() -> Mix.Tasks.Local.Hex.run(["--force"])
      true -> false
    end
  end

and the install.exs from vscode plugin look like this

aaa

so confused, elixir environment is just quite simple

apt install elixir
mix local.hex

I'm not sure it is caused by my configurtion, i reinstall debian, only install these

vscode
apt install elixir -y
proxychains
proxychains mix local.hex

create demo project

mix new demo

open with vscode, logs
aaaaaaaa

i have no idea about it.

it seems to be working, need a bit change of code

scripts/installer.exs

defp load_hex do
  if !Code.ensure_loaded?(Hex) do
    base_dir = System.user_home |> Path.join(".mix/archives")

    if base_dir |> File.exists? do
      sub_dirs = File.ls!(base_dir)
      if sub_dirs |> Enum.count() > 0 do
        hex_dirs = Enum.filter(sub_dirs, fn dir -> dir |> String.starts_with?("hex-") end)

        hex_dir = Enum.reduce(hex_dirs, fn dir, saved_dir ->
          start_pos = String.length("hex-")
          ver1 = dir |> String.slice(start_pos..-1) |> Version.parse!()
          ver2 = saved_dir |> String.slice(start_pos..-1) |> Version.parse!()

          case Version.compare(ver1, ver2) do
            :gt ->
              dir
            :lt ->
              saved_dir
            :eq ->
              [dir, saved_dir] |> Enum.random()
          end
        end)

        hex_beam_path = base_dir |> Path.join(hex_dir) |> Path.join(hex_dir) |> Path.join("ebin")
        Code.append_path(hex_beam_path)
      end
    end
  end
end

line 342

load_hex()
cond do xxx

making symbolic connection to system lib seems to be the easiest way, no need to change anything

sudo ln -s ~/.mix/archives/hex-2.0.6/hex-2.0.6 /usr/lib/elixir/lib/hex

I'm going to close it. The issue seems specific to OP's system and it's solved in their case