@papercraftgames/estragon 0.1.0-beta.2 → 0.1.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/CHANGELOG.md +7 -3
  2. package/README.md +11 -8
  3. package/addons/estragon/compiler/bindable.gd +3 -3
  4. package/addons/estragon/compiler/compiler.gd +8 -8
  5. package/addons/estragon/compiler/composition.gd +5 -4
  6. package/addons/estragon/compiler/emitter.gd +34 -8
  7. package/addons/estragon/compiler/frontend.gd +8 -8
  8. package/addons/estragon/compiler/lexer.gd +2 -2
  9. package/addons/estragon/compiler/model.gd +2 -0
  10. package/addons/estragon/compiler/native/resolver.gd +125 -29
  11. package/addons/estragon/compiler/parser.gd +3 -3
  12. package/addons/estragon/compiler/project_sources.gd +91 -0
  13. package/addons/estragon/compiler/project_sources.gd.uid +1 -0
  14. package/addons/estragon/compiler/script_validation.gd +3 -3
  15. package/addons/estragon/compiler/source.gd +19 -2
  16. package/addons/estragon/compiler/source_map.gd +3 -3
  17. package/addons/estragon/compiler/validator.gd +74 -10
  18. package/addons/estragon/editor/build_service.gd +91 -72
  19. package/addons/estragon/editor/color_property.gd +37 -0
  20. package/addons/estragon/editor/color_property.gd.uid +1 -0
  21. package/addons/estragon/editor/completion.gd +531 -0
  22. package/addons/estragon/editor/completion.gd.uid +1 -0
  23. package/addons/estragon/editor/completion_edit.gd +7 -0
  24. package/addons/estragon/editor/completion_edit.gd.uid +1 -0
  25. package/addons/estragon/editor/components.gd +20 -0
  26. package/addons/estragon/editor/components.gd.uid +1 -0
  27. package/addons/estragon/editor/creation_menu.gd.txt +14 -0
  28. package/addons/estragon/editor/generated_editors.gd +256 -0
  29. package/addons/estragon/editor/generated_editors.gd.uid +1 -0
  30. package/addons/estragon/editor/highlighter.gd +62 -103
  31. package/addons/estragon/editor/highlighter_association.gd +11 -2
  32. package/addons/estragon/editor/imports.gd +47 -0
  33. package/addons/estragon/editor/imports.gd.uid +1 -0
  34. package/addons/estragon/editor/language_services.gd +288 -0
  35. package/addons/estragon/editor/language_services.gd.uid +1 -0
  36. package/addons/estragon/editor/length_property.gd +22 -0
  37. package/addons/estragon/editor/length_property.gd.uid +1 -0
  38. package/addons/estragon/editor/lexical_context.gd +159 -0
  39. package/addons/estragon/editor/lexical_context.gd.uid +1 -0
  40. package/addons/estragon/editor/navigation.gd +30 -0
  41. package/addons/estragon/editor/navigation.gd.uid +1 -0
  42. package/addons/estragon/editor/new_script.gd +77 -0
  43. package/addons/estragon/editor/new_script.gd.uid +1 -0
  44. package/addons/estragon/editor/plugin.cfg +1 -1
  45. package/addons/estragon/editor/plugin.gd +113 -40
  46. package/addons/estragon/editor/scene_components.gd +267 -0
  47. package/addons/estragon/editor/scene_components.gd.uid +1 -0
  48. package/addons/estragon/editor/scene_inspector.gd +42 -0
  49. package/addons/estragon/editor/scene_inspector.gd.uid +1 -0
  50. package/addons/estragon/editor/script_dependencies.gd +5 -3
  51. package/addons/estragon/runtime/composition/binding.gd +1 -1
  52. package/addons/estragon/runtime/composition/computation.gd +141 -9
  53. package/addons/estragon/runtime/composition/element.gd +3 -1
  54. package/addons/estragon/runtime/composition/layout_host.gd +58 -0
  55. package/addons/estragon/runtime/composition/layout_host.gd.uid +1 -0
  56. package/addons/estragon/runtime/composition/profile.tres +1 -1
  57. package/addons/estragon/runtime/composition/projection.gd +32 -0
  58. package/addons/estragon/runtime/composition/projection.gd.uid +1 -0
  59. package/addons/estragon/runtime/composition/state.gd +13 -2
  60. package/addons/estragon/runtime/composition/state.tres +1 -1
  61. package/addons/estragon/runtime/node/box.gd +57 -0
  62. package/addons/estragon/runtime/node/box.gd.uid +1 -0
  63. package/addons/estragon/runtime/node/button.gd +44 -15
  64. package/addons/estragon/runtime/node/component_2d.gd +167 -24
  65. package/addons/estragon/runtime/node/component_3d.gd +54 -18
  66. package/addons/estragon/runtime/node/estragon_2d.gd +2 -11
  67. package/addons/estragon/runtime/node/estragon_3d.gd +1 -10
  68. package/addons/estragon/runtime/node/hbox.gd +4 -1
  69. package/addons/estragon/runtime/node/internal/component_2d_icon.tres +4 -0
  70. package/addons/estragon/runtime/node/internal/composition_hosts.gd +159 -0
  71. package/addons/estragon/runtime/node/internal/composition_hosts.gd.uid +1 -0
  72. package/addons/estragon/runtime/node/internal/composition_hosts.tres +6 -0
  73. package/addons/estragon/runtime/node/internal/control_participant.gd +164 -0
  74. package/addons/estragon/runtime/node/internal/control_participant.gd.uid +1 -0
  75. package/addons/estragon/runtime/node/internal/coordinator.gd +79 -27
  76. package/addons/estragon/runtime/node/internal/grid_definition.gd +75 -0
  77. package/addons/estragon/runtime/node/internal/grid_definition.gd.uid +1 -0
  78. package/addons/estragon/runtime/node/internal/layout_core.gd +205 -22
  79. package/addons/estragon/runtime/node/internal/length.gd +94 -0
  80. package/addons/estragon/runtime/node/internal/length.gd.uid +1 -0
  81. package/addons/estragon/runtime/node/internal/stack_contract.gd +21 -0
  82. package/addons/estragon/runtime/node/internal/stack_contract.gd.uid +1 -0
  83. package/addons/estragon/runtime/node/internal/stack_policy.gd +59 -0
  84. package/addons/estragon/runtime/node/internal/stack_policy.gd.uid +1 -0
  85. package/addons/estragon/runtime/node/internal/visual_style_2d.gd +75 -0
  86. package/addons/estragon/runtime/node/internal/visual_style_2d.gd.uid +1 -0
  87. package/addons/estragon/runtime/node/native_2d.gd +5 -5
  88. package/addons/estragon/runtime/node/native_3d.gd +5 -5
  89. package/addons/estragon/runtime/node/rect.gd +13 -13
  90. package/addons/estragon/runtime/node/spacer.gd +4 -0
  91. package/addons/estragon/runtime/node/spacer.gd.uid +1 -0
  92. package/addons/estragon/runtime/node/text.gd +5 -3
  93. package/addons/estragon/runtime/node/toggle.gd +18 -5
  94. package/addons/estragon/runtime/node/vbox.gd +4 -1
  95. package/package.json +1 -1
@@ -0,0 +1,288 @@
1
+ @tool
2
+ extends Node
3
+ ## Owns only authenticated Gogo CodeEdit connections and a dedicated gutter.
4
+ signal diagnostics_changed(records, phase)
5
+ signal source_edited(path)
6
+ const Context = preload("lexical_context.gd")
7
+ const Acceptance = preload("completion_edit.gd")
8
+ const Catalog = preload("components.gd")
9
+ const Completion = preload("completion.gd")
10
+ const Source = preload("../compiler/source.gd")
11
+ const Parser = preload("../compiler/parser.gd")
12
+ const Bindable = preload("../compiler/bindable.gd")
13
+ const GUTTER := "Estragon diagnostics"
14
+ var interface: EditorInterface
15
+ var navigation: RefCounted
16
+ var entries: Dictionary = {}
17
+ var _timer: Timer
18
+ var _active := true
19
+ var _generation := 0
20
+ func _init(editor_interface: EditorInterface, navigator: RefCounted) -> void:
21
+ interface = editor_interface
22
+ navigation = navigator
23
+ func _ready() -> void:
24
+ _timer = Timer.new()
25
+ _timer.one_shot = true
26
+ _timer.wait_time = 0.45
27
+ _timer.timeout.connect(_analyze)
28
+ add_child(_timer)
29
+ func attach(editor: ScriptEditorBase, code: CodeEdit, path: String) -> void:
30
+ if not _active: return
31
+ var id := code.get_instance_id()
32
+ if entries.has(id):
33
+ if entries[id].path == path: return
34
+ _detach(id)
35
+ if not path.ends_with(".gogo"): return
36
+ entries[id] = {"code":weakref(code),"editor":weakref(editor),"path":path,"model":Completion.new(),"lexical":Context.new(),"records":[],"pending":true,"marked":[],"line_count":code.get_line_count(),"mutating":false,"snapshot":-1,"script":code.get_script(),"lookup_enabled":code.symbol_lookup_on_click,"lookup":_lookup.bind(id),"caret":_hint.bind(id),"enabled":code.code_completion_enabled,"prefixes":code.code_completion_prefixes,"request":_complete.bind(id),"edit":_changed.bind(id),"gutter":_gutter_clicked.bind(id),"theme":_theme_changed.bind(id),"closing":_closed.bind(id)}
37
+ if code.get_script() == null:
38
+ code.set_script(Acceptance)
39
+ code.set("estragon_accept",_accept.bind(id))
40
+ code.symbol_lookup_on_click = true
41
+ code.symbol_lookup.connect(entries[id].lookup)
42
+ code.caret_changed.connect(entries[id].caret)
43
+ code.code_completion_enabled = true
44
+ code.code_completion_prefixes = PackedStringArray([".","<","/","@","{"])
45
+ code.code_completion_requested.connect(entries[id].request)
46
+ code.text_changed.connect(entries[id].edit)
47
+ code.text_set.connect(entries[id].edit)
48
+ code.gutter_clicked.connect(entries[id].gutter)
49
+ code.theme_changed.connect(entries[id].theme)
50
+ code.tree_exiting.connect(entries[id].closing)
51
+ # Native Text storage compares a removed gutter index to line count.
52
+ # Index zero is valid even for empty/single-line tabs (4.0/4.7 bridge).
53
+ code.add_gutter(0)
54
+ var gutter := 0
55
+ code.set_gutter_name(gutter,GUTTER)
56
+ code.set_gutter_type(gutter,TextEdit.GUTTER_TYPE_STRING)
57
+ code.set_gutter_width(gutter,20)
58
+ code.set_gutter_draw(gutter,true)
59
+ _timer.start()
60
+ func _gutter_index(code: CodeEdit) -> int:
61
+ for index in range(code.get_gutter_count()):
62
+ if code.get_gutter_name(index) == GUTTER: return index
63
+ return -1
64
+ func _detach(id: int) -> void:
65
+ var entry: Dictionary = entries[id]
66
+ var code = entry.code.get_ref()
67
+ if code != null:
68
+ for pair in [["code_completion_requested","request"],["text_changed","edit"],["text_set","edit"],["gutter_clicked","gutter"],["theme_changed","theme"],["tree_exiting","closing"],["symbol_lookup","lookup"],["caret_changed","caret"]]:
69
+ if code.is_connected(pair[0],entry[pair[1]]): code.disconnect(pair[0],entry[pair[1]])
70
+ code.set_code_hint("")
71
+ code.symbol_lookup_on_click = entry.lookup_enabled
72
+ code.cancel_code_completion()
73
+ code.code_completion_enabled = entry.enabled
74
+ code.code_completion_prefixes = entry.prefixes
75
+ var index := _gutter_index(code)
76
+ if index >= 0: code.remove_gutter(index)
77
+ if code.get_script() == Acceptance: code.set_script(entry.script)
78
+ entries.erase(id)
79
+ func _closed(id: int) -> void:
80
+ if entries.has(id): _detach(id)
81
+ func stop() -> void:
82
+ _active = false
83
+ _generation += 1
84
+ if _timer != null: _timer.stop()
85
+ for id in entries.keys(): _detach(id)
86
+ func invalidate() -> void:
87
+ for entry in entries.values(): entry.model.invalidate()
88
+ func _theme_changed(id: int) -> void:
89
+ if not entries.has(id): return
90
+ var code = entries[id].code.get_ref()
91
+ if code != null and code.syntax_highlighter != null: code.syntax_highlighter.update_cache()
92
+ _mark(entries[id])
93
+ func _changed(id: int, request_completion: bool = true) -> void:
94
+ if not _active or not entries.has(id) or entries[id].mutating: return
95
+ var entry: Dictionary = entries[id]
96
+ entry.pending = true
97
+ source_edited.emit(entry.path)
98
+ entry.records = []
99
+ _mark(entry)
100
+ var code = entry.code.get_ref()
101
+ if code != null and code.syntax_highlighter != null: code.syntax_highlighter.clear_highlighting_cache()
102
+ _timer.start()
103
+ if request_completion: _auto_complete.call_deferred(id)
104
+ func _auto_complete(id: int) -> void:
105
+ if not _active or not entries.has(id): return
106
+ var code = entries[id].code.get_ref()
107
+ if code == null or not code.has_focus(): return
108
+ var left: String = code.get_line(code.get_caret_line()).left(code.get_caret_column())
109
+ if not left.is_empty() and (left[-1] in [".","<","/","@","{","("] or left.length() >= 2 and left[-1].is_valid_identifier()): code.request_code_completion(false)
110
+ func _complete(id: int) -> void:
111
+ if not _active or not entries.has(id): return
112
+ var entry: Dictionary = entries[id]
113
+ var code = entry.code.get_ref()
114
+ if code == null: return
115
+ code.cancel_code_completion()
116
+ entry.model.metadata = {}
117
+ for script in interface.get_script_editor().get_open_scripts(): entry.model.metadata[script.resource_path] = script
118
+ for item in Catalog.ITEMS: entry.model.metadata[Catalog.path(item)] = item.script
119
+ entry.model.sources = {}
120
+ for other in entries.values():
121
+ var buffer = other.code.get_ref()
122
+ if buffer != null: entry.model.sources[other.path] = buffer.text
123
+ var options: Array = entry.model.candidates(code.text,entry.path,entry.lexical,code.get_caret_line(),code.get_caret_column())
124
+ entry.snapshot = code.get_version()
125
+ for option in options:
126
+ if code.get_script() != Acceptance and not option.get("imports",[]).is_empty(): continue
127
+ code.add_code_completion_option(option.kind,option.text,option.get("insert",option.text),code.get_theme_color("font_color"),null,option)
128
+ code.update_code_completion_options(true)
129
+ _hint(id)
130
+ func _apply_imports(code: CodeEdit, plan: Dictionary) -> void:
131
+ if plan.text.is_empty(): return
132
+ var row := code.get_caret_line()
133
+ var column := code.get_caret_column()
134
+ code.set_caret_line(plan.row)
135
+ code.set_caret_column(0)
136
+ code.insert_text_at_caret(plan.text)
137
+ code.set_caret_line(row+plan.text.count("\n") if row >= plan.row else row)
138
+ code.set_caret_column(column)
139
+ func _accept(replace: bool, id: int) -> void:
140
+ if not _active or not entries.has(id): return
141
+ var entry: Dictionary = entries[id]
142
+ var code = entry.code.get_ref()
143
+ if code == null: return
144
+ var selected: int = code.get_code_completion_selected_index()
145
+ if selected < 0 or code.get_caret_count() != 1 or entry.snapshot != code.get_version():
146
+ code.cancel_code_completion()
147
+ return
148
+ var selected_option: Dictionary = code.get_code_completion_option(selected)
149
+ var option = selected_option.get("default_value")
150
+ if not option is Dictionary or not option.has("start"):
151
+ code.cancel_code_completion()
152
+ return
153
+ var row: int = option.row
154
+ var start: int = option.start
155
+ var end: int = code.get_caret_column()
156
+ if row != code.get_caret_line() or start < 0 or start > end: code.cancel_code_completion(); return
157
+ var line: String = code.get_line(row)
158
+ var insert: String = option.get("insert",option.text)
159
+ var remaining := insert.substr(end-start)
160
+ if replace and not option.get("path",false):
161
+ while end < line.length() and (line[end].is_valid_identifier() or line[end].is_valid_int()): end += 1
162
+ else:
163
+ var matched := 0
164
+ while end < line.length() and matched < remaining.length() and line[end] == remaining[matched]: end += 1; matched += 1
165
+ if option.get("path",false) and insert[-1] in ['"',"'"] and end < line.length() and line[end] == insert[-1]: end += 1
166
+ var requests: Array = option.get("imports",[])
167
+ var plan: Dictionary = entry.model.import_plan(code.text,entry.path,requests) if not requests.is_empty() else {"row":0,"text":""}
168
+ code.cancel_code_completion()
169
+ entry.mutating = true
170
+ code.begin_complex_operation()
171
+ if code.has_selection():
172
+ code.insert_text_at_caret(insert)
173
+ else:
174
+ code.remove_text(row,start,row,end)
175
+ code.set_caret_line(row)
176
+ code.set_caret_column(start)
177
+ code.insert_text_at_caret(insert)
178
+ _apply_imports(code,plan)
179
+ code.end_complex_operation()
180
+ entry.mutating = false
181
+ _changed(id,false)
182
+ if insert.ends_with("/"): code.request_code_completion(false)
183
+ func add_missing_imports() -> void:
184
+ for id in entries:
185
+ var entry: Dictionary = entries[id]
186
+ var code = entry.code.get_ref()
187
+ if code == null or not code.is_visible_in_tree(): continue
188
+ var plan: Dictionary = entry.model.import_plan(code.text,entry.path)
189
+ entry.mutating = true
190
+ code.begin_complex_operation()
191
+ _apply_imports(code,plan)
192
+ code.end_complex_operation()
193
+ entry.mutating = false
194
+ _changed(id,false)
195
+ return
196
+ func _hint(id: int) -> void:
197
+ if not _active or not entries.has(id) or entries[id].mutating: return
198
+ var entry: Dictionary = entries[id]
199
+ var code = entry.code.get_ref()
200
+ if code == null: return
201
+ entry.hint = entry.model.call_hint(code.text,entry.path,entry.lexical,code.get_caret_line(),code.get_caret_column())
202
+ code.set_code_hint(entry.hint)
203
+ func _lookup(symbol: String, _row: int, _column: int, id: int) -> void:
204
+ if not entries.has(id): return
205
+ var entry: Dictionary = entries[id]
206
+ var code = entry.code.get_ref()
207
+ if code == null: return
208
+ var path: String = entry.model.definition(code.text,entry.path,symbol)
209
+ if not path.is_empty(): navigation.open(path)
210
+ func _analyze() -> void:
211
+ if not _active: return
212
+ var records: Array = []
213
+ for id in entries.keys():
214
+ var entry: Dictionary = entries[id]
215
+ var code = entry.code.get_ref()
216
+ if code == null: entries.erase(id); continue
217
+ if entry.pending:
218
+ entry.pending = false
219
+ var source := Source.new(code.text,entry.path)
220
+ var module = Parser.new(source).parse()
221
+ if module != null: Bindable.new(source).apply(module)
222
+ entry.records = []
223
+ for diagnostic in source.diagnostics:
224
+ entry.records.append({"source":entry.path,"line":diagnostic.span.start.line,"column":diagnostic.span.start.column,"end_line":diagnostic.span.end.line,"end_column":diagnostic.span.end.column,"message":diagnostic.message})
225
+ _mark(entry)
226
+ records.append_array(entry.records)
227
+ diagnostics_changed.emit(records,"Typing feedback — syntax only; save/Play validates semantics")
228
+ func report_build(report: Dictionary) -> void:
229
+ for entry in entries.values():
230
+ entry.records = []
231
+ entry.pending = false
232
+ for item in report.get("source_diagnostics",[]):
233
+ var record: Dictionary = item.duplicate()
234
+ if not record.source.begins_with("res://"): record.source = "res://"+record.source
235
+ for entry in entries.values():
236
+ if entry.path == record.source: entry.records.append(record)
237
+ for entry in entries.values(): _mark(entry)
238
+ func _mark(entry: Dictionary) -> void:
239
+ var code = entry.code.get_ref()
240
+ if code == null: return
241
+ var gutter := _gutter_index(code)
242
+ if gutter < 0: return
243
+ var stale: Array = entry.marked if entry.line_count == code.get_line_count() else range(code.get_line_count())
244
+ for line in stale:
245
+ code.set_line_gutter_text(line,gutter,"")
246
+ code.set_line_gutter_metadata(line,gutter,null)
247
+ code.set_line_gutter_clickable(line,gutter,false)
248
+ entry.marked = []
249
+ entry.line_count = code.get_line_count()
250
+ for record in entry.records:
251
+ var row := clampi(record.line-1,0,code.get_line_count()-1)
252
+ if row not in entry.marked: entry.marked.append(row)
253
+ code.set_line_gutter_text(row,gutter,"!")
254
+ code.set_line_gutter_item_color(row,gutter,code.get_theme_color("error_color","Editor"))
255
+ code.set_line_gutter_metadata(row,gutter,record)
256
+ code.set_line_gutter_clickable(row,gutter,true)
257
+ func _gutter_clicked(line: int, gutter: int, id: int) -> void:
258
+ if not entries.has(id): return
259
+ var code = entries[id].code.get_ref()
260
+ if code != null and _gutter_index(code) == gutter:
261
+ var record = code.get_line_gutter_metadata(line,gutter)
262
+ if record is Dictionary: navigate(record)
263
+ static func scalar_column(text: String, column: int) -> int:
264
+ var units := 0
265
+ var index := 0
266
+ while index < text.length() and units < maxi(0,column-1):
267
+ units += 2 if text.unicode_at(index) > 0xffff else 1
268
+ index += 1
269
+ return index
270
+ func navigate(record: Dictionary) -> void:
271
+ var target := str(record.source)
272
+ if not target.begins_with("res://"): target = "res://"+target
273
+ var generation := _generation
274
+ await navigation.open(target)
275
+ var deadline := Time.get_ticks_msec()+5000
276
+ while _active and generation == _generation and Time.get_ticks_msec() < deadline:
277
+ for entry in entries.values():
278
+ if entry.path != target: continue
279
+ var code = entry.code.get_ref()
280
+ if code == null or not code.is_visible_in_tree(): continue
281
+ var row := clampi(int(record.line)-1,0,code.get_line_count()-1)
282
+ var column := scalar_column(code.get_line(row),int(record.column))
283
+ code.set_caret_line(row)
284
+ code.set_caret_column(column)
285
+ code.set_line_as_center_visible(row)
286
+ code.grab_focus()
287
+ return
288
+ await get_tree().process_frame
@@ -0,0 +1 @@
1
+ uid://c59p2w2nmld
@@ -0,0 +1,22 @@
1
+ @tool
2
+ extends EditorProperty
3
+ const Length = preload("../runtime/node/internal/length.gd")
4
+ var input := LineEdit.new()
5
+ func _init() -> void:
6
+ input.placeholder_text = "200, 50%, 2.5in, auto"
7
+ add_child(input)
8
+ add_focusable(input)
9
+ input.text_submitted.connect(_submit)
10
+ func _submit(text: String) -> void:
11
+ var name := str(get_edited_property())
12
+ var value: Variant = float(text) if text.is_valid_float() else text
13
+ var parsed := Length.parse(value,Length.domain(name,get_edited_object().get_script()))
14
+ if parsed.has("error"):
15
+ input.tooltip_text = parsed.error
16
+ input.modulate = Color(1,0.5,0.5)
17
+ return
18
+ input.modulate = Color.WHITE
19
+ input.tooltip_text = ""
20
+ emit_changed(get_edited_property(),value)
21
+ func _update_property() -> void:
22
+ input.text = str(get_edited_object().get(get_edited_property()))
@@ -0,0 +1 @@
1
+ uid://b36hmqsxprn3d
@@ -0,0 +1,159 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Tolerant, line-cached editor contexts. Shares native identifier/operator and
4
+ ## expression-start rules; never substitutes source or executes authored code.
5
+ const Lexer = preload("../compiler/lexer.gd")
6
+ const Source = preload("../compiler/source.gd")
7
+ const Parser = preload("../compiler/parser.gd")
8
+ const KEYWORDS := ["extends", "class_name", "class", "func", "static", "var", "const", "return", "if", "elif", "else", "for", "in", "while", "await", "signal", "true", "false", "null", "pass", "and", "or", "not", "as", "is", "self", "match", "break", "continue", "assert", "enum", "preload", "load", "super", "get", "set", "when", "void"]
9
+ var lines: PackedStringArray = []
10
+ var records: Array = []
11
+ var scanned_lines := 0
12
+
13
+ func update(text: String) -> void:
14
+ var next := text.split("\n")
15
+ var same := 0
16
+ while same < mini(lines.size(), next.size()) and lines[same] == next[same]: same += 1
17
+ records.resize(mini(same, records.size()))
18
+ lines = next
19
+
20
+ static func initial() -> Dictionary:
21
+ return {"mode":"gd", "quote":"", "comment":false, "tags":[], "islands":[], "frames":[], "operand":true, "depth":0, "declared":[], "tag":"", "closing":false, "name_pending":false}
22
+
23
+ func line(index: int) -> Dictionary:
24
+ while records.size() <= index and records.size() < lines.size():
25
+ var state: Dictionary = initial() if records.is_empty() else records[-1].state.duplicate(true)
26
+ records.append(scan(lines[records.size()], state))
27
+ scanned_lines += 1
28
+ return records[index] if index >= 0 and index < records.size() else {"tokens":[], "state":initial()}
29
+
30
+ func context(index: int, column: int) -> Dictionary:
31
+ if index > 0: line(index - 1)
32
+ var state: Dictionary = initial() if index == 0 else records[index - 1].state.duplicate(true)
33
+ var result := scan(lines[index].left(column), state, false)
34
+ var end: Dictionary = result.state
35
+ end["tokens"] = result.tokens
36
+ end["suppressed"] = end.comment or not end.quote.is_empty()
37
+ return end
38
+
39
+ static func _add(tokens: Array, kind: String, start: int, end: int, word: String, native: bool = true) -> void:
40
+ if end > start: tokens.append({"kind":kind, "start":start, "end":end, "text":word,"native":native})
41
+
42
+ func scan(text: String, state: Dictionary, newline: bool = true) -> Dictionary:
43
+ var tokens: Array = []
44
+ var lexer := Lexer.new(Source.new(text))
45
+ var i := 0
46
+ var previous := ""
47
+ while i < text.length():
48
+ var start := i
49
+ var ch := text[i]
50
+ if state.comment:
51
+ var end := text.find("-->", i)
52
+ i = text.length() if end < 0 else end + 3
53
+ _add(tokens,"comment",start,i,text.substr(start,i-start),false)
54
+ if end >= 0: state.comment = false
55
+ continue
56
+ if not state.quote.is_empty():
57
+ var delimiter: String = state.quote
58
+ while i < text.length():
59
+ if text[i] == "\\": i = mini(text.length(), i + 2)
60
+ elif text.substr(i,delimiter.length()) == delimiter:
61
+ i += delimiter.length()
62
+ state.quote = ""
63
+ break
64
+ else: i += 1
65
+ _add(tokens,"string",start,i,text.substr(start,i-start),state.mode == "gd")
66
+ state.operand = false
67
+ continue
68
+ if ch in [" ","\t","\r"]: i += 1; continue
69
+ if state.mode != "gd" and text.substr(i,4) == "<!--":
70
+ state.comment = true
71
+ i += 4
72
+ _add(tokens,"comment",start,i,"<!--",false)
73
+ continue
74
+ if state.mode == "gd" and ch == "#":
75
+ _add(tokens,"comment",i,text.length(),text.substr(i))
76
+ if not newline: state.comment = true
77
+ i = text.length()
78
+ continue
79
+ if ch in ['"',"'"]:
80
+ state.quote = ch.repeat(3) if text.substr(i,3) == ch.repeat(3) else ch
81
+ i += state.quote.length()
82
+ _add(tokens,"string",start,i,text.substr(start,i-start))
83
+ continue
84
+ if ch == "<" and (state.mode == "body" or state.mode == "gd" and state.operand and (i+1 == text.length() or lexer.identifier_start(lexer.char_at(i+1)))):
85
+ if state.mode == "gd": state.islands.append(state.tags.size())
86
+ state.mode = "tag"
87
+ state.closing = text.substr(i,2) == "</"
88
+ state.tag = ""
89
+ state.name_pending = true
90
+ i += 2 if state.closing else 1
91
+ _add(tokens,"tag",start,i,text.substr(start,i-start),false)
92
+ continue
93
+ if state.mode == "tag":
94
+ if text.substr(i,2) == "/>" or ch == ">":
95
+ var self_closing := text.substr(i,2) == "/>"
96
+ i += 2 if self_closing else 1
97
+ _add(tokens,"tag",start,i,text.substr(start,i-start))
98
+ if state.closing:
99
+ if not state.tags.is_empty(): state.tags.pop_back()
100
+ elif not self_closing: state.tags.append(state.tag)
101
+ if not state.islands.is_empty() and state.tags.size() == state.islands[-1]:
102
+ state.islands.pop_back()
103
+ state.mode = "gd"
104
+ else: state.mode = "body" if not state.tags.is_empty() else "gd"
105
+ state.operand = false
106
+ continue
107
+ if lexer.identifier_start(ch):
108
+ i += 1
109
+ while i < text.length() and (lexer.identifier_part(text[i]) or text[i] in [".",":","-"]): i += 1
110
+ var name := text.substr(start,i-start)
111
+ _add(tokens,"tag" if state.name_pending else "property",start,i,name,false)
112
+ if state.name_pending: state.tag = name; state.name_pending = false
113
+ continue
114
+ if state.mode != "gd" and ch == "{":
115
+ state.frames.append({"mode":state.mode,"depth":state.depth,"tag":state.tag,"closing":state.closing,"name_pending":state.name_pending})
116
+ state.mode = "gd"
117
+ state.depth = 0
118
+ state.operand = true
119
+ _add(tokens,"expression",i,i+1,ch,false)
120
+ i += 1
121
+ continue
122
+ if state.mode == "gd" and ch == "}" and state.depth == 0 and not state.frames.is_empty():
123
+ var frame: Dictionary = state.frames.pop_back()
124
+ state.mode = frame.mode
125
+ state.depth = frame.depth
126
+ state.tag = frame.tag
127
+ state.closing = frame.closing
128
+ state.name_pending = frame.name_pending
129
+ _add(tokens,"expression",i,i+1,ch)
130
+ i += 1
131
+ continue
132
+ if state.mode == "body":
133
+ _add(tokens,"code",i,i+1,ch,false)
134
+ i += 1
135
+ continue
136
+ var token = lexer.next_token(i)
137
+ if token == null: i += 1; continue
138
+ i = token.span.end.index
139
+ var word: String = token.text
140
+ var kind := "symbol"
141
+ if token.kind == "identifier":
142
+ kind = "keyword" if word in KEYWORDS else "code"
143
+ if previous == "@": kind = "annotation"
144
+ elif previous in ["func","signal"] or text.substr(i).strip_edges().begins_with("(") and kind == "code": kind = "function"
145
+ elif kind == "code" and (ClassDB.class_exists(word) or word in state.declared or word in ["int","float","bool","String","Array","Dictionary","Vector2","Vector3","Color","Callable","StringName","NodePath"] or previous in [":","->","extends","class_name","class"]): kind = "type"
146
+ if previous in ["class_name","class"] or previous == "const" and text.substr(i).strip_edges().begins_with("= preload("):
147
+ if word not in state.declared: state.declared.append(word)
148
+ state.operand = word in Parser.OPERANDS
149
+ elif token.kind == "number": kind = "number"; state.operand = false
150
+ else:
151
+ if word in ["(","[","{"]: state.depth += 1
152
+ elif word in [")","]","}"]: state.depth = maxi(0,state.depth-1)
153
+ state.operand = word not in [".",")","]","}"]
154
+ _add(tokens,kind,start,i,word,state.mode == "gd")
155
+ previous = word
156
+ if newline:
157
+ if state.quote.length() == 1: state.quote = ""
158
+ if state.mode == "gd" and state.depth == 0 and state.frames.is_empty(): state.operand = true
159
+ return {"tokens":tokens,"state":state}
@@ -0,0 +1 @@
1
+ uid://8z7w8jx076b
@@ -0,0 +1,30 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## TextFile opening has no public ScriptEditor entry point on 4.0.
4
+ ## Activate only a native FileSystemDock item authenticated by its full path.
5
+ ## No private method, guessed basename/index, or menu injection is used.
6
+ var interface: EditorInterface
7
+ var active := true
8
+ func _init(editor_interface: EditorInterface) -> void: interface = editor_interface
9
+ func stop() -> void: active = false
10
+ func open(path: String) -> void:
11
+ if not active or not path.begins_with("res://") or not FileAccess.file_exists(path): return
12
+ var version := Engine.get_version_info()
13
+ if version.major != 4 or version.minor > 7:
14
+ interface.select_file(path)
15
+ return
16
+ var dock := interface.get_file_system_dock()
17
+ dock.navigate_to_path(path)
18
+ var deadline := Time.get_ticks_msec()+5000
19
+ while active and Time.get_ticks_msec() < deadline:
20
+ for tree in dock.find_children("*","Tree",true,false):
21
+ var selected: TreeItem = tree.get_selected()
22
+ if selected != null and selected.get_metadata(0) is String and selected.get_metadata(0) == path:
23
+ tree.item_activated.emit()
24
+ return
25
+ for list in dock.find_children("*","ItemList",true,false):
26
+ for index in list.get_selected_items():
27
+ if list.get_item_metadata(index) is String and list.get_item_metadata(index) == path:
28
+ list.item_activated.emit(index)
29
+ return
30
+ await dock.get_tree().process_frame
@@ -0,0 +1 @@
1
+ uid://i3yzit6qp5q
@@ -0,0 +1,77 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## User-invoked creation only. Never overwrites source or edits project config.
4
+ const Build = preload("build_service.gd")
5
+ const Source = preload("../compiler/source.gd")
6
+ const Element = preload("../runtime/composition/element.gd")
7
+ var dialog: Variant
8
+ var dimension: OptionButton
9
+ var error: AcceptDialog
10
+ var interface: EditorInterface
11
+ var navigation: RefCounted
12
+ var active := true
13
+ func _init(editor_interface: EditorInterface, navigator: RefCounted) -> void:
14
+ interface = editor_interface
15
+ navigation = navigator
16
+ func start(parent: Node) -> void:
17
+ # 4.0 registers EditorFileDialog abstract; do not reference its unavailable
18
+ # constructor even in a dead branch. Both paths use public native dialogs.
19
+ dialog = ClassDB.instantiate("EditorFileDialog") if ClassDB.can_instantiate("EditorFileDialog") else FileDialog.new()
20
+ dialog.name = "NewGogoComponent"
21
+ if dialog is FileDialog: dialog.mode_overrides_title = false
22
+ dialog.title = "New Gogo Component"
23
+ dialog.access = EditorFileDialog.ACCESS_RESOURCES
24
+ dialog.file_mode = EditorFileDialog.FILE_MODE_SAVE_FILE
25
+ if dialog is EditorFileDialog: dialog.disable_overwrite_warning = true
26
+ # Native save filters append their suffix even to explicit wrong extensions
27
+ # (Bad.txt becomes Bad.txt.gogo). Let the shared validator own suffixes.
28
+ dialog.add_filter("*","Gogo Component (.gogo)")
29
+ dimension = OptionButton.new()
30
+ dimension.name = "GogoTemplate"
31
+ dimension.add_item("Node2D — blank component")
32
+ dimension.add_item("Node3D — blank component")
33
+ dialog.get_vbox().add_child(dimension)
34
+ dialog.file_selected.connect(_selected)
35
+ parent.add_child(dialog)
36
+ error = AcceptDialog.new()
37
+ error.title = "New Gogo Component"
38
+ parent.add_child(error)
39
+ func show_dialog(context_directory: String = "", spatial: bool = false) -> void:
40
+ if not active: return
41
+ var directory := context_directory if not context_directory.is_empty() else interface.get_current_directory()
42
+ if not directory.begins_with("res://") or not DirAccess.dir_exists_absolute(directory): directory = "res://"
43
+ dialog.current_dir = directory
44
+ dialog.current_file = "NewComponent.gogo"
45
+ dimension.select(1 if spatial else 0)
46
+ dialog.popup_centered_ratio(0.65)
47
+ static func template(path: String, spatial: bool) -> String:
48
+ var kind := "Node3D" if spatial else "Node2D"
49
+ var directory := Build.output_for(path).get_base_dir()
50
+ var element := JSON.stringify(Source.relative_path(directory,(Element as Script).resource_path))
51
+ # Ordinary native grouping node: no drawing, layout scope or configuration.
52
+ return "extends "+kind+"\nconst Element = preload("+element+")\n\nfunc build_view() -> Element:\n\treturn <"+kind+" />\n"
53
+ func _selected(path: String) -> void:
54
+ if not active: return
55
+ if path.get_extension().is_empty(): path += ".gogo"
56
+ var check := Build.creation_check(path)
57
+ if not check.ok:
58
+ error.dialog_text = check.message
59
+ error.popup_centered()
60
+ return
61
+ var file := FileAccess.open(path,FileAccess.WRITE)
62
+ if file == null:
63
+ error.dialog_text = "Cannot create "+path+": "+error_string(FileAccess.get_open_error())
64
+ error.popup_centered()
65
+ return
66
+ file.store_string(template(path,dimension.selected == 1))
67
+ file.close()
68
+ interface.get_resource_filesystem().scan()
69
+ _open_after_scan(path)
70
+ func _open_after_scan(path: String) -> void:
71
+ var filesystem := interface.get_resource_filesystem()
72
+ while active and filesystem.is_scanning(): await dialog.get_tree().process_frame
73
+ if active: navigation.open(path)
74
+ func stop() -> void:
75
+ active = false
76
+ if dialog != null: dialog.free(); dialog = null
77
+ if error != null: error.free(); error = null
@@ -0,0 +1 @@
1
+ uid://b96jihgasld
@@ -3,5 +3,5 @@
3
3
  name="Estragon"
4
4
  description="Native Gogo/GGX highlighting, compilation and validation before Play."
5
5
  author="Resist Design"
6
- version="0.1.0-beta.2"
6
+ version="0.1.0-beta.21"
7
7
  script="plugin.gd"