1 /* eslint-disable max-len */
2 import { CommandWithArgs } from "./command.mjs";
3 import Logger from "../logger.mjs";
4 import { type QuickPickItem, ViewColumn, window, Uri } from "vscode";
5 import { readFileSync } from "fs";
7 export enum DocumentationId {
11 runtimeInfrastructure = 3,
14 export const DOCUMENTATION_LABEL_BY_ID: string[] = [
17 "Networking Libraries",
18 "Runtime Infrastructure",
21 // eslint-disable-next-line @typescript-eslint/no-unused-vars
22 const DOCUMENTATION_URLS_BY_ID: string[] = [
23 //"https://raspberrypi.github.io/pico-sdk-doxygen/index.html",
24 "https://www.raspberrypi.com/documentation/pico-sdk/hardware.html",
25 "https://www.raspberrypi.com/documentation/pico-sdk/high_level.html",
26 "https://www.raspberrypi.com/documentation/pico-sdk/networking.html",
27 "https://www.raspberrypi.com/documentation/pico-sdk/runtime.html",
30 const LOCAL_DOCUMENTATION_URLS_BY_ID: string[] = [
37 export default class OpenSdkDocumentationCommand extends CommandWithArgs {
38 private _logger: Logger = new Logger("OpenSdkDocumentationCommand");
40 public static readonly id = "openSdkDocumentation";
42 constructor(private readonly _extensionUri: Uri) {
43 super(OpenSdkDocumentationCommand.id);
46 async execute(docId?: DocumentationId): Promise<void> {
47 let url = docId !== undefined ? LOCAL_DOCUMENTATION_URLS_BY_ID[docId] : "";
48 if (docId === undefined) {
49 const options: QuickPickItem[] = DOCUMENTATION_LABEL_BY_ID.map(
52 detail: LOCAL_DOCUMENTATION_URLS_BY_ID[index],
56 const result = await window.showQuickPick(options, {
57 placeHolder: "Select Category",
59 ignoreFocusOut: false,
62 if (result === undefined || result.detail === undefined) {
70 this._logger.info("Opening SDK documentation in browser...");
71 const panel = window.createWebviewPanel(
72 "pico-sdk-documentation",
73 "Pico SDK Documentation",
74 { viewColumn: ViewColumn.Two, preserveFocus: false },
77 retainContextWhenHidden: true,
78 enableFindWidget: true,
79 localResourceRoots: [Uri.joinPath(this._extensionUri, "web", "docs")],
80 enableCommandUris: true,
84 panel.webview.html = this._getHtmlForWebview(
85 Uri.joinPath(this._extensionUri, "web", "docs", url).fsPath,
88 Uri.joinPath(this._extensionUri, "web", "docs", "docstyle.css")
91 panel.webview.cspSource
96 private _getHtmlForWebview(
101 const regex = /<a\s+(.*?)\s?href=".+(#[^"]+)"/g;
107 .replace(/{{docstyle}}/g, docstyle)
108 /*.replace(/{{jquery}}/g, jquery)
109 .replace(/{{jquery-ui}}/g, jqueryUi)
110 .replace(/{{jquery-tocify}}/g, jqueryTocify)
111 .replace(/{{nonce}}/g, nonce)*/
112 .replace(/{{cspSource}}/g, cspSource)
113 .replace(regex, '<a $1 href="$2"')