From 31aae2198cb601515dbb5cf9ee381024cd151a66 Mon Sep 17 00:00:00 2001 From: shura Date: Wed, 26 Oct 2022 23:27:59 +0200 Subject: [PATCH] Fix neovim upgrade (#77) --- src/steps/upgrade.vim | 13 +++++++------ src/steps/vim.rs | 39 +++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/steps/upgrade.vim b/src/steps/upgrade.vim index 812e9757..28e3df9f 100644 --- a/src/steps/upgrade.vim +++ b/src/steps/upgrade.vim @@ -18,11 +18,6 @@ if exists(":PlugUpgrade") endif endif -if exists(":PackerUpdate") - echo "Packer" - PackerSync -endif - if exists("*dein#update()") echo "dein#update()" call dein#update() @@ -43,4 +38,10 @@ if exists(":CocUpdateSync") CocUpdateSync endif -quitall +if exists(':PackerSync') + echo "Packer" + autocmd User PackerComplete quitall + PackerSync +else + quitall +endif diff --git a/src/steps/vim.rs b/src/steps/vim.rs index d10f069d..fb7f4990 100644 --- a/src/steps/vim.rs +++ b/src/steps/vim.rs @@ -1,7 +1,7 @@ use crate::error::{SkipStep, TopgradeError}; use anyhow::Result; -use crate::executor::{CommandExt, ExecutorOutput, RunType}; +use crate::executor::{CommandExt, Executor, ExecutorOutput, RunType}; use crate::terminal::print_separator; use crate::{ execution_context::ExecutionContext, @@ -9,7 +9,7 @@ use crate::{ }; use directories::BaseDirs; use log::debug; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::{ io::{self, Write}, process::Command, @@ -40,19 +40,14 @@ fn nvimrc(base_dirs: &BaseDirs) -> Result { .or_else(|_| base_dir.join("nvim/init.lua").require()) } -fn upgrade(vim: &Path, vimrc: &Path, ctx: &ExecutionContext) -> Result<()> { +fn upgrade_script() -> Result { let mut tempfile = tempfile::NamedTempFile::new()?; tempfile.write_all(UPGRADE_VIM.replace('\r', "").as_bytes())?; debug!("Wrote vim script to {:?}", tempfile.path()); + Ok(tempfile) +} - let mut command = ctx.run_type().execute(vim); - - command - .args(["-u"]) - .arg(vimrc) - .args(["-U", "NONE", "-V1", "-nNesS"]) - .arg(tempfile.path()); - +fn upgrade(command: &mut Executor, ctx: &ExecutionContext) -> Result<()> { if ctx.config().force_vim_plug_update() { command.env("TOPGRADE_FORCE_PLUGUPDATE", "true"); } @@ -114,13 +109,21 @@ pub fn upgrade_vim(base_dirs: &BaseDirs, ctx: &ExecutionContext) -> Result<()> { let output = Command::new(&vim).arg("--version").check_output()?; if !output.starts_with("VIM") { - return Err(SkipStep(String::from("vim binary might by actually nvim")).into()); + return Err(SkipStep(String::from("vim binary might be actually nvim")).into()); } let vimrc = vimrc(base_dirs)?; print_separator("Vim"); - upgrade(&vim, &vimrc, ctx) + upgrade( + ctx.run_type() + .execute(&vim) + .args(&["-u"]) + .arg(vimrc) + .args(&["-U", "NONE", "-V1", "-nNesS"]) + .arg(upgrade_script()?.path()), + ctx, + ) } pub fn upgrade_neovim(base_dirs: &BaseDirs, ctx: &ExecutionContext) -> Result<()> { @@ -128,7 +131,15 @@ pub fn upgrade_neovim(base_dirs: &BaseDirs, ctx: &ExecutionContext) -> Result<() let nvimrc = nvimrc(base_dirs)?; print_separator("Neovim"); - upgrade(&nvim, &nvimrc, ctx) + upgrade( + ctx.run_type() + .execute(&nvim) + .args(&["-u"]) + .arg(nvimrc) + .args(&["--headless", "-V1", "-nS"]) + .arg(upgrade_script()?.path()), + ctx, + ) } pub fn run_voom(_base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {