How To Use Default GDScript Highlighter In CodeEdit?

Godot Version

4.4

Question

I am working on a new project which involves displaying GDScript code to the user, and for the CodeEdits I wanted to use the GDScriptHighlighter resource, but that is for plugins only as it uses editor settings.

But my question is; Is there a way to get the default version of the GDScriptHighlighter? So one that uses all the settings from a clean install of Godot? Because so far the only workaround I have found is making a custom resource and copying over all the possible colours and trying to fit in all the keywords (For built-ins like print() or len(), or classes like int / String).
But even then Strings don’t show up correctly:

(My recreation, followed by the GDScriptHighlighter)


Is it possible to get a static / independent version of the GDScriptHighlighter so everything displays correctly?

Thanks.

As far as I know you’ll need to recreate it yourself.

For the strings you’ll need to use CodeHighlighter.add_color_region()

Here’s the GDScript hightlighter cpp code you could use to recreate it godot/modules/gdscript/editor/gdscript_highlighter.cpp at master · godotengine/godot · GitHub. _update_cache() seems to have everything you need.

1 Like

Ah okay, it is a shame that you can’t use the resource for this, and then it could use either the default or you could set it to use your current settings and then save it.
But having the source code will help a ton.

Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.