Sunset rustc docs search (#281)

This commit is contained in:
Folyd 2024-06-04 14:53:05 +08:00 committed by GitHub
parent 56039cd56a
commit 90016b2aff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 2 additions and 73 deletions

View file

@ -10,7 +10,6 @@ import LintSearch from "./search/lint.js";
import AttributeSearch from "./search/attribute.js";
import DocSearch from "./search/docs/base.js";
import CrateDocSearch from "./search/docs/crate-doc.js";
import RustcSearch from "./search/docs/rustc.js";
import LabelCommand from "./command/label.js";
import RfcCommand from "./command/rfc.js";
import RustcCommand from "./command/rustc.js";
@ -107,7 +106,6 @@ async function start(el, icon, placeholder) {
// Nightly docs doesn't support offline mode yet.
return "https://doc.rust-lang.org/nightly/";
});
let rustcSearcher = new RustcSearch();
let formatDoc = (index, doc) => {
let content = doc.href;
@ -189,36 +187,6 @@ async function start(el, icon, placeholder) {
},
});
// Nightly rustc docs search
omnibox.addPrefixQueryEvent("//", {
onSearch: (query) => {
query = query.replaceAll("/", "").trim();
return rustcSearcher.search(query);
},
onFormat: (index, doc) => {
let { content, description } = formatDoc(index, doc);
return { content, description: '[Rustc] ' + description };
},
onAppend: (query) => {
query = query.replaceAll("/", "").trim();
let appendix = {
content: rustcSearcher.getSearchUrl(query),
description: `Search nightly rustc docs <match>${query}</match> on ${rustcSearcher.getRootPath()}`,
};
if (rustcSearcher?.searchIndex?.length > 0) {
return [appendix];
} else {
return [
appendix,
{
content: rustcSearcher.getRootPath(),
description: "To search nightly rustc docs on the address bar, please open the nightly rustc docs page in advance.",
},
];
}
},
});
omnibox.addPrefixQueryEvent("~", {
isDefaultSearch: () => {
return defaultSearch.thirdPartyDocs;
@ -431,23 +399,6 @@ async function start(el, icon, placeholder) {
// https://github.com/mozilla/webextension-polyfill/issues/130#issuecomment-918076049
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
switch (message.action) {
// Rustc:* action is exclusive to rustc docs event
case "rustc:check": {
sendResponse({
version: rustcSearcher.version,
});
break;
}
case "rustc:add": {
if (message.searchIndex) {
rustcSearcher.setSearchIndex(message.searchIndex);
rustcSearcher.setVersion(message.version);
sendResponse(true);
} else {
sendResponse(false);
}
break;
}
case "open-url": {
if (message.url) {
Omnibox.navigateToUrl(message.url);

View file

@ -548,8 +548,8 @@ export default class DocSearch {
if (result.dontValidate) {
continue;
}
const name = result.item.name.toLowerCase(),
path = result.item.path.toLowerCase(),
const name = result.item.name?.toLowerCase(),
path = result.item.path?.toLowerCase(),
parent = result.item.parent;
if (this.validateResult(name, path, this.split, parent) === false) {

View file

@ -1,22 +0,0 @@
import DocSearch from "./base.js";
export default class RustcSearch extends DocSearch {
constructor(searchIndex) {
super("rustc", searchIndex, () => {
return "https://doc.rust-lang.org/nightly/nightly-rustc/";
});
}
// rustc cached version, see also script/rustc.js
setVersion(version) {
this.version = version;
}
getSearchUrl(keyword) {
let url = `${this.getRootPath()}index.html`;
if (keyword) {
url += `?search=${encodeURIComponent(keyword)}`;
}
return url;
}
};