# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit edo

DESCRIPTION="Frontend-independent IDE server for Elixir, implements LSP and DAP"
HOMEPAGE="https://github.com/elixir-lsp/elixir-ls/"

if [[ "${PV}" == *9999* ]] ; then
	inherit git-r3

	EGIT_REPO_URI="https://github.com/elixir-lsp/${PN}"
else
	SRC_URI="https://github.com/elixir-lsp/${PN}/archive/refs/tags/v${PV}.tar.gz
		-> ${P}.gh.tar.gz"

	KEYWORDS="~amd64"
fi

LICENSE="Apache-2.0"
SLOT="0"

RDEPEND="
	dev-lang/elixir
"
BDEPEND="
	${RDEPEND}
"

src_compile() {
	edo sed "${FILESDIR}/${PN}.in" -e "s|@EPREFIX@|${EPREFIX}|g" \
		> "${T}/${PN}"
}

src_install() {
	local app_home="/usr/lib/${PN}"

	dodir "${app_home}"
	edo cp -r . "${ED}/${app_home}"

	exeinto "${app_home}/server"
	doexe ./scripts/*

	insinto "${app_home}/server"
	doins VERSION

	dobin "${T}/${PN}"

	pushd "${ED}/${app_home}" || die
	dodoc ./*.md
	edo rm -f -r ./*.md .github
	popd || die
}