Improve rustc and target command search experiences

This commit is contained in:
Folyd 2022-10-30 20:38:36 +08:00
parent 19ef4f71ad
commit 8f75dbef84
2 changed files with 22 additions and 7 deletions

View file

@ -3,10 +3,11 @@ class RustcCommand extends Command {
super("rustc", "Search rustc codegen options and lints.");
this.docs = [];
Object.entries(index).forEach(([kind, data]) => {
data.items.forEach(item => {
data.items.forEach(name => {
this.docs.push({
content: `${data.url}#${item}`,
description: `${kind}: ${c.match(item)}`,
url: `${data.url}#${name}`,
kind,
name,
});
});
});
@ -14,6 +15,12 @@ class RustcCommand extends Command {
async onExecute(arg) {
return this.docs
.filter(({ description }) => !arg || description.toLowerCase().indexOf(arg) > -1);
.filter(({ kind, name }) => !arg || `${kind}: ${name}`.toLowerCase().indexOf(arg) > -1)
.map(doc => {
return {
content: doc.url,
description: `${doc.kind}: ${c.match(doc.name)}`,
};
});
}
}

View file

@ -5,8 +5,10 @@ class TargetCommand extends Command {
Object.entries(index).forEach(([tier, data]) => {
data.items.forEach(([name, description]) => {
this.targets.push({
content: data.url,
description: `${c.capitalize(tier)}: ${c.match(name)} - ${c.dim(description)}`,
url: data.url,
tier,
name,
description,
});
})
});
@ -14,6 +16,12 @@ class TargetCommand extends Command {
async onExecute(arg) {
return this.targets
.filter(({ description }) => !arg || description.toLowerCase().indexOf(arg) > -1);
.filter(({ tier, name, description }) => !arg || `${tier}: ${name} - ${description}`.toLowerCase().indexOf(arg) > -1)
.map(target => {
return {
content: target.url,
description: `${c.capitalize(target.tier)}: ${c.match(target.name)} - ${c.dim(target.description)}`,
};
});
}
}