Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions e2e/cli/test_install_inactive_hint
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@ assert_contains "mise install tiny@3.1.0 2>&1" "mise use tiny"
mise use dummy@1.0.0
assert_not_contains "mise install dummy 2>&1" "not activated"

# Test: Installing TOOL@VERSION for a tool that IS in config should NOT show
# the hint (regression test for #9501 — CLI args were overriding the config
# source in the merged tool request set, falsely flagging configured tools as
# inactive).
assert_not_contains "mise install dummy@1.0.0 2>&1" "not activated"
assert_not_contains "mise install dummy@latest 2>&1" "not activated"

# Clean up
mise use --rm dummy
22 changes: 16 additions & 6 deletions src/cli/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,24 @@ impl Install {
.iter()
.map(|ta| ta.ba.short.clone())
.collect();
// Collect inactive tool names before trs borrow is consumed
// Collect set of tools that appear in any config file. We can't use
// trs.sources here because load_runtime_args overrides the config-derived
// source with ToolSource::Argument whenever the user passes TOOL@VERSION.
let configured_tools: HashSet<String> = config
.config_files
.values()
.filter_map(|cf| cf.to_tool_request_set().ok())
.flat_map(|cf_trs| {
cf_trs
.tools
.keys()
.map(|ba| ba.short.clone())
.collect::<Vec<_>>()
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The intermediate Vec allocation inside flat_map is unnecessary. You can chain the iterator directly to improve efficiency and readability.

            .flat_map(|cf_trs| cf_trs.tools.keys().map(|ba| ba.short.clone()))

.collect();
Comment thread
cursor[bot] marked this conversation as resolved.
let inactive_tools: Vec<String> = expanded_runtimes
.iter()
.filter(|ta| {
trs.sources
.get(ta.ba.as_ref())
.is_none_or(|s| s.is_argument())
})
.filter(|ta| !configured_tools.contains(&ta.ba.short))
.map(|ta| ta.ba.short.clone())
.collect();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since the tools set (containing the names of tools being installed) is already computed at line 146, you can use it directly to calculate inactive_tools. This avoids re-iterating over expanded_runtimes and automatically handles duplicate tool names in the warning message (e.g., if a user runs mise install node@20 node@22).

Suggested change
let inactive_tools: Vec<String> = expanded_runtimes
.iter()
.filter(|ta| {
trs.sources
.get(ta.ba.as_ref())
.is_none_or(|s| s.is_argument())
})
.filter(|ta| !configured_tools.contains(&ta.ba.short))
.map(|ta| ta.ba.short.clone())
.collect();
let inactive_tools: Vec<String> = tools
.iter()
.filter(|t| !configured_tools.contains(*t))
.cloned()
.collect();

let mut ts: Toolset = trs.filter_by_tool(tools).into();
Expand Down
Loading