mirror of
https://github.com/huhu/rust-search-extension
synced 2024-11-14 15:47:12 +00:00
Migrate compat functions
This commit is contained in:
parent
568f0ad863
commit
1d95e7e2c4
10 changed files with 30 additions and 24 deletions
2
core
2
core
|
@ -1 +1 @@
|
||||||
Subproject commit e3a99edc7eab99866928055e689d044e2931276c
|
Subproject commit e23e8cd9e1040b6cc70862e7fb42648a088ddecb
|
|
@ -1,4 +1,3 @@
|
||||||
import { c } from "../core/index.js";
|
|
||||||
import Command from "../core/command/base.js";
|
import Command from "../core/command/base.js";
|
||||||
|
|
||||||
export default class HelpCommand extends Command {
|
export default class HelpCommand extends Command {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { c } from "../core/index.js";
|
import { Compat } from "../core/index.js";
|
||||||
import Command from "../core/command/base.js";
|
import Command from "../core/command/base.js";
|
||||||
|
|
||||||
export default class LabelCommand extends Command {
|
export default class LabelCommand extends Command {
|
||||||
|
@ -31,7 +31,7 @@ export default class LabelCommand extends Command {
|
||||||
return results.map(label => {
|
return results.map(label => {
|
||||||
return {
|
return {
|
||||||
content: `https://github.com/rust-lang/rust/labels/${label.name}`,
|
content: `https://github.com/rust-lang/rust/labels/${label.name}`,
|
||||||
description: `<match>${label.name}</match> - <dim>${c.escape(label.description)}</dim>`
|
description: `<match>${label.name}</match> - <dim>${Compat.escape(label.description)}</dim>`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { c } from "../core/index.js";
|
import { Compat } from "../core/index.js";
|
||||||
import Command from "../core/command/base.js";
|
import Command from "../core/command/base.js";
|
||||||
|
|
||||||
export default class RfcCommand extends Command {
|
export default class RfcCommand extends Command {
|
||||||
|
@ -34,7 +34,7 @@ export default class RfcCommand extends Command {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return results.map(rfc => {
|
return results.map(rfc => {
|
||||||
let title = rfc.title ? `- <dim>${c.escape(rfc.title)}</dim>` : `<dim>${c.escape(rfc.title)}</dim>`;
|
let title = rfc.title ? `- <dim>${Compat.escape(rfc.title)}</dim>` : `<dim>${Compat.escape(rfc.title)}</dim>`;
|
||||||
return {
|
return {
|
||||||
content: `https://www.ncameron.org/rfcs/${String(rfc.number).padStart(4, '0')}.html`,
|
content: `https://www.ncameron.org/rfcs/${String(rfc.number).padStart(4, '0')}.html`,
|
||||||
description: `<match>RFC ${rfc.number}:</match> ${rfc.name} ${rfc.date} ${title}`
|
description: `<match>RFC ${rfc.number}:</match> ${rfc.name} ${rfc.date} ${title}`
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { c } from "../core/index.js";
|
|
||||||
import Command from "../core/command/base.js";
|
import Command from "../core/command/base.js";
|
||||||
|
|
||||||
export default class RustcCommand extends Command {
|
export default class RustcCommand extends Command {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { c } from "../core/index.js";
|
import { Compat } from "../core/index.js";
|
||||||
import Command from "../core/command/base.js";
|
import Command from "../core/command/base.js";
|
||||||
import { getScheduledVersions } from "../rust-version.js";
|
import { getScheduledVersions } from "../rust-version.js";
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ export default class StableCommand extends Command {
|
||||||
|
|
||||||
async onExecute(arg) {
|
async onExecute(arg) {
|
||||||
let versions = getScheduledVersions(100)
|
let versions = getScheduledVersions(100)
|
||||||
.map(version => `Version <match>${version.number}</match> scheduled release on <match>${c.normalizeDate(version.date)}</match>`)
|
.map(version => `Version <match>${version.number}</match> scheduled release on <match>${Compat.normalizeDate(version.date)}</match>`)
|
||||||
return this.wrap(versions);
|
return this.wrap(versions);
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -1,4 +1,4 @@
|
||||||
import { c } from "../core/index.js";
|
import { Compat } from "../core/index.js";
|
||||||
import Command from "../core/command/base.js";
|
import Command from "../core/command/base.js";
|
||||||
|
|
||||||
export default class TargetCommand extends Command {
|
export default class TargetCommand extends Command {
|
||||||
|
@ -23,7 +23,7 @@ export default class TargetCommand extends Command {
|
||||||
.map(target => {
|
.map(target => {
|
||||||
return {
|
return {
|
||||||
content: target.url,
|
content: target.url,
|
||||||
description: `${c.capitalize(target.tier)}: <match>${target.name}</match> - <dim>${target.description}</dim>`,
|
description: `${Compat.capitalize(target.tier)}: <match>${target.name}</match> - <dim>${target.description}</dim>`,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1,10 @@
|
||||||
<script src="service-worker.js" type="module"></script>
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>Rust Search Extension</title>
|
||||||
|
<script src="service-worker.js" type="module"></script>
|
||||||
|
</head>
|
||||||
|
<body></body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ import OpenCommand from "./core/command/open.js";
|
||||||
import HistoryCommand from "./core/command/history.js";
|
import HistoryCommand from "./core/command/history.js";
|
||||||
import CommandManager from "./core/command/manager.js";
|
import CommandManager from "./core/command/manager.js";
|
||||||
import CrateDocManager from "./crate-manager.js";
|
import CrateDocManager from "./crate-manager.js";
|
||||||
import { Omnibox, c } from "./core/index.js";
|
import { Omnibox, Compat } from "./core/index.js";
|
||||||
|
|
||||||
const INDEX_UPDATE_URL = "https://rust.extension.sh/update";
|
const INDEX_UPDATE_URL = "https://rust.extension.sh/update";
|
||||||
const RUST_RELEASE_README_URL = "https://github.com/rust-lang/rust/blob/master/RELEASES.md";
|
const RUST_RELEASE_README_URL = "https://github.com/rust-lang/rust/blob/master/RELEASES.md";
|
||||||
|
@ -39,7 +39,7 @@ function getPlatformOs() {
|
||||||
|
|
||||||
async function start(el, placeholder) {
|
async function start(el, placeholder) {
|
||||||
const defaultSuggestion = `Search std <match>docs</match>, external <match>docs</match> (~,@), <match>crates</match> (!), <match>attributes</match> (#), <match>books</match> (%), clippy <match>lints</match> (>), and <match>error codes</match>, etc in your address bar instantly!`;
|
const defaultSuggestion = `Search std <match>docs</match>, external <match>docs</match> (~,@), <match>crates</match> (!), <match>attributes</match> (#), <match>books</match> (%), clippy <match>lints</match> (>), and <match>error codes</match>, etc in your address bar instantly!`;
|
||||||
const omnibox = new Omnibox({ el, defaultSuggestion: placeholder || defaultSuggestion, maxSuggestionSize: c.omniboxPageSize() });
|
const omnibox = new Omnibox({ el, defaultSuggestion: placeholder || defaultSuggestion, maxSuggestionSize: Compat.omniboxPageSize() });
|
||||||
|
|
||||||
// All dynamic setting items. Those items will been updated
|
// All dynamic setting items. Those items will been updated
|
||||||
// in chrome.storage.onchange listener callback.
|
// in chrome.storage.onchange listener callback.
|
||||||
|
@ -118,7 +118,7 @@ async function start(el, placeholder) {
|
||||||
|
|
||||||
let description = doc.displayPath + `<match>${doc.name}</match>`;
|
let description = doc.displayPath + `<match>${doc.name}</match>`;
|
||||||
if (doc.desc) {
|
if (doc.desc) {
|
||||||
description += ` - <dim>${c.escape(c.eliminateTags(doc.desc))}</dim>`;
|
description += ` - <dim>${Compat.escape(Compat.eliminateTags(doc.desc))}</dim>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doc.queryType === "s" || doc.queryType === "src") {
|
if (doc.queryType === "s" || doc.queryType === "src") {
|
||||||
|
@ -246,7 +246,7 @@ async function start(el, placeholder) {
|
||||||
let content = `@${item.name}`;
|
let content = `@${item.name}`;
|
||||||
return {
|
return {
|
||||||
content,
|
content,
|
||||||
description: `<match>${content}</match> v${item.version} - <dim>${c.escape(c.eliminateTags(item.doc))}</dim>`,
|
description: `<match>${content}</match> v${item.version} - <dim>${Compat.escape(Compat.eliminateTags(item.doc))}</dim>`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -279,7 +279,7 @@ async function start(el, placeholder) {
|
||||||
onFormat: (index, crate) => {
|
onFormat: (index, crate) => {
|
||||||
return {
|
return {
|
||||||
content: `https://docs.rs/${crate.id}`,
|
content: `https://docs.rs/${crate.id}`,
|
||||||
description: `${c.capitalize("docs.rs")}: <match>${crate.id}</match> v${crate.version} - <dim>${c.escape(c.eliminateTags(crate.description))}</dim>`,
|
description: `${Compat.capitalize("docs.rs")}: <match>${crate.id}</match> v${crate.version} - <dim>${Compat.escape(Compat.eliminateTags(crate.description))}</dim>`,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
onAppend: (query) => {
|
onAppend: (query) => {
|
||||||
|
@ -298,7 +298,7 @@ async function start(el, placeholder) {
|
||||||
onFormat: (index, crate) => {
|
onFormat: (index, crate) => {
|
||||||
return {
|
return {
|
||||||
content: `https://${crateRegistry}/crates/${crate.id}`,
|
content: `https://${crateRegistry}/crates/${crate.id}`,
|
||||||
description: `${c.capitalize(crateRegistry)}: <match>${crate.id}</match> v${crate.version} - <dim>${c.escape(c.eliminateTags(crate.description))}</dim>`,
|
description: `${Compat.capitalize(crateRegistry)}: <match>${crate.id}</match> v${crate.version} - <dim>${Compat.escape(Compat.eliminateTags(crate.description))}</dim>`,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
onAppend: (query) => {
|
onAppend: (query) => {
|
||||||
|
@ -318,7 +318,7 @@ async function start(el, placeholder) {
|
||||||
onFormat: (index, crate) => {
|
onFormat: (index, crate) => {
|
||||||
return {
|
return {
|
||||||
content: `${REDIRECT_URL}?crate=${crate.id}`,
|
content: `${REDIRECT_URL}?crate=${crate.id}`,
|
||||||
description: `${c.capitalize("repository")}: <match>${crate.id}</match> v${crate.version} - <dim>${c.escape(c.eliminateTags(crate.description))}</dim>`,
|
description: `${Compat.capitalize("repository")}: <match>${crate.id}</match> v${crate.version} - <dim>${Compat.escape(Compat.eliminateTags(crate.description))}</dim>`,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
onAppend: (query) => {
|
onAppend: (query) => {
|
||||||
|
@ -342,7 +342,7 @@ async function start(el, placeholder) {
|
||||||
onFormat: (index, attribute) => {
|
onFormat: (index, attribute) => {
|
||||||
return {
|
return {
|
||||||
content: attribute.href,
|
content: attribute.href,
|
||||||
description: `Attribute: <match>#[${attribute.name}]</match> <dim>${c.escape(attribute.description)}</dim>`,
|
description: `Attribute: <match>#[${attribute.name}]</match> <dim>${Compat.escape(attribute.description)}</dim>`,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -354,7 +354,7 @@ async function start(el, placeholder) {
|
||||||
onFormat: (index, feat, query) => {
|
onFormat: (index, feat, query) => {
|
||||||
return {
|
return {
|
||||||
content: `https://caniuse.rs/features/${feat.slug}`,
|
content: `https://caniuse.rs/features/${feat.slug}`,
|
||||||
description: `Can I use: <match>${c.escape(feat.match)}</match> [${feat.version}] - <dim>${c.escape(feat.description)}</dim>`
|
description: `Can I use: <match>${Compat.escape(feat.match)}</match> [${feat.version}] - <dim>${Compat.escape(feat.description)}</dim>`
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
onAppend: () => {
|
onAppend: () => {
|
||||||
|
@ -392,7 +392,7 @@ async function start(el, placeholder) {
|
||||||
let parentTitles = page.parentTitles || [];
|
let parentTitles = page.parentTitles || [];
|
||||||
return {
|
return {
|
||||||
content: page.url,
|
content: page.url,
|
||||||
description: `${[...parentTitles.map(t => c.escape(t)), `<match>${c.escape(page.title)}</match>`].join(" > ")} - <dim>${page.name}</dim>`
|
description: `${[...parentTitles.map(t => Compat.escape(t)), `<match>${Compat.escape(page.title)}</match>`].join(" > ")} - <dim>${page.name}</dim>`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onAppend: () => {
|
onAppend: () => {
|
||||||
|
@ -411,7 +411,7 @@ async function start(el, placeholder) {
|
||||||
onFormat: (_, lint) => {
|
onFormat: (_, lint) => {
|
||||||
return {
|
return {
|
||||||
content: `${LINT_URL}#${lint.name}`,
|
content: `${LINT_URL}#${lint.name}`,
|
||||||
description: `Clippy lint: [${lint.level}] <match>${lint.name}</match> - <dim>${c.escape(c.eliminateTags(lint.description))}</dim>`,
|
description: `Clippy lint: [${lint.level}] <match>${lint.name}</match> - <dim>${Compat.escape(Compat.eliminateTags(lint.description))}</dim>`,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { c } from "../../core/index.js";
|
|
||||||
import DocSearch from "./base.js";
|
import DocSearch from "./base.js";
|
||||||
import CrateDocManager from "../../crate-manager.js";
|
import CrateDocManager from "../../crate-manager.js";
|
||||||
import settings from "../../settings.js";
|
import settings from "../../settings.js";
|
||||||
|
|
Loading…
Reference in a new issue