feat: suggest similarly named features
@ -29,6 +29,7 @@ use crate::core::Summary;
|
||||
use crate::core::Workspace;
|
||||
use crate::sources::source::QueryKind;
|
||||
use crate::util::cache_lock::CacheLockMode;
|
||||
use crate::util::edit_distance;
|
||||
use crate::util::style;
|
||||
use crate::util::toml::lookup_path_base;
|
||||
use crate::util::toml_mut::dependency::Dependency;
|
||||
@ -167,7 +168,20 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<(
|
||||
if activated.is_empty() && deactivated.is_empty() {
|
||||
write!(message, "\n\nno features available for crate {}", dep.name)?;
|
||||
} else {
|
||||
if !deactivated.is_empty() {
|
||||
let mut suggested = false;
|
||||
for unknown_feature in &unknown_features {
|
||||
let suggestion = edit_distance::closest_msg(
|
||||
unknown_feature,
|
||||
deactivated.iter().chain(activated.iter()),
|
||||
|dep| *dep,
|
||||
"feature",
|
||||
);
|
||||
if !suggestion.is_empty() {
|
||||
write!(message, "{suggestion}")?;
|
||||
suggested = true;
|
||||
}
|
||||
}
|
||||
if !deactivated.is_empty() && !suggested {
|
||||
if deactivated.len() <= MAX_FEATURE_PRINTS {
|
||||
write!(
|
||||
message,
|
||||
@ -191,7 +205,7 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<(
|
||||
)?;
|
||||
}
|
||||
}
|
||||
if !activated.is_empty() {
|
||||
if !activated.is_empty() && !suggested {
|
||||
if deactivated.len() + activated.len() <= MAX_FEATURE_PRINTS {
|
||||
writeln!(
|
||||
message,
|
||||
|
@ -1,4 +1,4 @@
|
||||
<svg width="740px" height="146px" xmlns="http://www.w3.org/2000/svg">
|
||||
<svg width="740px" height="164px" xmlns="http://www.w3.org/2000/svg">
|
||||
<style>
|
||||
.fg { fill: #AAAAAA }
|
||||
.bg { background: #000000 }
|
||||
@ -27,11 +27,13 @@
|
||||
</tspan>
|
||||
<tspan x="10px" y="82px">
|
||||
</tspan>
|
||||
<tspan x="10px" y="100px"><tspan>disabled features:</tspan>
|
||||
<tspan x="10px" y="100px"><tspan>help: a feature with a similar name exists: `bar`</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="118px"><tspan> bar, foo</tspan>
|
||||
<tspan x="10px" y="118px">
|
||||
</tspan>
|
||||
<tspan x="10px" y="136px">
|
||||
<tspan x="10px" y="136px"><tspan>help: a feature with a similar name exists: `foo`</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="154px">
|
||||
</tspan>
|
||||
</text>
|
||||
|
||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.3 KiB |
@ -1,4 +1,4 @@
|
||||
<svg width="740px" height="146px" xmlns="http://www.w3.org/2000/svg">
|
||||
<svg width="740px" height="128px" xmlns="http://www.w3.org/2000/svg">
|
||||
<style>
|
||||
.fg { fill: #AAAAAA }
|
||||
.bg { background: #000000 }
|
||||
@ -27,11 +27,9 @@
|
||||
</tspan>
|
||||
<tspan x="10px" y="82px">
|
||||
</tspan>
|
||||
<tspan x="10px" y="100px"><tspan>disabled features:</tspan>
|
||||
<tspan x="10px" y="100px"><tspan>help: a feature with a similar name exists: `bar`</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="118px"><tspan> bar</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="136px">
|
||||
<tspan x="10px" y="118px">
|
||||
</tspan>
|
||||
</text>
|
||||
|
||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
@ -1,4 +1,4 @@
|
||||
<svg width="740px" height="200px" xmlns="http://www.w3.org/2000/svg">
|
||||
<svg width="740px" height="164px" xmlns="http://www.w3.org/2000/svg">
|
||||
<style>
|
||||
.fg { fill: #AAAAAA }
|
||||
.bg { background: #000000 }
|
||||
@ -27,17 +27,13 @@
|
||||
</tspan>
|
||||
<tspan x="10px" y="82px">
|
||||
</tspan>
|
||||
<tspan x="10px" y="100px"><tspan>disabled features:</tspan>
|
||||
<tspan x="10px" y="100px"><tspan>help: a feature with a similar name exists: `eyes000`</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="118px"><tspan> eyes040, eyes041, eyes042, eyes043, eyes044, eyes045, eyes046, eyes047, eyes048</tspan>
|
||||
<tspan x="10px" y="118px">
|
||||
</tspan>
|
||||
<tspan x="10px" y="136px"><tspan> eyes049</tspan>
|
||||
<tspan x="10px" y="136px"><tspan>help: a feature with a similar name exists: `eyes001`</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="154px">
|
||||
</tspan>
|
||||
<tspan x="10px" y="172px"><tspan>40 enabled features available</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="190px">
|
||||
</tspan>
|
||||
</text>
|
||||
|
||||
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.3 KiB |
@ -27,11 +27,11 @@
|
||||
</tspan>
|
||||
<tspan x="10px" y="82px">
|
||||
</tspan>
|
||||
<tspan x="10px" y="100px"><tspan>199 disabled features available</tspan>
|
||||
<tspan x="10px" y="100px"><tspan>help: a feature with a similar name exists: `eyes100`</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="118px">
|
||||
</tspan>
|
||||
<tspan x="10px" y="136px"><tspan>1 enabled features available</tspan>
|
||||
<tspan x="10px" y="136px"><tspan>help: a feature with a similar name exists: `eyes101`</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="154px">
|
||||
</tspan>
|
||||
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
@ -1,4 +1,4 @@
|
||||
<svg width="740px" height="146px" xmlns="http://www.w3.org/2000/svg">
|
||||
<svg width="740px" height="128px" xmlns="http://www.w3.org/2000/svg">
|
||||
<style>
|
||||
.fg { fill: #AAAAAA }
|
||||
.bg { background: #000000 }
|
||||
@ -27,11 +27,9 @@
|
||||
</tspan>
|
||||
<tspan x="10px" y="82px">
|
||||
</tspan>
|
||||
<tspan x="10px" y="100px"><tspan>disabled features:</tspan>
|
||||
<tspan x="10px" y="100px"><tspan>help: a feature with a similar name exists: `nose`</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="118px"><tspan> ears, eyes, mouth, nose</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="136px">
|
||||
<tspan x="10px" y="118px">
|
||||
</tspan>
|
||||
</text>
|
||||
|
||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |