Closed ziyouchutuwenwu closed 2 months ago
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
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
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
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 was installed by apt, not asdf
i am not sure, accoring the logs, i think maybe is v0.21.1
$ cat /etc/debian_version 12.5
$ neofetch _,met$$$$$gg. mmc@deb-kvm ,g$$$$$$$$$$$$$$$P. ----------- ,g$$P" """Y$$.". OS: Debian GNU/Linux 12 (bookworm) x8664 ,$$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: JacWin10Y$$. 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 / 1967MiBCurrent 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
my git mirror
i download hex manually
then
when i create demo project
open with vscode, then check the elixirls output
i had installed hex, but plugin can not find it.
Expected behavior
hex can be found by elixir-ls
same behavior for astronvim