mirror of
https://github.com/huhu/rust-search-extension
synced 2024-11-14 23:57:07 +00:00
Search crate from crate index
This commit is contained in:
parent
e945c3cd29
commit
d352ce4372
3 changed files with 12 additions and 1 deletions
|
@ -108,4 +108,6 @@ CrateSearch.prototype.search = function(keyword, limit = 5) {
|
|||
.map(item => {
|
||||
return this.crateIndex[item.id];
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
const crateSearcher = new CrateSearch(crateIndex);
|
|
@ -25,6 +25,8 @@
|
|||
"settings.js",
|
||||
"search.js",
|
||||
"search-index.js",
|
||||
"crates-index.js",
|
||||
"crate-search.js",
|
||||
"omnibox.js",
|
||||
"main.js"
|
||||
]
|
||||
|
|
|
@ -71,6 +71,13 @@ Omnibox.prototype.appendErrorIndexResult = function(query, length) {
|
|||
};
|
||||
|
||||
Omnibox.prototype.appendCratesResult = function(query) {
|
||||
let crates = crateSearcher.search(query);
|
||||
for (let crate of crates) {
|
||||
this.suggestResults.push({
|
||||
content: `https://crates.io/crates/${crate.id}`,
|
||||
description: `[crate] ${this.tagged("match", crate.id)} v${crate.version} - ${this.tagged("dim", this.escape(crate.description))}`,
|
||||
});
|
||||
}
|
||||
this.suggestResults.push({
|
||||
content: "https://crates.io/search?q=" + encodeURIComponent(query),
|
||||
description: "Search Rust crates for " + this.tagged("match", query) + " on https://crates.io"
|
||||
|
|
Loading…
Reference in a new issue