Skip to content

Commit 775a22f

Browse files
authored
Merge pull request #958 from Spartan322/4.3-add/gdscript-syntax-highlighter
[4.3] Expose GDScript syntax highlighter to editor plugins
2 parents d79f560 + 3418e39 commit 775a22f

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

modules/gdscript/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def get_doc_classes():
1111
return [
1212
"@GDScript",
1313
"GDScript",
14+
"GDScriptSyntaxHighlighter",
1415
]
1516

1617

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<class name="GDScriptSyntaxHighlighter" inherits="EditorSyntaxHighlighter" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
3+
<brief_description>
4+
A GDScript syntax highlighter that can be used with [TextEdit] and [CodeEdit] nodes.
5+
</brief_description>
6+
<description>
7+
[b]Note:[/b] This class can only be used for editor plugins because it relies on editor settings.
8+
[codeblocks]
9+
[gdscript]
10+
var code_preview = TextEdit.new()
11+
var highlighter = GDScriptSyntaxHighlighter.new()
12+
code_preview.syntax_highlighter = highlighter
13+
[/gdscript]
14+
[csharp]
15+
var codePreview = new TextEdit();
16+
var highlighter = new GDScriptSyntaxHighlighter();
17+
codePreview.SyntaxHighlighter = highlighter;
18+
[/csharp]
19+
[/codeblocks]
20+
</description>
21+
<tutorials>
22+
</tutorials>
23+
</class>

modules/gdscript/register_types.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ void initialize_gdscript_module(ModuleInitializationLevel p_level) {
167167

168168
gdscript_translation_parser_plugin.instantiate();
169169
EditorTranslationParser::get_singleton()->add_parser(gdscript_translation_parser_plugin, EditorTranslationParser::STANDARD);
170+
} else if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
171+
ClassDB::APIType prev_api = ClassDB::get_current_api();
172+
ClassDB::set_current_api(ClassDB::API_EDITOR);
173+
174+
GDREGISTER_CLASS(GDScriptSyntaxHighlighter);
175+
176+
ClassDB::set_current_api(prev_api);
170177
}
171178
#endif // TOOLS_ENABLED
172179
}

0 commit comments

Comments
 (0)