Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vscode): updated extensions for a given profile #1022

Merged

Conversation

necromeo
Copy link
Contributor

What does this PR do

This PR adds a configuration extension to allow selecting a Vscode profile for which the extensions should be updated for. If no profile is stated in the config file, the default profile is used.

Standards checklist

  • The PR title is descriptive
  • I have read CONTRIBUTING.md
  • Optional: I have tested the code myself
  • If this PR introduces new user-facing messages they are translated

For new steps

  • Optional: Topgrade skips this step where needed
  • Optional: The --dry-run option works with this step
  • Optional: The --yes option works with this step if it is supported by
    the underlying command

If you developed a feature or a bug fix for someone else and you do not have the
means to test it, please tag this person here.

Copy link
Member

@SteveLauC SteveLauC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late reply, been overwhelmed by notifications so I missed this one🤦‍♂️

Left some suggested changes, which would make the code more rusty

src/config.rs Outdated
Comment on lines 1681 to 1687
pub fn vscode_profile(&self) -> &str {
self.config_file
.vscode
.as_ref()
.and_then(|vscode| vscode.profile.as_deref())
.unwrap_or("")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn vscode_profile(&self) -> &str {
self.config_file
.vscode
.as_ref()
.and_then(|vscode| vscode.profile.as_deref())
.unwrap_or("")
}
pub fn vscode_profile(&self) -> Option<&str> {
let vscode_cfg = self.config_file.vscode?;
let profile = vscode_cfg.profile?;
// Treat empty profile as None
if profile.is_empty() {
None
} else {
profile.as_str()
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to make some changes to apply this suggestion. The borrow checker had some complaints.
f0d055c

Comment on lines 474 to 486
if !ctx.config().vscode_profile().is_empty() {
ctx.run_type()
.execute(vscode)
.arg("--profile")
.arg(ctx.config().vscode_profile())
.arg("--update-extensions")
.status_checked()
} else {
ctx.run_type()
.execute(vscode)
.arg("--update-extensions")
.status_checked()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !ctx.config().vscode_profile().is_empty() {
ctx.run_type()
.execute(vscode)
.arg("--profile")
.arg(ctx.config().vscode_profile())
.arg("--update-extensions")
.status_checked()
} else {
ctx.run_type()
.execute(vscode)
.arg("--update-extensions")
.status_checked()
}
if let Some(profile) = ctx.config().vscode_profile() {
ctx.run_type()
.execute(vscode)
.arg("--profile")
.arg(profile)
.arg("--update-extensions")
.status_checked()
} else {
ctx.run_type()
.execute(vscode)
.arg("--update-extensions")
.status_checked()
}

@@ -9,6 +10,7 @@ use std::{fs, io::Write};
use color_eyre::eyre::eyre;
use color_eyre::eyre::Context;
use color_eyre::eyre::Result;
use color_eyre::owo_colors::OwoColorize;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Looks like this was imported accidentally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed e31ea1c

@@ -1,6 +1,7 @@
#![allow(unused_imports)]

use std::ffi::OsStr;
use std::ops::Deref;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this was imported accidentally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, must have been imported automatically by my editor.
Removed e31ea1c

Comment on lines 295 to 297
# Specify the profile the extensions should be updated for.
# If no profile is selected, the default one will be used.
# (default: "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Specify the profile the extensions should be updated for.
# If no profile is selected, the default one will be used.
# (default: "")
# If this is set and is a non-empty string, it specify the profile the extensions
# should be updated for.
#
# (default: this won't be set by default)

@necromeo
Copy link
Contributor Author

@SteveLauC thanks for the suggestions! They're appreciated, especially since I'm not a Rust dev.

@necromeo necromeo requested a review from SteveLauC February 10, 2025 15:27
Copy link
Member

@SteveLauC SteveLauC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@SteveLauC SteveLauC merged commit 66a12cc into topgrade-rs:main Feb 11, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants