@papercraftgames/estragon 0.0.0-stage → 0.1.0-beta.2
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.
- package/CHANGELOG.md +11 -0
- package/LICENSE +20 -0
- package/README.md +28 -2
- package/addons/estragon/compiler/bindable.gd +213 -0
- package/addons/estragon/compiler/bindable.gd.uid +1 -0
- package/addons/estragon/compiler/compiler.gd +24 -0
- package/addons/estragon/compiler/compiler.gd.uid +1 -0
- package/addons/estragon/compiler/composition.gd +51 -0
- package/addons/estragon/compiler/composition.gd.uid +1 -0
- package/addons/estragon/compiler/diagnostic_capture.gd.txt +18 -0
- package/addons/estragon/compiler/emitter.gd +209 -0
- package/addons/estragon/compiler/emitter.gd.uid +1 -0
- package/addons/estragon/compiler/frontend.gd +22 -0
- package/addons/estragon/compiler/frontend.gd.uid +1 -0
- package/addons/estragon/compiler/lexer.gd +78 -0
- package/addons/estragon/compiler/lexer.gd.uid +1 -0
- package/addons/estragon/compiler/model.gd +87 -0
- package/addons/estragon/compiler/model.gd.uid +1 -0
- package/addons/estragon/compiler/native/resolver.gd +200 -0
- package/addons/estragon/compiler/native/resolver.gd.uid +1 -0
- package/addons/estragon/compiler/parser.gd +252 -0
- package/addons/estragon/compiler/parser.gd.uid +1 -0
- package/addons/estragon/compiler/script_validation.gd +80 -0
- package/addons/estragon/compiler/script_validation.gd.uid +1 -0
- package/addons/estragon/compiler/source.gd +65 -0
- package/addons/estragon/compiler/source.gd.uid +1 -0
- package/addons/estragon/compiler/source_map.gd +59 -0
- package/addons/estragon/compiler/source_map.gd.uid +1 -0
- package/addons/estragon/compiler/validator.gd +277 -0
- package/addons/estragon/compiler/validator.gd.uid +1 -0
- package/addons/estragon/editor/buffer_guard.gd +84 -0
- package/addons/estragon/editor/buffer_guard.gd.uid +1 -0
- package/addons/estragon/editor/build_service.gd +252 -0
- package/addons/estragon/editor/build_service.gd.uid +1 -0
- package/addons/estragon/editor/highlighter.gd +116 -0
- package/addons/estragon/editor/highlighter.gd.uid +1 -0
- package/addons/estragon/editor/highlighter_association.gd +80 -0
- package/addons/estragon/editor/highlighter_association.gd.uid +1 -0
- package/addons/estragon/editor/plugin.cfg +7 -0
- package/addons/estragon/editor/plugin.gd +225 -0
- package/addons/estragon/editor/plugin.gd.uid +1 -0
- package/addons/estragon/editor/script_dependencies.gd +45 -0
- package/addons/estragon/editor/script_dependencies.gd.uid +1 -0
- package/addons/estragon/runtime/composition/binding.gd +62 -0
- package/addons/estragon/runtime/composition/binding.gd.uid +1 -0
- package/addons/estragon/runtime/composition/computation.gd +477 -0
- package/addons/estragon/runtime/composition/computation.gd.uid +1 -0
- package/addons/estragon/runtime/composition/element.gd +23 -0
- package/addons/estragon/runtime/composition/element.gd.uid +1 -0
- package/addons/estragon/runtime/composition/profile.gd +21 -0
- package/addons/estragon/runtime/composition/profile.gd.uid +1 -0
- package/addons/estragon/runtime/composition/profile.tres +6 -0
- package/addons/estragon/runtime/composition/state.gd +65 -0
- package/addons/estragon/runtime/composition/state.gd.uid +1 -0
- package/addons/estragon/runtime/composition/state.tres +6 -0
- package/addons/estragon/runtime/node/button.gd +53 -0
- package/addons/estragon/runtime/node/button.gd.uid +1 -0
- package/addons/estragon/runtime/node/component_2d.gd +105 -0
- package/addons/estragon/runtime/node/component_2d.gd.uid +1 -0
- package/addons/estragon/runtime/node/component_3d.gd +91 -0
- package/addons/estragon/runtime/node/component_3d.gd.uid +1 -0
- package/addons/estragon/runtime/node/estragon_2d.gd +32 -0
- package/addons/estragon/runtime/node/estragon_2d.gd.uid +1 -0
- package/addons/estragon/runtime/node/estragon_3d.gd +15 -0
- package/addons/estragon/runtime/node/estragon_3d.gd.uid +1 -0
- package/addons/estragon/runtime/node/hbox.gd +6 -0
- package/addons/estragon/runtime/node/hbox.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/coordinator.gd +145 -0
- package/addons/estragon/runtime/node/internal/coordinator.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/layout_core.gd +115 -0
- package/addons/estragon/runtime/node/internal/layout_core.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/native_bounds.gd +103 -0
- package/addons/estragon/runtime/node/internal/native_bounds.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/pointer_2d.gd +70 -0
- package/addons/estragon/runtime/node/internal/pointer_2d.gd.uid +1 -0
- package/addons/estragon/runtime/node/native_2d.gd +40 -0
- package/addons/estragon/runtime/node/native_2d.gd.uid +1 -0
- package/addons/estragon/runtime/node/native_3d.gd +40 -0
- package/addons/estragon/runtime/node/native_3d.gd.uid +1 -0
- package/addons/estragon/runtime/node/rect.gd +15 -0
- package/addons/estragon/runtime/node/rect.gd.uid +1 -0
- package/addons/estragon/runtime/node/text.gd +66 -0
- package/addons/estragon/runtime/node/text.gd.uid +1 -0
- package/addons/estragon/runtime/node/toggle.gd +23 -0
- package/addons/estragon/runtime/node/toggle.gd.uid +1 -0
- package/addons/estragon/runtime/node/vbox.gd +6 -0
- package/addons/estragon/runtime/node/vbox.gd.uid +1 -0
- package/package.json +31 -4
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Native project build. No editor UI, processes or external tool configuration.
|
|
4
|
+
const Compiler = preload("res://addons/estragon/compiler/compiler.gd")
|
|
5
|
+
const Validation = preload("res://addons/estragon/compiler/script_validation.gd")
|
|
6
|
+
const Dependencies = preload("res://addons/estragon/editor/script_dependencies.gd")
|
|
7
|
+
const CONFIG := "gogo.config.json"
|
|
8
|
+
const EXCLUDED := ["generated", "node_modules", "tests", "vendor"]
|
|
9
|
+
var _project: String
|
|
10
|
+
var _report := {"ok": false, "outputs": [], "changed": [], "diagnostics": [], "isolated_preflight": {"status": "UNTESTED"}}
|
|
11
|
+
var _sources: Dictionary = {}
|
|
12
|
+
var _staging: String
|
|
13
|
+
var _previous_code: Dictionary = {}
|
|
14
|
+
|
|
15
|
+
static func run_build(project: String = "res://") -> Dictionary:
|
|
16
|
+
var build := new()
|
|
17
|
+
build._project = ProjectSettings.globalize_path(project).simplify_path().trim_suffix("/")
|
|
18
|
+
return build._run()
|
|
19
|
+
|
|
20
|
+
func _fail(message: String) -> void:
|
|
21
|
+
_report.diagnostics.append(message)
|
|
22
|
+
|
|
23
|
+
func _safe(path: String) -> bool:
|
|
24
|
+
if not path.begins_with(_project + "/"):
|
|
25
|
+
_fail("Generated/source path escapes the project: " + path)
|
|
26
|
+
return false
|
|
27
|
+
var current := path
|
|
28
|
+
while current != _project:
|
|
29
|
+
var directory := DirAccess.open(current.get_base_dir())
|
|
30
|
+
if directory != null and directory.has_method("is_link") and directory.call("is_link", current.get_file()):
|
|
31
|
+
_fail("Symlinks are not supported in Gogo source/output paths: " + path.trim_prefix(_project + "/"))
|
|
32
|
+
return false
|
|
33
|
+
current = current.get_base_dir()
|
|
34
|
+
return true
|
|
35
|
+
|
|
36
|
+
func _discover() -> void:
|
|
37
|
+
var config_path := _project.path_join(CONFIG)
|
|
38
|
+
if not FileAccess.file_exists(config_path):
|
|
39
|
+
_visit(_project, true)
|
|
40
|
+
return
|
|
41
|
+
if not _safe(config_path): return
|
|
42
|
+
var json := JSON.new()
|
|
43
|
+
if json.parse(FileAccess.get_file_as_string(config_path)) != OK:
|
|
44
|
+
_fail(CONFIG + ": " + json.get_error_message())
|
|
45
|
+
return
|
|
46
|
+
var config: Variant = json.data
|
|
47
|
+
if not config is Dictionary or config.size() != 2 or config.get("version") != 1 or not config.get("source_roots") is Array or config.source_roots.is_empty():
|
|
48
|
+
_fail(CONFIG + ": expected version 1 and nonempty project-relative source_roots only")
|
|
49
|
+
return
|
|
50
|
+
for source_root in config.source_roots:
|
|
51
|
+
if not source_root is String or source_root.is_empty() or source_root.is_absolute_path() or ":" in source_root or "\\" in source_root:
|
|
52
|
+
_fail(CONFIG + ": invalid source root " + str(source_root))
|
|
53
|
+
continue
|
|
54
|
+
var invalid := false
|
|
55
|
+
for part in source_root.split("/"):
|
|
56
|
+
if part.begins_with(".") or part in EXCLUDED: invalid = true
|
|
57
|
+
if invalid:
|
|
58
|
+
_fail(CONFIG + ": invalid source root " + source_root)
|
|
59
|
+
continue
|
|
60
|
+
var path := _project.path_join(source_root).simplify_path()
|
|
61
|
+
if _safe(path): _visit(path)
|
|
62
|
+
|
|
63
|
+
func _visit(path: String, default_root: bool = false) -> void:
|
|
64
|
+
if path != _project and not _safe(path): return
|
|
65
|
+
if FileAccess.file_exists(path):
|
|
66
|
+
if path.ends_with(".gogo"): _sources[path.trim_prefix(_project + "/")] = true
|
|
67
|
+
return
|
|
68
|
+
var directory := DirAccess.open(path)
|
|
69
|
+
if directory == null:
|
|
70
|
+
_fail("Cannot read Gogo source root: " + path.trim_prefix(_project + "/"))
|
|
71
|
+
return
|
|
72
|
+
var entries := Array(directory.get_directories()) + Array(directory.get_files())
|
|
73
|
+
entries.sort()
|
|
74
|
+
for name in entries:
|
|
75
|
+
if name.begins_with(".") or name in EXCLUDED or default_root and name == "addons": continue
|
|
76
|
+
_visit(path.path_join(name))
|
|
77
|
+
|
|
78
|
+
static func output_for(source: String) -> String:
|
|
79
|
+
return source.get_base_dir().path_join("generated").path_join(source.get_file().trim_suffix(".gogo") + ".gd")
|
|
80
|
+
|
|
81
|
+
func _run() -> Dictionary:
|
|
82
|
+
var directory := DirAccess.open(_project)
|
|
83
|
+
_report["symlink_checks"] = {"status": "PASS" if directory != null and directory.has_method("is_link") else "BLOCKED", "reason": "Symlink-free source/output paths are required; older engines cannot introspect links. Lexical path containment remains enforced."}
|
|
84
|
+
_discover()
|
|
85
|
+
if not _report.diagnostics.is_empty(): return _report
|
|
86
|
+
var sources := _sources.keys()
|
|
87
|
+
sources.sort()
|
|
88
|
+
var compiled: Array[Dictionary] = []
|
|
89
|
+
for source in sources:
|
|
90
|
+
var input := FileAccess.open(_project.path_join(source), FileAccess.READ)
|
|
91
|
+
if input == null:
|
|
92
|
+
_fail(source + ": cannot read source (" + error_string(FileAccess.get_open_error()) + ")")
|
|
93
|
+
continue
|
|
94
|
+
var result := Compiler.compile(input.get_as_text(), source)
|
|
95
|
+
if not result.ok:
|
|
96
|
+
for diagnostic in result.diagnostics: _fail(diagnostic.format())
|
|
97
|
+
else: compiled.append({"source": source, "output": output_for(source), "result": result})
|
|
98
|
+
if not _report.diagnostics.is_empty(): return _report
|
|
99
|
+
var writes: Dictionary = {}
|
|
100
|
+
for item in compiled:
|
|
101
|
+
_report.outputs.append(item.output)
|
|
102
|
+
writes[item.output] = item.result.code.to_utf8_buffer()
|
|
103
|
+
writes[item.output + ".map.json"] = item.result.source_map.serialize().to_utf8_buffer()
|
|
104
|
+
for path in writes:
|
|
105
|
+
if not _safe(_project.path_join(path)): return _report
|
|
106
|
+
# Stage new bytes; retain old files by rename so rollback preserves their
|
|
107
|
+
# content and timestamps. No filesystem notifications until commit succeeds.
|
|
108
|
+
var stage := _project.path_join(".godot/estragon/transaction-%d" % get_instance_id())
|
|
109
|
+
_staging = stage
|
|
110
|
+
if not _safe(stage): return _report
|
|
111
|
+
if DirAccess.make_dir_recursive_absolute(stage) != OK:
|
|
112
|
+
_fail("Cannot create native Gogo staging directory")
|
|
113
|
+
return _report
|
|
114
|
+
var operations: Array[Dictionary] = []
|
|
115
|
+
for path in writes:
|
|
116
|
+
var target := _project.path_join(path)
|
|
117
|
+
var exists := FileAccess.file_exists(target)
|
|
118
|
+
var bytes: Variant = writes[path]
|
|
119
|
+
if bytes == null and not exists: continue
|
|
120
|
+
if exists:
|
|
121
|
+
var old_file := FileAccess.open(target, FileAccess.READ)
|
|
122
|
+
if old_file == null:
|
|
123
|
+
_fail("Cannot read existing generated output: " + path)
|
|
124
|
+
_cleanup(operations)
|
|
125
|
+
return _report
|
|
126
|
+
var old_bytes := old_file.get_buffer(old_file.get_length())
|
|
127
|
+
old_file.close()
|
|
128
|
+
if path.ends_with(".gd"): _previous_code[path] = old_bytes.get_string_from_utf8()
|
|
129
|
+
if bytes != null and old_bytes == bytes: continue
|
|
130
|
+
var operation := {"path": path, "target": target, "old": stage.path_join("old-%d" % operations.size()), "new": stage.path_join("new-%d" % operations.size()), "existed": exists, "installed": false, "backed_up": false}
|
|
131
|
+
if not _safe(operation.old) or not _safe(operation.new): return _report
|
|
132
|
+
operations.append(operation)
|
|
133
|
+
if bytes != null:
|
|
134
|
+
var file := FileAccess.open(operation.new, FileAccess.WRITE)
|
|
135
|
+
if file == null:
|
|
136
|
+
_fail("Cannot stage generated output: " + path)
|
|
137
|
+
_cleanup(operations)
|
|
138
|
+
return _report
|
|
139
|
+
file.store_buffer(bytes)
|
|
140
|
+
file.flush()
|
|
141
|
+
var write_error := file.get_error()
|
|
142
|
+
file.close()
|
|
143
|
+
if write_error != OK:
|
|
144
|
+
_fail("Cannot write generated output: " + path)
|
|
145
|
+
_cleanup(operations)
|
|
146
|
+
return _report
|
|
147
|
+
for operation in operations:
|
|
148
|
+
if DirAccess.make_dir_recursive_absolute(operation.target.get_base_dir()) != OK:
|
|
149
|
+
_fail("Cannot create generated directory: " + operation.path)
|
|
150
|
+
break
|
|
151
|
+
if operation.existed:
|
|
152
|
+
if DirAccess.rename_absolute(operation.target, operation.old) != OK:
|
|
153
|
+
_fail("Cannot back up generated output: " + operation.path)
|
|
154
|
+
break
|
|
155
|
+
operation.backed_up = true
|
|
156
|
+
if writes[operation.path] != null:
|
|
157
|
+
if DirAccess.rename_absolute(operation.new, operation.target) != OK:
|
|
158
|
+
_fail("Cannot publish generated output: " + operation.path)
|
|
159
|
+
break
|
|
160
|
+
operation.installed = true
|
|
161
|
+
var cache_state: Array[Dictionary] = []
|
|
162
|
+
var isolated := Validation.supports_isolated_path()
|
|
163
|
+
_report.isolated_preflight = {"status": "UNTESTED" if isolated else "BLOCKED", "reason": "" if isolated else "Unavailable native path API; mandatory transactional actual-path validation used instead"}
|
|
164
|
+
if _report.diagnostics.is_empty():
|
|
165
|
+
compiled = _validation_order(compiled)
|
|
166
|
+
for item in compiled:
|
|
167
|
+
if isolated:
|
|
168
|
+
var checked := Validation.validate(item.result, _resource_path(item.output))
|
|
169
|
+
for diagnostic in checked.diagnostics: _fail(diagnostic.format())
|
|
170
|
+
if not checked.ok:
|
|
171
|
+
_report.isolated_preflight.status = "FAIL"
|
|
172
|
+
break
|
|
173
|
+
# Owner-approved older-engine capability contract: isolated validation is unavailable,
|
|
174
|
+
# never simulated with a cached Script. Native actual-path reload is
|
|
175
|
+
# mandatory, including no-op builds, before this transaction can commit.
|
|
176
|
+
_refresh_cache(item, cache_state)
|
|
177
|
+
if not _report.diagnostics.is_empty(): break
|
|
178
|
+
if not _report.diagnostics.is_empty():
|
|
179
|
+
_rollback(operations)
|
|
180
|
+
_restore_cache(cache_state)
|
|
181
|
+
else:
|
|
182
|
+
if isolated and not compiled.is_empty(): _report.isolated_preflight.status = "PASS"
|
|
183
|
+
for operation in operations: _report.changed.append(operation.path)
|
|
184
|
+
_report.ok = true
|
|
185
|
+
_cleanup(operations)
|
|
186
|
+
return _report
|
|
187
|
+
|
|
188
|
+
func _rollback(operations: Array[Dictionary]) -> void:
|
|
189
|
+
for index in range(operations.size() - 1, -1, -1):
|
|
190
|
+
var operation := operations[index]
|
|
191
|
+
if operation.installed and DirAccess.remove_absolute(operation.target) != OK:
|
|
192
|
+
_fail("Cannot remove rejected output during rollback: " + operation.path)
|
|
193
|
+
if operation.backed_up and DirAccess.rename_absolute(operation.old, operation.target) != OK:
|
|
194
|
+
_fail("Cannot restore output; backup retained at " + operation.old)
|
|
195
|
+
operation.backed_up = false # Preserve the backup for manual recovery.
|
|
196
|
+
|
|
197
|
+
func _cleanup(operations: Array[Dictionary]) -> void:
|
|
198
|
+
for operation in operations:
|
|
199
|
+
DirAccess.remove_absolute(operation.new)
|
|
200
|
+
if operation.backed_up: DirAccess.remove_absolute(operation.old)
|
|
201
|
+
DirAccess.remove_absolute(_staging)
|
|
202
|
+
|
|
203
|
+
func _resource_path(output: String) -> String:
|
|
204
|
+
return "res://" + output if _project == ProjectSettings.globalize_path("res://").trim_suffix("/") else _project.path_join(output)
|
|
205
|
+
|
|
206
|
+
func _refresh_cache(item: Dictionary, state: Array[Dictionary]) -> void:
|
|
207
|
+
# GDScript also has an internal cache not exposed by get_cached_ref().
|
|
208
|
+
# Loading the validated path retrieves its existing Script identity.
|
|
209
|
+
var path := _resource_path(item.output)
|
|
210
|
+
var was_cached := ResourceLoader.has_cached(path)
|
|
211
|
+
var script: GDScript
|
|
212
|
+
if not Validation.supports_isolated_path() and not was_cached and not _previous_code.has(item.output):
|
|
213
|
+
# First publication has no previous resource to preserve. Establish the
|
|
214
|
+
# actual native path inside the transaction and compile exactly once.
|
|
215
|
+
script = GDScript.new()
|
|
216
|
+
script.resource_path = path
|
|
217
|
+
else:
|
|
218
|
+
script = ResourceLoader.load(path, "GDScript") as GDScript
|
|
219
|
+
if script == null:
|
|
220
|
+
_fail("Cannot load validated generated script: " + item.output)
|
|
221
|
+
return
|
|
222
|
+
# Matching source bytes cannot prove which implementation is compiled.
|
|
223
|
+
# Reload the actual Script even on no-op builds; keep_state preserves owners.
|
|
224
|
+
state.append({"script": script, "previous": script.source_code if was_cached else _previous_code.get(item.output), "output": item.output})
|
|
225
|
+
var checked := Validation.reload_script(item.result, script, true)
|
|
226
|
+
for diagnostic in checked.diagnostics: _fail(diagnostic.format())
|
|
227
|
+
|
|
228
|
+
func _restore_cache(state: Array[Dictionary]) -> void:
|
|
229
|
+
for item in state:
|
|
230
|
+
if item.previous == null:
|
|
231
|
+
# Failed first publication must not leave an invalid cached resource.
|
|
232
|
+
item.script.resource_path = ""
|
|
233
|
+
else: item.script.source_code = item.previous
|
|
234
|
+
for item in state:
|
|
235
|
+
if item.previous != null and item.script.reload(true) != OK: _fail("Cannot restore cached script: " + item.output)
|
|
236
|
+
|
|
237
|
+
func _validation_order(compiled: Array[Dictionary]) -> Array[Dictionary]:
|
|
238
|
+
var by_path: Dictionary = {}
|
|
239
|
+
for item in compiled:
|
|
240
|
+
by_path[_resource_path(item.output)] = item
|
|
241
|
+
item.dependencies = Dependencies.paths(item.result.code, _resource_path(item.output))
|
|
242
|
+
var ordered: Array[Dictionary] = []
|
|
243
|
+
var visited: Dictionary = {}
|
|
244
|
+
for item in compiled: _visit_dependencies(item, by_path, visited, ordered)
|
|
245
|
+
return ordered
|
|
246
|
+
|
|
247
|
+
func _visit_dependencies(item: Dictionary, by_path: Dictionary, visited: Dictionary, ordered: Array[Dictionary]) -> void:
|
|
248
|
+
if visited.has(item.output): return # Godot diagnoses illegal dependency cycles.
|
|
249
|
+
visited[item.output] = true
|
|
250
|
+
for path in item.dependencies:
|
|
251
|
+
if by_path.has(path): _visit_dependencies(by_path[path], by_path, visited, ordered)
|
|
252
|
+
ordered.append(item)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://g7sw77j7lv31
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends EditorSyntaxHighlighter
|
|
3
|
+
## Presentation-only lexical coloring. The native compiler owns diagnostics.
|
|
4
|
+
|
|
5
|
+
const CODE := Color("dedede")
|
|
6
|
+
const KEYWORD := Color("ff7085")
|
|
7
|
+
const TAG := Color("8bd5ff")
|
|
8
|
+
const PROPERTY := Color("c6a0f6")
|
|
9
|
+
const STRING := Color("a6da95")
|
|
10
|
+
const COMMENT := Color("808790")
|
|
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
|
+
|
|
15
|
+
|
|
16
|
+
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
|
+
|
|
28
|
+
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:
|
|
39
|
+
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)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://djexf62e7mm5t
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Repair extension association after native tab creation / cached state restore.
|
|
4
|
+
## Kept separate from compilation; no timer, file writes or editor preferences.
|
|
5
|
+
const Highlighter = preload("res://addons/estragon/editor/highlighter.gd")
|
|
6
|
+
const PATH_META := "estragon_gogo_path"
|
|
7
|
+
var _scripts: ScriptEditor
|
|
8
|
+
var _tree: SceneTree
|
|
9
|
+
var _active: bool = false
|
|
10
|
+
var _pending: bool = false
|
|
11
|
+
var _tested_adapter: bool = false
|
|
12
|
+
|
|
13
|
+
func start(interface: EditorInterface) -> void:
|
|
14
|
+
var version := Engine.get_version_info()
|
|
15
|
+
_tested_adapter = version.major == 4 and version.minor >= 0 and version.minor <= 7
|
|
16
|
+
if not _tested_adapter:
|
|
17
|
+
push_warning("Estragon E01: native tab-path adapter is unverified on this engine; UI fallback disabled. See C01 compatibility requirements.")
|
|
18
|
+
_scripts = interface.get_script_editor()
|
|
19
|
+
_tree = _scripts.get_tree()
|
|
20
|
+
_active = true
|
|
21
|
+
_tree.node_added.connect(_node_added)
|
|
22
|
+
_queue_refresh()
|
|
23
|
+
|
|
24
|
+
func stop() -> void:
|
|
25
|
+
_active = false
|
|
26
|
+
_tree.node_added.disconnect(_node_added)
|
|
27
|
+
for editor in _scripts.get_open_script_editors():
|
|
28
|
+
if editor.visibility_changed.is_connected(_queue_refresh):
|
|
29
|
+
editor.visibility_changed.disconnect(_queue_refresh)
|
|
30
|
+
var code := editor.get_base_editor() as TextEdit
|
|
31
|
+
if code != null and code.syntax_highlighter != null and code.syntax_highlighter.get_script() == Highlighter:
|
|
32
|
+
code.syntax_highlighter = EditorSyntaxHighlighter.new()
|
|
33
|
+
|
|
34
|
+
func _node_added(node: Node) -> void:
|
|
35
|
+
if node is ScriptEditorBase and _scripts.is_ancestor_of(node):
|
|
36
|
+
_queue_refresh()
|
|
37
|
+
|
|
38
|
+
func _queue_refresh() -> void:
|
|
39
|
+
if _active and not _pending:
|
|
40
|
+
_pending = true
|
|
41
|
+
_refresh.call_deferred()
|
|
42
|
+
|
|
43
|
+
func _refresh() -> void:
|
|
44
|
+
_pending = false
|
|
45
|
+
if not _active: return
|
|
46
|
+
for editor in _scripts.get_open_script_editors():
|
|
47
|
+
if not editor.visibility_changed.is_connected(_queue_refresh):
|
|
48
|
+
editor.visibility_changed.connect(_queue_refresh)
|
|
49
|
+
var code := editor.get_base_editor() as TextEdit
|
|
50
|
+
if code == null: continue
|
|
51
|
+
var path := _path(editor, code)
|
|
52
|
+
if path.get_extension() != "gogo": continue
|
|
53
|
+
code.set_meta(PATH_META, path)
|
|
54
|
+
if code.syntax_highlighter != null and code.syntax_highlighter.get_script() == Highlighter:
|
|
55
|
+
continue
|
|
56
|
+
# A fresh instance per CodeEdit. Do not add duplicate native menu entries
|
|
57
|
+
# or rewrite the per-file cache; normal editor persistence handles state.
|
|
58
|
+
code.syntax_highlighter = Highlighter.new()
|
|
59
|
+
|
|
60
|
+
func _path(editor: ScriptEditorBase, code: TextEdit, allow_cached: bool = true) -> String:
|
|
61
|
+
if code.syntax_highlighter is EditorSyntaxHighlighter and code.syntax_highlighter.has_method("_get_edited_resource"):
|
|
62
|
+
# Capability-check the bound getter; it is not a published API contract.
|
|
63
|
+
var resource: Resource = code.syntax_highlighter.call("_get_edited_resource") as Resource
|
|
64
|
+
if resource != null: return resource.resource_path
|
|
65
|
+
# A never-associated Plain Text tab has a null highlighter resource, and
|
|
66
|
+
# ScriptEditorBase exposes no resource getter. Stock 4.7's script list
|
|
67
|
+
# supplies exact path tooltips and tab indices (not filtered-list indices).
|
|
68
|
+
# Validate both against the tab's actual parent; never guess from contents
|
|
69
|
+
# or a basename. Pinned-engine adapter covered by real editor regressions.
|
|
70
|
+
if not _tested_adapter: return str(code.get_meta(PATH_META, "")) if allow_cached else ""
|
|
71
|
+
var tabs := editor.get_parent() as TabContainer
|
|
72
|
+
if tabs == null: return ""
|
|
73
|
+
for list in _scripts.find_children("*", "ItemList", true, false):
|
|
74
|
+
for item in range(list.item_count):
|
|
75
|
+
var index: Variant = list.get_item_metadata(item)
|
|
76
|
+
if not (index is int) or index < 0 or index >= tabs.get_tab_count(): continue
|
|
77
|
+
if tabs.get_tab_control(index) != editor: continue
|
|
78
|
+
var path: String = list.get_item_tooltip(item)
|
|
79
|
+
if path.begins_with("res://"): return path
|
|
80
|
+
return str(code.get_meta(PATH_META, "")) if allow_cached else ""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://ckqku6mn18m51
|