Skip to content

Commit c3d0312

Browse files
committed
First setup
1 parent a8bb7ce commit c3d0312

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

modes/gdscript/icon.png

2.35 KB
Loading

modes/gdscript/mode.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[mode]
2+
3+
name="GDScript"
4+
description="GDScript support for Text Forge"
5+
author="Text Forge Team"
6+
version="1.0.0"
7+
extensions=["gd"]

modes/gdscript/mode.gd

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
extends TextForgeMode
2+
3+
var keyword_colors: Dictionary[Color, Array] = {
4+
Color(1, 0.44, 0.52, 1): ["await", "var", "in", "func", "false", "true", "const", "extends", "class", "class_name", "is", "not", "and", "or"],
5+
Color(1, 0.55, 0.8, 1): ["for", "while", "if", "return", "break", "continue", "else", "elif", "pass"],
6+
Color(1, 0.69, 0.45, 1): ["@", "export", "export_category", "export_color_no_alpha", "export_custom", "export_dir", "export_enum", "export_exp_easing", "export_file", "export_flags", "export_flags_2d_navigation", "export_flags_2d_physics", "export_flags_2d_render", "export_flags_3d_navigation", "export_flags_3d_physics", "export_flags_3d_render", "export_flags_avoidance", "export_global_dir", "export_global_file", "export_group", "export_multiline", "export_node_path", "export_placeholder", "export_range", "export_storage", "export_subgroup", "export_tool_button", "icon", "onready", "rpc", "static_unload", "tool", "warning_ignore", "warning_ignore_restore", "warning_ignore_start"]
7+
}
8+
var code_regions: Array[Array] = [
9+
[Color(1, 0.92, 0.64, 1), '"', '"', false],
10+
[Color(1, 0.92, 0.65, 1), "'", "'", false],
11+
[Color(0.38, 0.76, 0.36, 1), "$", "", true],
12+
[Color(0.38, 0.76, 0.35, 1), '$"', '"', false],
13+
[Color(0.38, 0.76, 0.34, 1), "$'", "'", false],
14+
[Color(0.8, 0.81, 0.82, 0.5), "#", "", true],
15+
[Color(0.6, 0.7, 0.8, 0.8), "##", "", true],
16+
]
17+
18+
func _initialize_mode() -> Error:
19+
_initialize_highlighter()
20+
comment_delimiters.append({
21+
"start_key": "#",
22+
"end_key": "",
23+
"line_only": true,
24+
})
25+
comment_delimiters.append({
26+
"start_key": "##",
27+
"end_key": "",
28+
"line_only": true,
29+
})
30+
string_delimiters.append({
31+
"start_key": '"',
32+
"end_key": '"',
33+
"line_only": false,
34+
})
35+
string_delimiters.append({
36+
"start_key": "'",
37+
"end_key": "'",
38+
"line_only": false,
39+
})
40+
return OK
41+
42+
43+
func _update_code_completion_options(text: String) -> void:
44+
for color in keyword_colors:
45+
for keyword in keyword_colors[color]:
46+
Global.get_editor().add_code_completion_option(CodeEdit.KIND_CLASS, keyword, keyword, color)
47+
48+
49+
func _generate_outline(text: String) -> Array:
50+
var outline := Array()
51+
for l in text.split("\n").size():
52+
var line := text.split("\n")[l]
53+
if line.begins_with("func "):
54+
outline.append([line.substr(5, line.find("(") - 5),l])
55+
return outline
56+
57+
58+
# TODO
59+
func _lint_file(text: String) -> Array[Dictionary]:
60+
return Array([], TYPE_DICTIONARY, "", null)
61+
62+
63+
func _initialize_highlighter() -> void:
64+
syntax_highlighter = CodeHighlighter.new()
65+
syntax_highlighter.number_color = Color(0.63, 1, 0.88, 1)
66+
syntax_highlighter.symbol_color = Color(0.67, 0.79, 1, 1)
67+
syntax_highlighter.function_color = Color(0.35, 0.7, 1, 1)
68+
syntax_highlighter.member_variable_color = Color(0.73, 0.87, 1, 1)
69+
for color in keyword_colors:
70+
for keyword in keyword_colors[color]:
71+
syntax_highlighter.add_keyword_color(keyword, color)
72+
73+
for region in code_regions:
74+
syntax_highlighter.add_color_region(region[1], region[2], region[0], region[3])

0 commit comments

Comments
 (0)