You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Context
I'm creating an editor plugin with GDExtension that involves working with .ink files, and I'm trying to create a syntax highlighter for it in pure C++. I'm creating and registering this highlighter class:
// _enter_tree() in the EditorPlugin class
Ref<InkSyntaxHighlighter> hl = memnew(InkSyntaxHighlighter);
syntax_highlighter = hl;
ScriptEditor* script_editor = get_editor_interface()->get_script_editor();
script_editor->register_syntax_highlighter(syntax_highlighter);
However, I cannot get any part of the highlighter to actually work; it shows up as an option in the syntax highlighters list, but it just shows up as Unnamed and doesn't actually provide any highlighting. (I tried putting prints in all three functions and none of them are even called)
What I think is the problem
I looked into the Godot source code for EditorSyntaxHighlighter, and it has a method called _create which is called whenever a highlighter is instantiated. Normally, it instantiates a base EditorSyntaxHighlighter and just tries to give it whatever script the object has:
My class is a native derived class that has no script, so it seems like it's failing to find a script and just instantiating a default base EditorSyntaxHighlighter for me.
However, looking at the source code for the derived GDScriptSyntaxHighlighter class, this class overrides the _create function and just returns a ref to the derived class instead.
This seems to be the solution to get a pure C++ EditorSyntaxHighlighter with no script to work; however, this _create() function is not accessible in GDExtension, so this seems to not currently be possible unless I'm missing another way of doing this.
Steps to reproduce
Create a GDExtension project
Create and register a class that derives from EditorSyntaxHighlighter and overrides the _get_name function
Create and register an EditorPlugin class that registers this syntax highlighter
Observe that the custom named defined in _get_name is not shown when selecting it in editor
Minimal reproduction project
N/A
The text was updated successfully, but these errors were encountered:
This is really a Godot issue - once this is exposed there (or some other way to allow this is added), it should start working with godot-cpp.
I threw together PR godotengine/godot#98929 which exposes the _create() virtual method. I haven't tested it, and since I don't really know this API, I'm not sure this is right approach, but hopefully this could help get things started :-)
Godot version
4.3.stable
godot-cpp version
4.3.stable
System information
Windows 10
Issue description
Context
I'm creating an editor plugin with GDExtension that involves working with .ink files, and I'm trying to create a syntax highlighter for it in pure C++. I'm creating and registering this highlighter class:
However, I cannot get any part of the highlighter to actually work; it shows up as an option in the syntax highlighters list, but it just shows up as Unnamed and doesn't actually provide any highlighting. (I tried putting prints in all three functions and none of them are even called)
What I think is the problem
I looked into the Godot source code for
EditorSyntaxHighlighter
, and it has a method called_create
which is called whenever a highlighter is instantiated. Normally, it instantiates a baseEditorSyntaxHighlighter
and just tries to give it whatever script the object has:My class is a native derived class that has no script, so it seems like it's failing to find a script and just instantiating a default base
EditorSyntaxHighlighter
for me.However, looking at the source code for the derived
GDScriptSyntaxHighlighter
class, this class overrides the_create
function and just returns a ref to the derived class instead.This seems to be the solution to get a pure C++
EditorSyntaxHighlighter
with no script to work; however, this_create()
function is not accessible in GDExtension, so this seems to not currently be possible unless I'm missing another way of doing this.Steps to reproduce
EditorSyntaxHighlighter
and overrides the_get_name
functionEditorPlugin
class that registers this syntax highlighter_get_name
is not shown when selecting it in editorMinimal reproduction project
N/A
The text was updated successfully, but these errors were encountered: