Skip to main content

idt/installers/
nvim.rs

1use std::path::Path;
2
3use rootcause::prelude::ResultExt;
4
5use crate::Installer;
6
7pub struct Nvim<'a> {
8    pub dev_tools_dir: &'a Path,
9    pub bin_dir: &'a Path,
10}
11
12impl Installer for Nvim<'_> {
13    fn bin_name(&self) -> &'static str {
14        "nvim"
15    }
16
17    fn install(&self) -> rootcause::Result<()> {
18        // Compiling from sources because I can checkout specific refs in case of broken nightly builds.
19        // Moreover...it's pretty badass 😎
20        let nvim_source_dir = self.dev_tools_dir.join(self.bin_name()).join("source");
21        let nvim_release_dir = self.dev_tools_dir.join(self.bin_name()).join("release");
22
23        ytil_cmd::silent_cmd("sh")
24            .args([
25                "-c",
26                &format!(
27                    r#"
28                        ([ ! -d "{0}" ] && \
29                            git clone https://github.com/neovim/neovim {0} || true) && \
30                        cd {0} && \
31                        git checkout master && \
32                        git pull origin master && \
33                        make distclean && \
34                        make CMAKE_BUILD_TYPE=Release CMAKE_EXTRA_FLAGS="-DCMAKE_INSTALL_PREFIX={1}" && \
35                        make install
36                    "#,
37                    nvim_source_dir.display(),
38                    nvim_release_dir.display(),
39                ),
40            ])
41            .status()
42            .context("failed to spawn build command")?
43            .exit_ok()
44            .context("build failed")
45            .attach_with(|| format!("tool={}", self.bin_name()))
46            .attach_with(|| format!("source_dir={}", nvim_source_dir.display()))?;
47
48        let target = nvim_release_dir.join("bin").join(self.bin_name());
49        ytil_sys::file::ln_sf(&target, &self.bin_dir.join(self.bin_name()))?;
50        ytil_sys::file::chmod_x(&target)?;
51
52        Ok(())
53    }
54
55    fn health_check_args(&self) -> Option<&[&str]> {
56        Some(&["-V1", "-v"])
57    }
58}