idt/installers/
lua_ls.rs

1use std::path::Path;
2
3use ytil_sys::Arch;
4use ytil_sys::Os;
5use ytil_sys::SysInfo;
6
7use crate::downloaders::curl::CurlDownloaderOption;
8use crate::installers::Installer;
9use crate::installers::SystemDependent;
10
11pub struct LuaLanguageServer<'a> {
12    pub dev_tools_dir: &'a Path,
13    pub sys_info: &'a SysInfo,
14}
15
16impl SystemDependent for LuaLanguageServer<'_> {
17    fn target_arch_and_os(&self) -> (&str, &str) {
18        let SysInfo { os, arch } = self.sys_info;
19        let os = match os {
20            Os::MacOs => "darwin",
21            Os::Linux => "linux",
22        };
23        let arch = match arch {
24            Arch::Arm => "arm64",
25            Arch::X86 => "x64",
26        };
27        (arch, os)
28    }
29}
30
31impl Installer for LuaLanguageServer<'_> {
32    fn bin_name(&self) -> &'static str {
33        "lua-language-server"
34    }
35
36    fn install(&self) -> color_eyre::Result<()> {
37        let (arch, os) = self.target_arch_and_os();
38
39        // No `bin` link as it requires some local stuff so, leave the garbage in `dev-tools` and configure the LSP to
40        // point to the `bin` there.
41        let repo = format!("LuaLS/{}", self.bin_name());
42        let dev_tools_repo_dir = self.dev_tools_dir.join(self.bin_name());
43        let latest_release = ytil_gh::get_latest_release(&repo)?;
44        std::fs::create_dir_all(&dev_tools_repo_dir)?;
45
46        let target_dir = crate::downloaders::curl::run(
47            &format!(
48                "https://github.com/{repo}/releases/download/{latest_release}/{}-{latest_release}-{os}-{arch}.tar.gz",
49                self.bin_name()
50            ),
51            &CurlDownloaderOption::PipeIntoTar {
52                dest_dir: &dev_tools_repo_dir,
53                dest_name: None,
54            },
55        )?;
56
57        ytil_sys::file::chmod_x(target_dir.join("bin").join(self.bin_name()))?;
58
59        Ok(())
60    }
61
62    // NOTE: skip because it's a shitshow...
63    fn check_args(&self) -> Option<&[&str]> {
64        None
65    }
66}