Expose GDScript syntax highlighter to editor plugins

This commit is contained in:
passivestar 2024-08-18 22:40:24 +04:00
parent 1bd740d18d
commit 3fe644de86
3 changed files with 31 additions and 0 deletions

View file

@ -11,6 +11,7 @@ def get_doc_classes():
return [
"@GDScript",
"GDScript",
"GDScriptSyntaxHighlighter",
]

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="GDScriptSyntaxHighlighter" inherits="EditorSyntaxHighlighter" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A GDScript syntax highlighter that can be used with [TextEdit] and [CodeEdit] nodes.
</brief_description>
<description>
[b]Note:[/b] This class can only be used for editor plugins because it relies on editor settings.
[codeblocks]
[gdscript]
var code_preview = TextEdit.new()
var highlighter = GDScriptSyntaxHighlighter.new()
code_preview.syntax_highlighter = highlighter
[/gdscript]
[csharp]
var codePreview = new TextEdit();
var highlighter = new GDScriptSyntaxHighlighter();
codePreview.SyntaxHighlighter = highlighter;
[/csharp]
[/codeblocks]
</description>
<tutorials>
</tutorials>
</class>

View file

@ -165,6 +165,13 @@ void initialize_gdscript_module(ModuleInitializationLevel p_level) {
gdscript_translation_parser_plugin.instantiate();
EditorTranslationParser::get_singleton()->add_parser(gdscript_translation_parser_plugin, EditorTranslationParser::STANDARD);
} else if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
ClassDB::APIType prev_api = ClassDB::get_current_api();
ClassDB::set_current_api(ClassDB::API_EDITOR);
GDREGISTER_CLASS(GDScriptSyntaxHighlighter);
ClassDB::set_current_api(prev_api);
}
#endif // TOOLS_ENABLED
}