Skip to content

Commit

Permalink
Add documentation page scaling feature (#722)
Browse files Browse the repository at this point in the history
* Add documentation.pageScale mechanism

* Fix issue with div of map() function catching the minimap style
  • Loading branch information
DaelonSuzuka authored Sep 23, 2024
1 parent 9b16946 commit 1a84a57
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 161 deletions.
2 changes: 1 addition & 1 deletion media/docs.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ a {
text-decoration: none;
}

#map {
#minimap {
position: fixed;
top: 0;
right: 0;
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/providers/document_link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
46 changes: 26 additions & 20 deletions src/providers/documentation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from "vscode";
import {
import type {
CancellationToken,
CustomDocument,
CustomDocumentOpenContext,
Expand All @@ -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");
Expand All @@ -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) {
Expand All @@ -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<void> {
public async resolveCustomEditor(
document: CustomDocument,
panel: WebviewPanel,
token: CancellationToken,
): Promise<void> {
const className = document.uri.path.split(".")[0];
const target = document.uri.fragment;
let symbol: GodotNativeSymbol = null;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Loading

0 comments on commit 1a84a57

Please sign in to comment.