Skip to content

Commit

Permalink
feat: support VSCodium (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveLauC authored Jan 9, 2025
1 parent aebc035 commit 9a6fe8e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ pub enum Step {
Vim,
VoltaPackages,
Vscode,
Vscodium,
Waydroid,
Winget,
Wsl,
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ fn run() -> Result<()> {
runner.execute(Step::Vscode, "Visual Studio Code extensions", || {
generic::run_vscode_extensions_update(&ctx)
})?;
runner.execute(Step::Vscodium, "VSCodium extensions", || {
generic::run_vscodium_extensions_update(&ctx)
})?;
runner.execute(Step::Conda, "conda", || generic::run_conda_update(&ctx))?;
runner.execute(Step::Mamba, "mamba", || generic::run_mamba_update(&ctx))?;
runner.execute(Step::Pixi, "pixi", || generic::run_pixi_update(&ctx))?;
Expand Down
42 changes: 42 additions & 0 deletions src/steps/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,48 @@ pub fn run_vcpkg_update(ctx: &ExecutionContext) -> Result<()> {
command.args(["upgrade", "--no-dry-run"]).status_checked()
}

/// Make VSCodium a separate step because:
///
/// 1. Users could use both VSCode and VSCoium
/// 2. Just in case, VSCodium could have incompatible changes with VSCode
pub fn run_vscodium_extensions_update(ctx: &ExecutionContext) -> Result<()> {
// Calling vscodoe in WSL may install a server instead of updating extensions (https://github.com/topgrade-rs/topgrade/issues/594#issuecomment-1782157367)
if is_wsl()? {
return Err(SkipStep(String::from("Should not run in WSL")).into());
}

let vscodium = require("codium")?;

// VSCode has update command only since 1.86 version ("january 2024" update), disable the update for prior versions
// Use command `code --version` which returns 3 lines: version, git commit, instruction set. We parse only the first one
//
// This should apply to VSCodium as well.
let version: Result<Version> = match Command::new(&vscodium)
.arg("--version")
.output_checked_utf8()?
.stdout
.lines()
.next()
{
Some(item) => Version::parse(item).map_err(|err| err.into()),
_ => return Err(SkipStep(String::from("Cannot find vscodium version")).into()),
};

if !matches!(version, Ok(version) if version >= Version::new(1, 86, 0)) {
return Err(SkipStep(String::from(
"Too old vscodium version to have update extensions command",
))
.into());
}

print_separator("VSCodium extensions");

ctx.run_type()
.execute(vscodium)
.arg("--update-extensions")
.status_checked()
}

pub fn run_vscode_extensions_update(ctx: &ExecutionContext) -> Result<()> {
// Calling vscode in WSL may install a server instead of updating extensions (https://github.com/topgrade-rs/topgrade/issues/594#issuecomment-1782157367)
if is_wsl()? {
Expand Down

0 comments on commit 9a6fe8e

Please sign in to comment.