Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation page scaling feature #722

Merged
merged 6 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading