Merge pull request #95764 from passivestar/gdscript-syntax-highlighter

Expose GDScript syntax highlighter to editor plugins
This commit is contained in:
Rémi Verschelde 2024-08-20 10:02:35 +02:00
commit f45421204c
No known key found for this signature in database
GPG key ID: C3336907360768E1
3 changed files with 31 additions and 0 deletions

View file

@ -11,6 +11,7 @@ def get_doc_classes():
return [ return [
"@GDScript", "@GDScript",
"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(); gdscript_translation_parser_plugin.instantiate();
EditorTranslationParser::get_singleton()->add_parser(gdscript_translation_parser_plugin, EditorTranslationParser::STANDARD); 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 #endif // TOOLS_ENABLED
} }