Skip to content
Open
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
43 changes: 43 additions & 0 deletions .changeset/silent-clouds-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
"@godot-js/editor": minor
---

feat: additionally to @bind.help/experimental/deprecated add an editor setting to enable standard JS comments and JSDoc like annotations for documentation comments.

You need to enable the setting, set ``Editor -> Editor Settings -> GodotJS -> Experimental -> Jsdoc Documentation Comments `` to ``on``.

Here is an example for more information see https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_documentation_comments.html:
````ts
/**
* A brief description of the class's role and functionality.
*
* The description of the script, what it can do,
* and any further detail.
*
* @tutorial https://example.com/tutorial_1
* @tutorial(Tutorial 2) https://example.com/tutorial_2
* @experimental
*/
export default class DocumentationComments extends Node {

/**
* This is a multiline description of the variable v2.
* The type information below will be extracted for the documentation.
*/
v2: number = 0;

/**
* As the following function is documented, even though its name starts with
* an underscore, it will appear in the help window.
*/
_fn(p1: number, p2: string): number {
return 0;
}

/**
* This function is deprecated and should not appear in the help window.
* @deprecated Use [method _fn] instead
*/
_deprecated() {}
}
````
10 changes: 9 additions & 1 deletion internal/jsb_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace jsb::internal
{
#ifdef TOOLS_ENABLED
static constexpr char kEdExperimentalJSDocDocumentationComments[] = JSB_MODULE_NAME_STRING "/experimental/jsdoc_documentation_comments";
static constexpr char kEdDebuggerPort[] = JSB_MODULE_NAME_STRING "/debugger/editor_port";
static constexpr char kEdIgnoredClasses[] = JSB_MODULE_NAME_STRING "/codegen/ignored_classes";
static constexpr char kEdAutogenPath[] = JSB_MODULE_NAME_STRING "/codegen/autogen_path";
Expand Down Expand Up @@ -61,7 +62,8 @@ namespace jsb::internal
if (EditorSettings::get_singleton())
{
inited = true;
_EDITOR_DEF(kEdDebuggerPort, 9230, true);
_EDITOR_DEF(kEdExperimentalJSDocDocumentationComments, false, true);
_EDITOR_DEF(kEdDebuggerPort, 9230, true);
_EDITOR_DEF(kEdIgnoredClasses, PackedStringArray(), false);
_EDITOR_DEF(kEdAutogenPath, "gen/godot", false);
_EDITOR_DEF(kEdGenSceneDTS, true, false);
Expand Down Expand Up @@ -174,6 +176,12 @@ namespace jsb::internal
init_editor_settings();
return EDITOR_GET(kEdCodegenUseProjectSettings);
}

bool Settings::get_jsdoc_documentation_comments()
{
init_editor_settings();
return EDITOR_GET(kEdExperimentalJSDocDocumentationComments);
}
#endif

bool Settings::is_packaging_with_source_map()
Expand Down
1 change: 1 addition & 0 deletions internal/jsb_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace jsb::internal
static bool get_autogen_resource_dts_on_save();
static bool get_gen_resource_dts();
static bool get_codegen_use_project_settings();
static bool get_jsdoc_documentation_comments();
#endif
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module "godot" {
interface SceneNodes {
"tests/documentation-comments/DocumentationComments.tscn": { Label: Label<{}>; };
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import DocumentationComments from "../../../../tests/documentation-comments/documentation-comments";
declare module "godot" {
interface ResourceTypes {
"res://tests/documentation-comments/DocumentationComments.tscn": PackedScene<DocumentationComments>;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[gd_scene load_steps=2 format=3 uid="uid://b33p5actrbp6s"]

[ext_resource type="Script" uid="uid://b13817mvpqwo5" path="res://tests/documentation-comments/documentation-comments.ts" id="1_j3med"]

[node name="DocumentationComments" type="Node2D"]
script = ExtResource("1_j3med")

[node name="Label" type="Label" parent="."]
offset_right = 40.0
offset_bottom = 23.0
text = "DocumentationComments"
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Node, Signal, Variant } from "godot";
import { createClassBinder } from "godot.annotations";

const bind = createClassBinder();

/** This is a description of the below enum. */
enum Direction {
/** Direction up. */
UP = 0,
/** Direction down. */
DOWN = 1,
/** Direction left. */
LEFT = 2,
/** Direction right. */
RIGHT = 3,
}

/**
* A brief description of the class's role and functionality.
*
* The description of the script, what it can do,
* and any further detail.
*
* @tutorial https://example.com/tutorial_1
* @tutorial(Tutorial 2) https://example.com/tutorial_2
* @experimental
*/
@bind()
export default class DocumentationComments extends Node {
/** The description of a signal. */
@bind.signal()
accessor my_signal!: Signal<() => void>;

/** The description of a constant. */
static readonly GRAVITY = 9.8;

/** The description of the variable v1. */
v1: any;

/**
* This is a multiline description of the variable v2.
* The type information below will be extracted for the documentation.
*/
v2: number = 0;

/**
* If the member has any annotation, the annotation should
* immediately precede it.
*/
@bind.export(Variant.Type.TYPE_INT)
accessor v3: number = some_func();

/**
* As the following function is documented, even though its name starts with
* an underscore, it will appear in the help window.
*/
_fn(p1: number, p2: string): number {
return 0;
}

// The below function isn't documented and its name starts with an underscore
// so it will treated as private and will not be shown in the help window.
_internal(): void {}

/**
* This function is deprecated and should not appear in the help window.
* @deprecated Use [method _fn] instead
*/
_deprecated() {}
}

function some_func(): number {
return 0;
}
Loading
Loading