forked from GDQuest/learn-gdscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeEditorEnhancer.gd
171 lines (159 loc) · 2.81 KB
/
CodeEditorEnhancer.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Sets options on a TextEdit for it to be more suitable as
# a text editor.
#
# Sets some colors, and adds keywords used GDScript to the
# highlight list, as well as strings and comments.
class_name CodeEditorEnhancer
extends Node
const COLOR_CLASS := Color(0.666667, 0, 0.729412)
const COLOR_MEMBER := Color(0.14902, 0.776471, 0.968627)
const COLOR_KEYWORD := Color(1, 0.094118, 0.321569)
const COLOR_QUOTES := Color(1, 0.960784, 0.25098)
const COLOR_COMMENTS := Color(0.290196, 0.294118, 0.388235)
const KEYWORDS := [
# Basic keywords.
"var",
"const",
"func",
"signal",
"enum",
"class",
"static",
"extends",
"self",
# Control flow keywords.
"if",
"elif",
"else",
"not",
"and",
"or",
"in",
"for",
"do",
"while",
"match",
"switch",
"case",
"break",
"continue",
"pass",
"return",
"is",
# Godot-specific keywords.
"onready",
"export",
"tool",
"setget",
"breakpoint",
"remote", "sync",
"master", "puppet", "slave",
"remotesync", "mastersync", "puppetsync",
# Primitive data types.
"bool",
"int",
"float",
"null",
"true", "false",
# Global GDScript namespace.
"Color8",
"ColorN",
"abs",
"acos",
"asin",
"assert",
"atan",
"atan2",
"bytes2var",
"cartesian2polar",
"ceil",
"char",
"clamp",
"convert",
"cos",
"cosh",
"db2linear",
"decials",
"dectime",
"deg2rad",
"dict2inst",
"ease",
"expo",
"floor",
"fmod",
"fposmod",
"funcref",
"hash",
"inst2dict",
"instance_from_id",
"inverse_lerp",
"is_inf",
"is_nan",
"len",
"lerp",
"linear2db",
"load",
"log",
"max",
"min",
"nearest_po2",
"parse_json",
"polar2cartesian",
"pow",
"preload",
"print",
"print_stack",
"printerr",
"printraw",
"prints",
"printt",
"rad2deg",
"rand_range",
"rand_seed",
"randf",
"randi",
"randomize",
"range",
"range_lerp",
"round",
"seed",
"sign",
"sin",
"sinh",
"sqrt",
"stepify",
"str",
"str2var",
"tan",
"tanh",
"to_json",
"type_exists",
"typeof",
"validate_json",
"var2bytes",
"var2str",
"weakref",
"wrapf",
"wrapi",
"yield",
"PI", "TAU", "INF", "NAN",
]
# Enhances a TextEdit to better highlight GDScript code.
static func enhance(text_edit: TextEdit) -> void:
text_edit.syntax_highlighting = true
text_edit.show_line_numbers = true
text_edit.draw_tabs = true
text_edit.draw_spaces = true
text_edit.smooth_scrolling = true
text_edit.caret_blink = true
text_edit.wrap_enabled = true
text_edit.add_color_region('"', '"', COLOR_QUOTES)
text_edit.add_color_region("'", "'", COLOR_QUOTES)
text_edit.add_color_region("#", "\n", COLOR_COMMENTS, true)
for classname in ClassDB.get_class_list():
text_edit.add_keyword_color(classname, COLOR_CLASS)
for member in ClassDB.class_get_property_list(classname):
for key in member:
text_edit.add_keyword_color(key, COLOR_MEMBER)
for keyword in KEYWORDS:
text_edit.add_keyword_color(keyword, COLOR_KEYWORD)