mirror of
https://github.com/huhu/rust-search-extension
synced 2024-11-15 08:07:08 +00:00
Merge pull request #43 from shwin0901/master
This commit is contained in:
commit
ac39b19654
8 changed files with 139 additions and 7 deletions
38
extension/command/book.js
Normal file
38
extension/command/book.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
class BookCommand extends Command {
|
||||
constructor() {
|
||||
super("book", "Show all Rust official books.");
|
||||
}
|
||||
onExecute(arg) {
|
||||
const books = [
|
||||
["The Rust Programming Language", "https://doc.rust-lang.org/stable/book/"],
|
||||
["Rust Async Book", "https://rust-lang.github.io/async-book/"],
|
||||
["Rust Edition Guide Book", "https://doc.rust-lang.org/stable/edition-guide/"],
|
||||
["The Cargo Book", "https://doc.rust-lang.org/cargo/index.html"],
|
||||
["Rust and WebAssembly Book", "https://rustwasm.github.io/docs/book/"],
|
||||
["The Embedded Rust Book", "https://rust-embedded.github.io/book/"],
|
||||
["The Rust Cookbook", "https://rust-lang-nursery.github.io/rust-cookbook/"],
|
||||
["Command line apps in Rust", "https://rust-cli.github.io/book/index.html"],
|
||||
["Rust by Example", "https://doc.rust-lang.org/stable/rust-by-example/"],
|
||||
["Rust RFC", "https://rust-lang.github.io/rfcs/"],
|
||||
["The Rust Doc Book", "https://doc.rust-lang.org/rustdoc/index.html"],
|
||||
["The rustc Book", "https://doc.rust-lang.org/rustc/index.html"],
|
||||
["Guide to Rustc Development", "https://rustc-dev-guide.rust-lang.org/"],
|
||||
["The Rust Reference", "https://doc.rust-lang.org/reference/index.html"],
|
||||
["The Rustonomicon", "https://doc.rust-lang.org/nomicon/index.html"],
|
||||
["The Unstable Book", "https://doc.rust-lang.org/unstable-book/index.html"],
|
||||
["Rust bindgen User Guide", "https://rust-lang.github.io/rust-bindgen/"],
|
||||
["The wasm-bindgen Guide", "https://rustwasm.github.io/docs/wasm-bindgen/"],
|
||||
["Rust API Guidelines", "https://rust-lang.github.io/api-guidelines/"],
|
||||
["Rust Fuzz Book", "https://rust-fuzz.github.io/book/"],
|
||||
["Rust Forge Book", "https://forge.rust-lang.org/"],
|
||||
];
|
||||
return books
|
||||
.filter(item => !arg || item[0].toLowerCase().indexOf(arg) > -1)
|
||||
.map(([name, url]) => {
|
||||
return {
|
||||
content: url,
|
||||
description: `${c.match(name)} - ${c.dim(url)}`,
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
21
extension/command/help.js
Normal file
21
extension/command/help.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
class HelpCommand extends Command {
|
||||
constructor() {
|
||||
super("help", "Show the help messages.")
|
||||
}
|
||||
|
||||
onExecute() {
|
||||
const value = ([
|
||||
`Prefix ${c.match(":")} to execute command (:book, :yet, :stable etc)`,
|
||||
`Prefix ${c.match("!")} to search crates, prefix ${c.match("!!")} to search crates's docs url`,
|
||||
`Prefix ${c.match("@crate")} (${c.dim("e.g. @tokio")}) to search that crate's doc exclusively`,
|
||||
`Prefix ${c.match("#")} to search builtin attributes`,
|
||||
`Prefix ${c.match("%")} to search Rust official book chapters`,
|
||||
`Prefix ${c.match(">")} to search Rust clippy lints`,
|
||||
`[WIP] Prefix ${c.match("/")} to search official Rust project (rust-lang, rust-lang-nursery)`,
|
||||
`[WIP] Prefix ${c.match("?")} to search Rust tracking issues`,
|
||||
]);
|
||||
return value.map((description, index) => {
|
||||
return {content: `${index + 1}`, description};
|
||||
});
|
||||
}
|
||||
}
|
21
extension/command/stable.js
Normal file
21
extension/command/stable.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
class StableCommand extends Command {
|
||||
constructor() {
|
||||
super("stable", "Show stable Rust scheduled release date in the next year.")
|
||||
}
|
||||
onExecute(arg) {
|
||||
let dates = [];
|
||||
let startVersion = 42;
|
||||
let end = new Date();
|
||||
end.setFullYear(end.getFullYear() + 1);
|
||||
let date = new Date("2020-03-12");
|
||||
let now = new Date();
|
||||
for (let v = 1; ; v++) {
|
||||
date.setDate(date.getDate() + 42);
|
||||
if (date > end) break;
|
||||
if (date >= now) {
|
||||
dates.push(`Version ${c.match("1." + (startVersion + v) + ".0")} scheduled release on ${c.match(c.normalizeDate(date))}`);
|
||||
}
|
||||
}
|
||||
return this.wrap(dates);
|
||||
}
|
||||
}
|
22
extension/command/tool.js
Normal file
22
extension/command/tool.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
class ToolCommand extends Command {
|
||||
constructor() {
|
||||
super("tool", "Show some most useful Rust tools.");
|
||||
}
|
||||
|
||||
onExecute(arg) {
|
||||
const tools = [
|
||||
["Rust Playground", "https://play.rust-lang.org/"],
|
||||
["cheats.rs", "https://cheats.rs/"],
|
||||
["caniuse.rs", "https://caniuse.rs/"],
|
||||
["Macro Railroad ", "https://lukaslueg.github.io/macro_railroad_wasm_demo/"],
|
||||
];
|
||||
return tools
|
||||
.filter(item => !arg || item[0].toLowerCase().indexOf(arg) > -1)
|
||||
.map(([name,url]) => {
|
||||
return {
|
||||
content: url,
|
||||
description: `${c.match(name)} - ${c.dim(url)}`
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
26
extension/command/yet.js
Normal file
26
extension/command/yet.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
class YetCommand extends Command {
|
||||
constructor() {
|
||||
super("yet", "Show all Are We Yet websites.")
|
||||
}
|
||||
|
||||
onExecute(arg) {
|
||||
const areweyet = [
|
||||
["Are we async yet?", "Asynchronous I/O in Rust", "https://areweasyncyet.rs"],
|
||||
["Are we audio yet?", "Audio related development in Rust", "https://areweaudioyet.com"],
|
||||
["Are we game yet?", "Rust game development", "http://arewegameyet.com"],
|
||||
["Are we GUI yet?", "Rust GUI development", "http://areweguiyet.com"],
|
||||
["Are we IDE yet?", "Rust development environments", "http://areweideyet.com"],
|
||||
["Are we learning yet?", "Rust machine learning ecosystem", "http://www.arewelearningyet.com"],
|
||||
["Are we web yet?", "Rust libraries for web development", "http://arewewebyet.org"],
|
||||
["Are we podcast yet?", "Rust Are We Podcast Yet", "https://soundcloud.com/arewepodcastyet"],
|
||||
];
|
||||
return areweyet
|
||||
.filter(item => !arg || item[0].toLowerCase().indexOf(arg) > -1)
|
||||
.map(([title, description, content]) => {
|
||||
return {
|
||||
content,
|
||||
description: `${title} - ${c.dim(description)}`,
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -5,7 +5,14 @@ const bookSearcher = new BookSearch(booksIndex);
|
|||
const lintSearcher = new LintSearch(lintsIndex);
|
||||
const stdSearcher = new StdSearch(searchIndex);
|
||||
const crateDocSearchManager = new CrateDocSearchManager();
|
||||
const commandManager = new CommandManager();
|
||||
const commandManager = new CommandManager([
|
||||
new HelpCommand(),
|
||||
new BookCommand(),
|
||||
new YetCommand(),
|
||||
new StableCommand(),
|
||||
new ToolCommand(),
|
||||
new LabelCommand(labelsIndex),
|
||||
]);
|
||||
|
||||
const defaultSuggestion = `Search std ${c.match("docs")}, external ${c.match("docs")} (@), ${c.match("crates")} (!), ${c.match("attributes")} (#), ${c.match("books")} (%), clippy ${c.match("lints")} (>), and ${c.match("error codes")}, etc in your address bar instantly!`;
|
||||
const omnibox = new Omnibox(defaultSuggestion, c.omniboxPageSize());
|
||||
|
|
|
@ -58,11 +58,8 @@ history.forEach(({ query, content, description, time }) => {
|
|||
let pathname = url.pathname.replace("/crates/", "/").slice(1);
|
||||
let [crate, _] = pathname.split("/");
|
||||
crate = crate.replace(/-/gi, "_");
|
||||
if (topCratesData[crate]) {
|
||||
topCratesData[crate] += 1;
|
||||
} else {
|
||||
topCratesData[crate] = 1;
|
||||
}
|
||||
let counter = topCratesData[crate] || 0;
|
||||
topCratesData[crate] = counter + 1;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ local json = manifest.new(
|
|||
.addBackgroundScripts(js_files('search', ['book', 'crate', 'attribute', 'lint']))
|
||||
.addBackgroundScripts(js_files('search/docs', ['base', 'std', 'crate-doc']))
|
||||
.addBackgroundScripts(js_files('index', ['books', 'crates', 'std-docs', 'lints', 'labels']))
|
||||
.addBackgroundScripts(js_files('command', ['label']))
|
||||
.addBackgroundScripts(js_files('command', ['label', 'tool', 'book', 'help', 'yet', 'stable']))
|
||||
.addBackgroundScripts('main.js')
|
||||
.addContentScript(
|
||||
matches=['*://docs.rs/*'],
|
||||
|
|
Loading…
Reference in a new issue