@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,256 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Authenticated compiled views. Native editing/debug navigation stays native;
4
+ ## only verified Estragon output is protected. Recovery precedes replacement.
5
+ const Components = preload("scene_components.gd")
6
+ const Compiler = preload("../compiler/compiler.gd")
7
+ const RECOVERY := "user://estragon/generated-edits"
8
+ var plugin: EditorPlugin
9
+ var interface: EditorInterface
10
+ var navigation: RefCounted
11
+ var association: RefCounted
12
+ var entries: Dictionary = {}
13
+ var panel: MenuButton
14
+ var viewer: AcceptDialog
15
+ var preview: TextEdit
16
+ var location: TextEdit
17
+ var selected := 0
18
+ var active := true
19
+ var mutating := false
20
+ var problem := ""
21
+ var presentation := ""
22
+ var action: Callable
23
+ func _init(owner: EditorPlugin, navigator: RefCounted, adapter: RefCounted) -> void:
24
+ plugin = owner
25
+ interface = owner.get_editor_interface()
26
+ navigation = navigator
27
+ association = adapter
28
+ panel = MenuButton.new()
29
+ panel.name = "GogoGeneratedView"
30
+ plugin.add_control_to_container(EditorPlugin.CONTAINER_TOOLBAR,panel)
31
+ panel.hide()
32
+ interface.get_script_editor().visibility_changed.connect(_present)
33
+ viewer = AcceptDialog.new()
34
+ viewer.title = "Recovered generated edit — copy changes into the Gogo source"
35
+ viewer.min_size = Vector2i(760,460)
36
+ var box := VBoxContainer.new()
37
+ viewer.add_child(box)
38
+ # A wrapping Label can feed an unbounded minimum height back into a
39
+ # native Window before its first layout. Keep the selectable path bounded.
40
+ location = TextEdit.new()
41
+ location.editable = false
42
+ location.wrap_mode = TextEdit.LINE_WRAPPING_BOUNDARY
43
+ location.custom_minimum_size = Vector2(740,110)
44
+ box.add_child(location)
45
+ preview = TextEdit.new()
46
+ preview.editable = false
47
+ preview.custom_minimum_size = Vector2(740,360)
48
+ preview.size_flags_vertical = Control.SIZE_EXPAND_FILL
49
+ box.add_child(preview)
50
+ plugin.add_child(viewer)
51
+ func _verified(path: String) -> String:
52
+ var source := Components.source_path(path)
53
+ if source.is_empty() or not FileAccess.file_exists(source) or not FileAccess.file_exists(path): return ""
54
+ var map = JSON.parse_string(FileAccess.get_file_as_string(path+".map.json"))
55
+ if not map is Dictionary: return ""
56
+ if not map.get("sourceContent") is String or not map.get("segments") is Array: return ""
57
+ var text := FileAccess.get_file_as_string(path)
58
+ if map.has("generatedHash"):
59
+ return source if map.generatedHash == text.sha256_text() else ""
60
+ # Older v1 maps have no output hash. Authenticate by deterministic native
61
+ # emission of their recorded source; never guess from a folder/basename.
62
+ var result := Compiler.compile(map.sourceContent,map.sourceName,path)
63
+ return source if result.ok and result.code == text else ""
64
+ func _display(path: String) -> String:
65
+ return FileAccess.get_file_as_string(path).replace("\r\n","\n")
66
+ func _recovery_prefix(path: String) -> String:
67
+ return (ProjectSettings.globalize_path("res://").simplify_path()+"|"+path).sha256_text()+"-"
68
+ func _latest(path: String) -> String:
69
+ var directory := DirAccess.open(RECOVERY)
70
+ if directory == null: return ""
71
+ var prefix := _recovery_prefix(path)
72
+ var latest := ""
73
+ for name in directory.get_files():
74
+ var file := RECOVERY.path_join(name)
75
+ if name.begins_with(prefix) and name.ends_with(".txt") and (latest.is_empty() or name>latest.get_file()): latest = file
76
+ return latest
77
+ func attach(editor: ScriptEditorBase, code: TextEdit, path: String) -> void:
78
+ if not active or not code is CodeEdit: return
79
+ _present()
80
+ if path.is_empty(): return
81
+ var id := code.get_instance_id()
82
+ if entries.has(id):
83
+ if entries[id].path == path: return
84
+ _detach(id)
85
+ var source := _verified(path)
86
+ if source.is_empty(): return
87
+ var changed := _changed.bind(id)
88
+ var closing := _closed.bind(id)
89
+ entries[id] = {"editor":weakref(editor),"code":weakref(code),"path":path,"source":source,"editable":code.editable,"baseline":_display(path),"recovery":_latest(path),"changed":changed,"closing":closing,"blocked":false}
90
+ code.editable = false
91
+ code.text_changed.connect(changed)
92
+ code.text_set.connect(changed)
93
+ code.tree_exiting.connect(closing)
94
+ # Includes a dirty tab restored before the addon is enabled. Native input
95
+ # is already read-only; no byte is cleared until recovery is verified.
96
+ _changed(id)
97
+ _present()
98
+ func _preserve(entry: Dictionary, text: String) -> bool:
99
+ var file := RECOVERY.path_join(_recovery_prefix(entry.path)+str(int(Time.get_unix_time_from_system()*1000000))+"-"+text.sha256_text()+".txt")
100
+ var error := DirAccess.make_dir_recursive_absolute(ProjectSettings.globalize_path(RECOVERY))
101
+ if error == OK:
102
+ var output := FileAccess.open(file,FileAccess.WRITE)
103
+ if output != null:
104
+ output.store_buffer(text.to_utf8_buffer())
105
+ output.flush()
106
+ error = output.get_error()
107
+ output.close()
108
+ else: error = FileAccess.get_open_error()
109
+ if error != OK or not FileAccess.file_exists(file) or FileAccess.get_file_as_bytes(file) != text.to_utf8_buffer():
110
+ entry.blocked = true
111
+ problem = entry.path+": Cannot preserve edited generated buffer. Save/Play blocked; copy the visible edit before continuing. Recovery: "+ProjectSettings.globalize_path(file)
112
+ return false
113
+ entry.recovery = file
114
+ entry.blocked = false
115
+ return true
116
+ func _changed(id: int) -> void:
117
+ if not active or mutating or not entries.has(id): return
118
+ var entry: Dictionary = entries[id]
119
+ var code = entry.code.get_ref()
120
+ if code == null: return
121
+ if code.text != entry.baseline:
122
+ # Native external reload can already contain a newly authenticated build.
123
+ if code.text == _display(entry.path) and not _verified(entry.path).is_empty(): entry.baseline = code.text
124
+ elif not _preserve(entry,code.text): _present(); return
125
+ else: _replace(entry,entry.baseline)
126
+ _present()
127
+ func _replace(entry: Dictionary, text: String) -> void:
128
+ text = text.replace("\r\n","\n")
129
+ var code = entry.code.get_ref()
130
+ if code == null: return
131
+ mutating = true
132
+ var line: int = code.get_caret_line()
133
+ var column: int = code.get_caret_column()
134
+ var vertical: float = code.scroll_vertical
135
+ var horizontal: int = code.scroll_horizontal
136
+ var breakpoints: PackedInt32Array = code.get_breakpointed_lines()
137
+ if code.text != text:
138
+ # Whole-buffer assignment clears CodeEdit gutters and emits native
139
+ # breakpoint removals. Update line contents instead, retaining native
140
+ # inspection state on existing lines (including unchanged breakpoints).
141
+ var lines := text.split("\n")
142
+ code.begin_complex_operation()
143
+ while code.get_line_count() < lines.size(): code.insert_line_at(code.get_line_count()-1,"")
144
+ while code.get_line_count() > lines.size():
145
+ var last: int = code.get_line_count()-1
146
+ code.remove_text(last-1,code.get_line(last-1).length(),last,code.get_line(last).length())
147
+ for index in range(lines.size()):
148
+ if code.get_line(index) != lines[index]: code.set_line(index,lines[index])
149
+ code.end_complex_operation()
150
+ for marked_line in breakpoints:
151
+ if marked_line < code.get_line_count() and not code.is_line_breakpointed(marked_line): code.set_line_as_breakpoint(marked_line,true)
152
+ code.set_caret_line(line)
153
+ code.set_caret_column(column)
154
+ code.scroll_vertical = vertical
155
+ code.scroll_horizontal = horizontal
156
+ code.tag_saved_version()
157
+ entry.baseline = text
158
+ mutating = false
159
+ func prepare() -> bool:
160
+ problem = ""
161
+ for editor in interface.get_script_editor().get_open_script_editors():
162
+ var code = editor.get_base_editor()
163
+ if code is CodeEdit: attach(editor,code,_path(editor,code))
164
+ for id in entries.keys():
165
+ _changed(id)
166
+ if entries.has(id) and entries[id].blocked:
167
+ if problem.is_empty(): problem = entries[id].path+": Generated edit recovery failed; save/build blocked."
168
+ _present()
169
+ return problem.is_empty()
170
+ func _path(editor: ScriptEditorBase, code: TextEdit) -> String:
171
+ var scripts := interface.get_script_editor()
172
+ var script := scripts.get_current_script()
173
+ if script != null and scripts.get_current_editor() == editor: return script.resource_path
174
+ return association._path(editor,code,false)
175
+ func refresh() -> void:
176
+ for entry in entries.values():
177
+ if not entry.blocked and not _verified(entry.path).is_empty(): _replace(entry,FileAccess.get_file_as_string(entry.path))
178
+ _present()
179
+ func _present() -> void:
180
+ if not active: return
181
+ selected = 0
182
+ var editor := interface.get_script_editor().get_current_editor()
183
+ for id in entries:
184
+ if entries[id].editor.get_ref() == editor: selected = id; break
185
+ panel.visible = selected != 0 and interface.get_script_editor().is_visible_in_tree()
186
+ if selected == 0:
187
+ # A missing source cannot authorize read-only or synchronization. Still
188
+ # explain its map claim on the selected native Script without redirecting.
189
+ var code = editor.get_base_editor() if editor != null else null
190
+ var source := Components.source_path(_path(editor,code)) if code is CodeEdit else ""
191
+ if not source.is_empty() and not FileAccess.file_exists(source):
192
+ panel.visible = interface.get_script_editor().is_visible_in_tree()
193
+ panel.text = "Gogo source missing"
194
+ panel.tooltip_text = "Unverified source association: "+source+". Restore the source; this tab remains editable."
195
+ if presentation != source:
196
+ presentation = source
197
+ var popup := panel.get_popup()
198
+ if action.is_valid() and popup.id_pressed.is_connected(action): popup.id_pressed.disconnect(action)
199
+ action = Callable()
200
+ popup.clear()
201
+ popup.add_item("Gogo source missing — restore "+source)
202
+ popup.set_item_disabled(0,true)
203
+ return
204
+ var entry: Dictionary = entries[selected]
205
+ var exists := FileAccess.file_exists(entry.source)
206
+ panel.text = "Generated: "+entry.source.get_file()
207
+ if not entry.recovery.is_empty(): panel.text = "Generated · edit recovered"
208
+ var status := "Read-only — edit the Gogo source"
209
+ if not exists: status = "Gogo source missing — restore it before editing"
210
+ elif _verified(entry.path).is_empty(): status = "Source map unavailable/changed — inspect only"
211
+ if entry.blocked:
212
+ status = "Recovery failed — Save/Play blocked"
213
+ panel.text = "Recovery failed!"
214
+ panel.tooltip_text = status+"\n"+entry.path+"\nGogo source: "+entry.source
215
+ var signature: String = str(selected)+status+entry.recovery+str(exists)
216
+ if signature == presentation: return
217
+ presentation = signature
218
+ var popup := panel.get_popup()
219
+ if action.is_valid() and popup.id_pressed.is_connected(action): popup.id_pressed.disconnect(action)
220
+ action = _action.bind(entry.source,entry.path,entry.recovery)
221
+ popup.id_pressed.connect(action,CONNECT_DEFERRED)
222
+ popup.clear()
223
+ popup.add_item(status,0)
224
+ popup.set_item_disabled(0,true)
225
+ popup.add_item("Open Gogo Source",1)
226
+ popup.set_item_disabled(1,not exists)
227
+ popup.add_separator()
228
+ popup.add_item("View Recovered Edit"+(" (preserved)" if not entry.recovery.is_empty() else ""),2)
229
+ popup.set_item_disabled(popup.get_item_index(2),entry.recovery.is_empty())
230
+ func _action(id: int, source: String, path: String, recovery: String) -> void:
231
+ if not active: return
232
+ if id == 1 and FileAccess.file_exists(source):
233
+ await navigation.open(source)
234
+ elif id == 2 and FileAccess.file_exists(recovery):
235
+ location.text = "Preserved edit for "+path+"\n"+ProjectSettings.globalize_path(recovery)+"\nOlder recovered versions remain in this directory. Copy intended changes into "+source+"."
236
+ preview.text = FileAccess.get_file_as_string(recovery)
237
+ viewer.popup_centered()
238
+ func _closed(id: int) -> void:
239
+ if entries.has(id): _detach(id)
240
+ func _detach(id: int) -> void:
241
+ var entry: Dictionary = entries[id]
242
+ var code = entry.code.get_ref()
243
+ if code != null:
244
+ for pair in [["text_changed","changed"],["text_set","changed"],["tree_exiting","closing"]]:
245
+ if code.is_connected(pair[0],entry[pair[1]]): code.disconnect(pair[0],entry[pair[1]])
246
+ code.editable = entry.editable
247
+ entries.erase(id)
248
+ func stop() -> void:
249
+ active = false
250
+ for id in entries.keys(): _detach(id)
251
+ interface.get_script_editor().visibility_changed.disconnect(_present)
252
+ if action.is_valid() and panel.get_popup().id_pressed.is_connected(action): panel.get_popup().id_pressed.disconnect(action)
253
+ action = Callable()
254
+ plugin.remove_control_from_container(EditorPlugin.CONTAINER_TOOLBAR,panel)
255
+ panel.free()
256
+ viewer.free()
@@ -0,0 +1 @@
1
+ uid://g6qi8b62ebi5
@@ -1,7 +1,7 @@
1
1
  @tool
2
2
  extends EditorSyntaxHighlighter
3
- ## Presentation-only lexical coloring. The native compiler owns diagnostics.
4
-
3
+ ## Native theme palette + edit-invalidated tolerant line contexts.
4
+ const Context = preload("lexical_context.gd")
5
5
  const CODE := Color("dedede")
6
6
  const KEYWORD := Color("ff7085")
7
7
  const TAG := Color("8bd5ff")
@@ -9,108 +9,67 @@ const PROPERTY := Color("c6a0f6")
9
9
  const STRING := Color("a6da95")
10
10
  const COMMENT := Color("808790")
11
11
  const EXPRESSION := Color("eed49f")
12
- 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"]
13
- var _lines: Array[Dictionary] = []
14
-
12
+ var settings: EditorSettings
13
+ var lexical = Context.new()
14
+ var _version := -1
15
+ var _preview: TextEdit
16
+ var _native: SyntaxHighlighter
17
+ const PALETTE := {"code":["text_color",CODE], "keyword":["keyword_color",KEYWORD], "tag":["user_type_color",TAG], "property":["member_variable_color",PROPERTY], "string":["string_color",STRING], "comment":["comment_color",COMMENT], "expression":["symbol_color",EXPRESSION], "symbol":["symbol_color",EXPRESSION], "number":["number_color",Color("a1ffe0")], "type":["base_type_color",TAG], "function":["function_color",Color("57b3ff")], "annotation":["annotation_color",KEYWORD]}
15
18
 
19
+ func _init(editor_settings: EditorSettings = null) -> void:
20
+ settings = editor_settings
16
21
  func _create() -> EditorSyntaxHighlighter:
17
- return load("res://addons/estragon/editor/highlighter.gd").new()
18
-
19
-
20
- func _get_name() -> String:
21
- return "Gogo"
22
-
23
-
24
- func _get_supported_languages() -> PackedStringArray:
25
- return PackedStringArray(["gogo"])
26
-
27
-
22
+ return get_script().new(settings)
23
+ func _get_name() -> String: return "Gogo"
24
+ func _get_supported_languages() -> PackedStringArray: return PackedStringArray(["gogo"])
28
25
  func _clear_highlighting_cache() -> void:
29
- _lines.clear()
30
-
31
-
32
- func _get_line_syntax_highlighting(line: int) -> Dictionary:
33
- if _lines.is_empty():
34
- _scan()
35
- return _lines[line] if line < _lines.size() else {}
36
-
37
-
38
- func _scan() -> void:
26
+ _version = -1
27
+ if _native != null: _native.update_cache()
28
+ func color(kind: String) -> Color:
29
+ var entry: Array = PALETTE.get(kind,PALETTE.code)
30
+ var key: String = "text_editor/theme/highlighting/"+entry[0]
31
+ return settings.get_setting(key) if settings != null and settings.has_setting(key) else entry[1]
32
+ func _notification(what: int) -> void:
33
+ if what == NOTIFICATION_PREDELETE and is_instance_valid(_preview):
34
+ _preview.free()
35
+ _preview = null
36
+ func uses_native() -> bool: return _native != null
37
+ func _ensure_native() -> void:
38
+ if _native != null or not Engine.is_editor_hint(): return
39
+ if ClassDB.class_exists("GDScriptSyntaxHighlighter") and ClassDB.can_instantiate("GDScriptSyntaxHighlighter"):
40
+ _native = ClassDB.instantiate("GDScriptSyntaxHighlighter")
41
+ _preview = TextEdit.new()
42
+ _preview.syntax_highlighter = _native
43
+ func _native_color(colors: Dictionary, column: int) -> Color:
44
+ var result := color("code")
45
+ var keys := colors.keys()
46
+ keys.sort()
47
+ for key in keys:
48
+ if key > column: break
49
+ result = colors[key].color
50
+ return result
51
+ func _get_line_syntax_highlighting(index: int) -> Dictionary:
39
52
  var edit := get_text_edit()
40
- if edit == null:
41
- return
42
- var quote := ""
43
- var xml_comment := false
44
- var tag_depths: Array[int] = []
45
- var braces: int = 0
46
- for line_index in range(edit.get_line_count()):
47
- var text := edit.get_line(line_index)
48
- var colors: Dictionary = {0: {"color": CODE}}
49
- var i: int = 0
50
- while i < text.length():
51
- if xml_comment:
52
- colors[i] = {"color": COMMENT}
53
- var end := text.find("-->", i)
54
- if end < 0:
55
- break
56
- i = end + 3
57
- xml_comment = false
58
- colors[i] = {"color": CODE}
59
- continue
60
- if not quote.is_empty():
61
- colors[i] = {"color": STRING}
62
- while i < text.length():
63
- if text[i] == "\\":
64
- i += 2
65
- continue
66
- if text.substr(i, quote.length()) == quote:
67
- i += quote.length()
68
- quote = ""
69
- break
70
- i += 1
71
- colors[i] = {"color": CODE}
72
- continue
73
- var character := text[i]
74
- if text.substr(i, 4) == "<!--":
75
- xml_comment = true
76
- continue
77
- if character == "#" and (tag_depths.is_empty() or braces > tag_depths[-1]):
78
- colors[i] = {"color": COMMENT}
79
- break
80
- if character == '"' or character == "'":
81
- quote = character.repeat(3) if text.substr(i, 3) == character.repeat(3) else character
82
- colors[i] = {"color": STRING}
83
- i += quote.length()
84
- continue
85
- if character == "<" and i + 1 < text.length() and (text[i + 1] == "/" or text[i + 1].to_upper() == text[i + 1] and text[i + 1].to_lower() != text[i + 1]):
86
- tag_depths.append(braces)
87
- var end := i + 1
88
- while end < text.length() and text[end] not in [" ", "\t", ">"]:
89
- end += 1
90
- colors[i] = {"color": TAG}
91
- i = end
92
- colors[i] = {"color": CODE}
93
- continue
94
- if character == ">" and not tag_depths.is_empty() and braces == tag_depths[-1]:
95
- colors[i] = {"color": TAG}
96
- tag_depths.pop_back()
97
- colors[i + 1] = {"color": CODE}
98
- if character == "{" or character == "}":
99
- braces += 1 if character == "{" else -1
100
- braces = maxi(0, braces)
101
- colors[i] = {"color": EXPRESSION}
102
- colors[i + 1] = {"color": CODE}
103
- if character.is_valid_identifier() and not character.is_valid_int():
104
- var end := i + 1
105
- while end < text.length() and (text[end].is_valid_identifier() or text[end].is_valid_int()):
106
- end += 1
107
- var word := text.substr(i, end - i)
108
- if word in KEYWORDS or not tag_depths.is_empty() and braces == tag_depths[-1]:
109
- colors[i] = {"color": KEYWORD if word in KEYWORDS else PROPERTY}
110
- colors[end] = {"color": CODE}
111
- i = end
112
- continue
113
- i += 1
114
- if quote.length() == 1:
115
- quote = ""
116
- _lines.append(colors)
53
+ if edit == null: return {}
54
+ _ensure_native()
55
+ if _version != edit.get_version():
56
+ lexical.update(edit.text)
57
+ _version = edit.get_version()
58
+ if _native != null:
59
+ var masked: Array = []
60
+ for row in range(lexical.lines.size()):
61
+ var line: String = lexical.lines[row]
62
+ # Keep all code-point columns/newlines; markup cannot poison native
63
+ # GDScript string/comment state across a GGX island. No compilation.
64
+ for token in lexical.line(row).tokens:
65
+ if not token.native: line = line.left(token.start)+" ".repeat(token.end-token.start)+line.substr(token.end)
66
+ masked.append(line)
67
+ _preview.text = "\n".join(masked)
68
+ _native.update_cache()
69
+ var native_colors: Dictionary = _native.get_line_syntax_highlighting(index) if _native != null else {}
70
+ var result: Dictionary = native_colors.duplicate(true) if _native != null else {0:{"color":color("code")}}
71
+ for token in lexical.line(index).tokens:
72
+ if _native != null and token.native and not (token.kind == "annotation" and token.text == "bindable"): continue
73
+ result[token.start] = {"color":color(token.kind)}
74
+ result[token.end] = {"color":_native_color(native_colors,token.end) if _native != null else color("code")}
75
+ return result
@@ -2,7 +2,9 @@
2
2
  extends RefCounted
3
3
  ## Repair extension association after native tab creation / cached state restore.
4
4
  ## Kept separate from compilation; no timer, file writes or editor preferences.
5
- const Highlighter = preload("res://addons/estragon/editor/highlighter.gd")
5
+ const Highlighter = preload("highlighter.gd")
6
+ signal associated(editor, code, path)
7
+ var _settings: EditorSettings
6
8
  const PATH_META := "estragon_gogo_path"
7
9
  var _scripts: ScriptEditor
8
10
  var _tree: SceneTree
@@ -11,6 +13,7 @@ var _pending: bool = false
11
13
  var _tested_adapter: bool = false
12
14
 
13
15
  func start(interface: EditorInterface) -> void:
16
+ _settings = interface.get_editor_settings()
14
17
  var version := Engine.get_version_info()
15
18
  _tested_adapter = version.major == 4 and version.minor >= 0 and version.minor <= 7
16
19
  if not _tested_adapter:
@@ -49,13 +52,19 @@ func _refresh() -> void:
49
52
  var code := editor.get_base_editor() as TextEdit
50
53
  if code == null: continue
51
54
  var path := _path(editor, code)
55
+ associated.emit(editor,code,path)
52
56
  if path.get_extension() != "gogo": continue
53
57
  code.set_meta(PATH_META, path)
54
58
  if code.syntax_highlighter != null and code.syntax_highlighter.get_script() == Highlighter:
59
+ # 4.0 clones the script directly; its native _create is not a
60
+ # script virtual, so constructor arguments are not preserved.
61
+ if code.syntax_highlighter.settings != _settings:
62
+ code.syntax_highlighter.settings = _settings
63
+ code.syntax_highlighter.update_cache()
55
64
  continue
56
65
  # A fresh instance per CodeEdit. Do not add duplicate native menu entries
57
66
  # or rewrite the per-file cache; normal editor persistence handles state.
58
- code.syntax_highlighter = Highlighter.new()
67
+ code.syntax_highlighter = Highlighter.new(_settings)
59
68
 
60
69
  func _path(editor: ScriptEditorBase, code: TextEdit, allow_cached: bool = true) -> String:
61
70
  if code.syntax_highlighter is EditorSyntaxHighlighter and code.syntax_highlighter.has_method("_get_edited_resource"):
@@ -0,0 +1,47 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Pure bounded edit plans. No saves, generated writes or authored Script loads.
4
+ const Build = preload("build_service.gd")
5
+ const Source = preload("../compiler/source.gd")
6
+ const Catalog = preload("components.gd")
7
+ static func occupied(name: String, resource: String, symbols: Dictionary) -> bool:
8
+ if symbols.has(name) or ClassDB.class_exists(name): return true
9
+ for entry in ProjectSettings.get_global_class_list():
10
+ if str(entry["class"]) == name and str(entry.path) != resource and FileAccess.file_exists(str(entry.path)): return true
11
+ return false
12
+ static func alias_for(item: Dictionary, symbols: Dictionary, aliases: Dictionary) -> String:
13
+ for name in aliases:
14
+ if aliases[name] == Catalog.path(item): return name
15
+ var name: String = item.alias
16
+ if occupied(name,Catalog.path(item),symbols): name = item.canonical
17
+ var stem := name
18
+ var suffix := 2
19
+ while occupied(name,Catalog.path(item),symbols):
20
+ name = stem+str(suffix)
21
+ suffix += 1
22
+ return name
23
+ static func declaration(name: String, resource: String, source: String) -> String:
24
+ return "const "+name+" = preload("+JSON.stringify(Source.relative_path(Build.output_for(source).get_base_dir(),resource))+")\n"
25
+ static func plan(text: String, source: String, requested: Array, symbols: Dictionary, aliases: Dictionary, tokens: Array) -> Dictionary:
26
+ var declarations: Array = []
27
+ var names: Dictionary = aliases.duplicate()
28
+ for request in requested:
29
+ if names.get(request.alias) == request.path: continue
30
+ # Caller resolves collisions explicitly; never replace an authored name.
31
+ if occupied(request.alias,request.path,symbols) or names.has(request.alias): continue
32
+ declarations.append(declaration(request.alias,request.path,source))
33
+ names[request.alias] = request.path
34
+ # A first build_view()->Element needs the explicit composition resource too.
35
+ if not occupied("Element",Catalog.path(Catalog.named("Element")),symbols) and not names.has("Element"):
36
+ for index in range(tokens.size()-1):
37
+ if tokens[index].text == "->" and tokens[index+1].text == "Element":
38
+ declarations.push_front(declaration("Element",Catalog.path(Catalog.named("Element")),source))
39
+ break
40
+ var row := 0
41
+ for token in tokens:
42
+ if token.indent == 0 and token.text in ["extends","class_name"]: row = maxi(row,int(token.row)+1)
43
+ # Preserve file-level tool/icon annotations when no extends header exists yet.
44
+ if row == 0:
45
+ var lines := text.split("\n")
46
+ while row < lines.size() and (lines[row].strip_edges().is_empty() or lines[row].strip_edges().begins_with("#") or lines[row].begins_with("@tool") or lines[row].begins_with("@icon")): row += 1
47
+ return {"row":mini(row,text.count("\n")),"text":"".join(declarations)}
@@ -0,0 +1 @@
1
+ uid://ckzxzc2w16s