From 1a84a576477d07d1c4ce07cc0ff86099347582e3 Mon Sep 17 00:00:00 2001 From: David Kincaid Date: Mon, 23 Sep 2024 13:56:25 -0400 Subject: [PATCH] Add documentation page scaling feature (#722) * Add documentation.pageScale mechanism * Fix issue with div of map() function catching the minimap style --- media/docs.css | 2 +- package.json | 7 + src/providers/document_link.ts | 8 +- src/providers/documentation.ts | 46 ++--- src/providers/documentation_builder.ts | 236 +++++++++++-------------- 5 files changed, 137 insertions(+), 162 deletions(-) diff --git a/media/docs.css b/media/docs.css index c73718b..2e2d1a8 100644 --- a/media/docs.css +++ b/media/docs.css @@ -6,7 +6,7 @@ a { text-decoration: none; } -#map { +#minimap { position: fixed; top: 0; right: 0; diff --git a/package.json b/package.json index 6c9890d..26f8d7a 100644 --- a/package.json +++ b/package.json @@ -251,6 +251,13 @@ "type": "object", "title": "Godot Tools", "properties": { + "godotTools.documentation.pageScale": { + "type": "integer", + "default": 100, + "minimum": 50, + "maximum": 200, + "description": "Scale factor (%) to apply to the Godot documentation viewer." + }, "godotTools.editorPath.godot3": { "type": "string", "default": "godot3", diff --git a/src/providers/document_link.ts b/src/providers/document_link.ts index bffb0c9..cf183fe 100644 --- a/src/providers/document_link.ts +++ b/src/providers/document_link.ts @@ -2,11 +2,11 @@ import * as vscode from "vscode"; import { Uri, Range, - TextDocument, - CancellationToken, + type TextDocument, + type CancellationToken, DocumentLink, - DocumentLinkProvider, - ExtensionContext, + type DocumentLinkProvider, + type ExtensionContext, } from "vscode"; import { SceneParser } from "../scene_tools"; import { convert_resource_path_to_uri, createLogger } from "../utils"; diff --git a/src/providers/documentation.ts b/src/providers/documentation.ts index 625400a..8254a3a 100644 --- a/src/providers/documentation.ts +++ b/src/providers/documentation.ts @@ -1,5 +1,5 @@ import * as vscode from "vscode"; -import { +import type { CancellationToken, CustomDocument, CustomDocumentOpenContext, @@ -8,15 +8,15 @@ import { Uri, WebviewPanel, } from "vscode"; -import { NotificationMessage } from "vscode-jsonrpc"; -import { +import type { NotificationMessage } from "vscode-jsonrpc"; +import type { NativeSymbolInspectParams, GodotNativeSymbol, GodotNativeClassInfo, GodotCapabilities, } from "../lsp/gdscript.capabilities"; import { make_html_content } from "./documentation_builder"; -import { createLogger, get_extension_uri, make_docs_uri } from "../utils"; +import { createLogger, get_configuration, get_extension_uri, make_docs_uri } from "../utils"; import { globals } from "../extension"; const log = createLogger("providers.docs"); @@ -37,9 +37,7 @@ export class GDDocumentationProvider implements CustomReadonlyEditorProvider { }, supportsMultipleEditorsPerDocument: true, }; - context.subscriptions.push( - vscode.window.registerCustomEditorProvider("gddoc", this, options), - ); + context.subscriptions.push(vscode.window.registerCustomEditorProvider("gddoc", this, options)); } public register_capabilities(message: NotificationMessage) { @@ -63,23 +61,28 @@ export class GDDocumentationProvider implements CustomReadonlyEditorProvider { } public async list_native_classes() { - const classname = await vscode.window.showQuickPick( - [...this.classInfo.keys()].sort(), - { - placeHolder: "Type godot class name here", - canPickMany: false, - } - ); + const classname = await vscode.window.showQuickPick([...this.classInfo.keys()].sort(), { + placeHolder: "Type godot class name here", + canPickMany: false, + }); if (classname) { vscode.commands.executeCommand("vscode.open", make_docs_uri(classname)); } } - public openCustomDocument(uri: Uri, openContext: CustomDocumentOpenContext, token: CancellationToken): CustomDocument { - return { uri: uri, dispose: () => { } }; + public openCustomDocument( + uri: Uri, + openContext: CustomDocumentOpenContext, + token: CancellationToken, + ): CustomDocument { + return { uri: uri, dispose: () => {} }; } - public async resolveCustomEditor(document: CustomDocument, panel: WebviewPanel, token: CancellationToken): Promise { + public async resolveCustomEditor( + document: CustomDocument, + panel: WebviewPanel, + token: CancellationToken, + ): Promise { const className = document.uri.path.split(".")[0]; const target = document.uri.fragment; let symbol: GodotNativeSymbol = null; @@ -89,7 +92,7 @@ export class GDDocumentationProvider implements CustomReadonlyEditorProvider { }; while (!this.ready) { - await new Promise(resolve => setTimeout(resolve, 100)); + await new Promise((resolve) => setTimeout(resolve, 100)); } symbol = this.symbolDb.get(className); @@ -109,9 +112,12 @@ export class GDDocumentationProvider implements CustomReadonlyEditorProvider { if (!this.htmlDb.has(className)) { this.htmlDb.set(className, make_html_content(panel.webview, symbol, target)); } - panel.webview.html = this.htmlDb.get(className); + + const scaleFactor = get_configuration("documentation.pageScale"); + + panel.webview.html = this.htmlDb.get(className).replaceAll("scaleFactor", scaleFactor); panel.iconPath = get_extension_uri("resources/godot_icon.svg"); - panel.webview.onDidReceiveMessage(msg => { + panel.webview.onDidReceiveMessage((msg) => { if (msg.type === "INSPECT_NATIVE_SYMBOL") { const uri = make_docs_uri(msg.data.native_class, msg.data.symbol_name); vscode.commands.executeCommand("vscode.open", uri); diff --git a/src/providers/documentation_builder.ts b/src/providers/documentation_builder.ts index 85ac873..9d7d3f2 100644 --- a/src/providers/documentation_builder.ts +++ b/src/providers/documentation_builder.ts @@ -3,7 +3,7 @@ import { SymbolKind } from "vscode-languageclient"; import * as Prism from "prismjs"; import * as csharp from "prismjs/components/prism-csharp"; import { marked } from "marked"; -import { GodotNativeSymbol } from "../lsp/gdscript.capabilities"; +import type { GodotNativeSymbol } from "../lsp/gdscript.capabilities"; import { get_extension_uri } from "../utils"; import yabbcode = require("ya-bbcode"); @@ -14,7 +14,7 @@ const parser = new yabbcode(); const wtf = csharp; marked.setOptions({ - highlight: function (code, lang) { + highlight: (code, lang) => { if (lang === "gdscript") { return Prism.highlight(code, GDScriptGrammar, lang); } @@ -69,7 +69,7 @@ export function make_html_content(webview: vscode.Webview, symbol: GodotNativeSy `; } - return /*html*/` + return /*html*/ ` @@ -78,16 +78,16 @@ export function make_html_content(webview: vscode.Webview, symbol: GodotNativeSy ${symbol.name} - +
${make_symbol_document(symbol)}
- +