mirror of
https://github.com/huhu/rust-search-extension
synced 2024-11-14 23:57:07 +00:00
Improve rustc and target command search experiences
This commit is contained in:
parent
19ef4f71ad
commit
8f75dbef84
2 changed files with 22 additions and 7 deletions
|
@ -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)}`,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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)}`,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue