Skip to content

Update to Godot 4 and highlight.js 11 #17

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Calinou
Copy link
Contributor

@Calinou Calinou commented May 10, 2025

Note that I couldn't get the ES module build to work in the browser, so maybe we should remove it.

Testing project: highlightjs-gdscript-test.zip
Change the path to dist/gdscript.min.js in index.html to match a location on disk, then open index.html in a web browser. No build step needed.

Preview

Using vs2015 theme and the test project linked above.

Preview

@joshgoebel
Copy link
Member

Please do the "upgrade" work in an isolated commit (that doesn't move the file around) so I can properly review the changes.

Note that I couldn't get the ES module build to work in the browser,
so maybe we should remove it.
@Calinou Calinou force-pushed the update-to-godot-4 branch from 2ab771b to 1851cfa Compare May 12, 2025 18:02
@Calinou
Copy link
Contributor Author

Calinou commented May 12, 2025

Please do the "upgrade" work in an isolated commit (that doesn't move the file around) so I can properly review the changes.

Done (it turns out we don't need to move any files after rebasing on master).

{
className: "comment",
className: 'string',
Copy link
Contributor Author

@Calinou Calinou May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context, GDScript does not actually have multiline comments, but only multiline strings. Multiline strings on their own line are standalone expressions, so they have no effect if you use them as comments.

The style guide recommends using ## for documentation comments, as this makes them display in the inspector when hovering the property.

Copy link

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me overall.

Regarding my comments to document the source of the lists of keywords/built-ins, if it's not suitable to include in gdscript.js as comments, maybe this could go in a README.

Comment on lines +45 to +48
'StringName NodePath Dictionary Array PackedByteArray ' +
'PackedInt32Array PackedInt64Array PackedFloat32Array ' +
'PackedFloat64Array PackedStringArray PackedVector2Array ' +
'PackedVector3Array PackedColorArray PackedVector4Array Variant ' +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we lost the Godot 3 Pool*Arrays here.

Comment on lines +43 to +44
'Vector3 Vector3i Vector4 Vector4i Plane AABB Quaternion Basis ' +
'Transform3D Projection Color RID Object Callable Signal ' +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also include the old Godot 3 math types?

Rect3 Quat Transform

Comment on lines +11 to +16
keyword:
'class class_name const enum extends func namespace signal static ' +
'trait var await breakpoint yield set get and in not or void as ' +
'assert tool export onready break continue if elif else for pass ' +
'return match when while remote sync master puppet remotesync ' +
'mastersync puppetsync',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth documenting where to find those for future syncs.
Maybe use modules/gdscript/gdscript.cpp GDScriptLanguage::get_reserved_words() as reference?

BTW Godot 4.5 is adding abstract too.

There's also namespace and trait which are reserved for future use and thus highlighted by Godot, so we should include them too.

keyword:
'class class_name const enum extends func namespace signal static ' +
'trait var await breakpoint yield set get and in not or void as ' +
'assert tool export onready break continue if elif else for pass ' +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For assert, gdscript.cpp has:

                // Functions (highlighter uses global function color instead).
                "assert",
                "preload",

So maybe it should be moved to built_in like preload?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I see it is also listed under built_in already, so the one here should probably be removed.

Comment on lines +18 to +21
built_in:
'abs absf absi acos acosh angle_difference asin asinh atan atan2 ' +
'atanh bezier_derivative bezier_interpolate bytes_to_var ' +
'bytes_to_var_with_objects ceil ceilf ceili clamp clampf clampi ' +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to document how to retrieve/update that list in case it changes in the future.

I've got the list for Godot 4 with:

grep "method name=" doc/classes/@GlobalScope.xml | sed 's/.*name="\([^"]*\)".*/\1/'

and

grep "method name=" modules/gdscript/doc_classes/@GDScript.xml | sed 's/.*name="\([^"]*\)".*/\1/'

And confirmed that it matches the list you have here. But that also means we're missing 3.x built-ins.

Assuming we can include comments between lines in this long string, I'd suggest prefacing the blocks like this:

# Godot 4 @GlobalScope methods
# `grep "method name=" doc/classes/@GlobalScope.xml | sed 's/.*name="\([^"]*\)".*/\1/'`

# Godot 4 @GDScript built-ins
# `grep "method name=" modules/gdscript/doc_classes/@GDScript.xml | sed 's/.*name="\([^"]*\)".*/\1/'`

# Godot 3 @GDScript built-ins not in Godot 4
# `grep "method name=" modules/gdscript/doc_classes/@GDScript.xml | sed 's/.*name="\([^"]*\)".*/\1/'``

(there's no @GlobalScope methods in 3.x, they're all in @GDScript)

I found the following Godot 3 built-ins missing here:

ColorN
bytes2var
cartesian2polar
db2linear
dectime
deep_equal
deg2rad
dict2inst
funcref
inst2dict
linear2db
ord
parse_json
polar2cartesian
rad2deg
rand_range
rand_seed
range_lerp
stepify
str2var
to_json
validate_json
var2bytes
var2str
yield

(yield is already a reserved keyword listed above for Godot 4 so it doesn't need to be re-listed here)

Comment on lines +113 to +116
keyword:
'@export @export_category @export_color_no_alpha @export_custom ' +
'@export_dir @export_enum @export_exp_easing @export_file ' +
'@export_flags @export_flags_2d_navigation @export_flags_2d_physics ' +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed the list of annotations is accurate for Godot 4 with:

grep "register_annotation(MethodInfo" gdscript_parser.cpp | sed 's/.*MethodInfo("\([^"]*\)".*/\1/' | sort

Could be documented too for future syncs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants