godot-cpp
godot-cpp copied to clipboard
SyntaxHighlighter cache use seems to not be possible
Godot version
4.1.2-stable
godot-cpp version
4.1
System information
Arch linux: 6.3.2-arch1-1
Issue description
The current godot-cpp codegen generates the following definition for _get_line_syntax_highlighting
virtual Dictionary _get_line_syntax_highlighting(int32_t line) const;
In the base engine it is
virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) { return Dictionary(); }
The issue I am running into is I am basing my SyntaxHighlighter implementation on the built in CodeHlighter. It caches color using a HashMap as a private member. But if _get_line_syntax_highlighting is const then we cannot modify the cache as we compute the color.
Steps to reproduce
Generate the header files for the current 4.1 branch
Minimal reproduction project
N/A
I have a dirty workaround for this
Dictionary LuaHighlighter::_get_line_syntax_highlighting(int p_line) const {
return const_cast<LuaHighlighter *>(this)->get_line_syntax_highlighting(p_line);
}
Dictionary LuaHighlighter::get_line_syntax_highlighting(int p_line) {
...
}
Thanks!
I think the fix for this would actually be a change in Godot. It's using the GDVIRTUAL1RC
macro in scene/resources/syntax_highlighter.h
:
GDVIRTUAL1RC(Dictionary, _get_line_syntax_highlighting, int)
That would need to be changed to the GDVIRTUAL1R()
macro (ie with no C
at the end).
That said, changing this would be a source compatibility break: any GDExtensions that currently implement this method would need to update. I think binary compatibility would be fine, though? Given that not probably not a lot of GDExtensions use this, the compatibility breakage may be OK. That would need some wider discussion.