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

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 (94) 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 +122 -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 +71 -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 +134 -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 +90 -0
  62. package/addons/estragon/runtime/node/box.gd.uid +1 -0
  63. package/addons/estragon/runtime/node/button.gd +8 -2
  64. package/addons/estragon/runtime/node/component_2d.gd +128 -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/composition_hosts.gd +159 -0
  70. package/addons/estragon/runtime/node/internal/composition_hosts.gd.uid +1 -0
  71. package/addons/estragon/runtime/node/internal/composition_hosts.tres +6 -0
  72. package/addons/estragon/runtime/node/internal/control_participant.gd +164 -0
  73. package/addons/estragon/runtime/node/internal/control_participant.gd.uid +1 -0
  74. package/addons/estragon/runtime/node/internal/coordinator.gd +79 -27
  75. package/addons/estragon/runtime/node/internal/grid_definition.gd +75 -0
  76. package/addons/estragon/runtime/node/internal/grid_definition.gd.uid +1 -0
  77. package/addons/estragon/runtime/node/internal/layout_core.gd +200 -22
  78. package/addons/estragon/runtime/node/internal/length.gd +93 -0
  79. package/addons/estragon/runtime/node/internal/length.gd.uid +1 -0
  80. package/addons/estragon/runtime/node/internal/stack_contract.gd +21 -0
  81. package/addons/estragon/runtime/node/internal/stack_contract.gd.uid +1 -0
  82. package/addons/estragon/runtime/node/internal/stack_policy.gd +59 -0
  83. package/addons/estragon/runtime/node/internal/stack_policy.gd.uid +1 -0
  84. package/addons/estragon/runtime/node/internal/visual_style_2d.gd +65 -0
  85. package/addons/estragon/runtime/node/internal/visual_style_2d.gd.uid +1 -0
  86. package/addons/estragon/runtime/node/native_2d.gd +5 -5
  87. package/addons/estragon/runtime/node/native_3d.gd +5 -5
  88. package/addons/estragon/runtime/node/rect.gd +2 -1
  89. package/addons/estragon/runtime/node/spacer.gd +4 -0
  90. package/addons/estragon/runtime/node/spacer.gd.uid +1 -0
  91. package/addons/estragon/runtime/node/text.gd +2 -1
  92. package/addons/estragon/runtime/node/toggle.gd +1 -1
  93. package/addons/estragon/runtime/node/vbox.gd +4 -1
  94. package/package.json +1 -1
@@ -0,0 +1,91 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Shared authored source scope. No compiler/editor/tree or authored Script loads.
4
+ const CONFIG := "gogo.config.json"
5
+ const EXCLUDED := ["generated", "node_modules", "tests", "vendor"]
6
+ var root: String
7
+ var sources: Dictionary = {}
8
+ var errors: Array = []
9
+ var overrides: Dictionary = {}
10
+ var discovered := false
11
+ var texts: Dictionary = {}
12
+ func _init(project: String = "res://") -> void:
13
+ root = ProjectSettings.globalize_path(project).simplify_path().trim_suffix("/")
14
+ func _fail(message: String) -> void: errors.append(message)
15
+ func safe(path: String) -> bool:
16
+ if not path.begins_with(root + "/"):
17
+ _fail("Generated/source path escapes the project: " + path)
18
+ return false
19
+ var current := path
20
+ while current != root:
21
+ var directory := DirAccess.open(current.get_base_dir())
22
+ if directory != null and directory.has_method("is_link") and directory.call("is_link", current.get_file()):
23
+ _fail("Symlinks are not supported in Gogo source/output paths: " + path.trim_prefix(root + "/"))
24
+ return false
25
+ current = current.get_base_dir()
26
+ return true
27
+
28
+ func discover() -> void:
29
+ if discovered: return
30
+ discovered = true
31
+ var config_path := root.path_join(CONFIG)
32
+ if not FileAccess.file_exists(config_path):
33
+ visit(root, true)
34
+ return
35
+ if not safe(config_path): return
36
+ var json := JSON.new()
37
+ if json.parse(FileAccess.get_file_as_string(config_path)) != OK:
38
+ _fail(CONFIG + ": " + json.get_error_message())
39
+ return
40
+ var config: Variant = json.data
41
+ 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():
42
+ _fail(CONFIG + ": expected version 1 and nonempty project-relative source_roots only")
43
+ return
44
+ for source_root in config.source_roots:
45
+ 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:
46
+ _fail(CONFIG + ": invalid source root " + str(source_root))
47
+ continue
48
+ var invalid := false
49
+ for part in source_root.split("/"):
50
+ if part.begins_with(".") or part in EXCLUDED: invalid = true
51
+ if invalid:
52
+ _fail(CONFIG + ": invalid source root " + source_root)
53
+ continue
54
+ var path := root.path_join(source_root).simplify_path()
55
+ if safe(path): visit(path)
56
+
57
+ func visit(path: String, default_root: bool = false) -> void:
58
+ if path != root and not safe(path): return
59
+ if FileAccess.file_exists(path):
60
+ if path.ends_with(".gogo"): sources[path.trim_prefix(root + "/")] = true
61
+ return
62
+ var directory := DirAccess.open(path)
63
+ if directory == null:
64
+ _fail("Cannot read Gogo source root: " + path.trim_prefix(root + "/"))
65
+ return
66
+ var entries := Array(directory.get_directories()) + Array(directory.get_files())
67
+ entries.sort()
68
+ for name in entries:
69
+ if name.begins_with(".") or name in EXCLUDED or default_root and name == "addons": continue
70
+ visit(path.path_join(name))
71
+
72
+ static func output_for(source: String) -> String:
73
+ return source.get_base_dir().path_join("generated").path_join(source.get_file().trim_suffix(".gogo") + ".gd")
74
+
75
+
76
+ func resource(source: String) -> String:
77
+ return "res://"+source if root == ProjectSettings.globalize_path("res://").trim_suffix("/") else root.path_join(source)
78
+ func authored(path: String) -> String:
79
+ return ProjectSettings.globalize_path(path).simplify_path().trim_prefix(root+"/")
80
+ func read(source: String) -> String:
81
+ var path := resource(source)
82
+ if overrides.has(path): return overrides[path]
83
+ if not texts.has(source): texts[source] = FileAccess.get_file_as_string(root.path_join(source))
84
+ return texts[source]
85
+ func named(name: String) -> Array:
86
+ discover()
87
+ var found: Array = []
88
+ for source in sources:
89
+ if str(source).get_file().get_basename() == name: found.append(source)
90
+ found.sort()
91
+ return found
@@ -0,0 +1 @@
1
+ uid://bsxatgsbmtf1g
@@ -2,8 +2,8 @@
2
2
  extends RefCounted
3
3
  ## Explicit Godot semantic validation, separate from deterministic source emission.
4
4
  ## Uses native Logger only for the synchronous reload window; never spawns tools.
5
- const Model = preload("res://addons/estragon/compiler/model.gd")
6
- const Compiler = preload("res://addons/estragon/compiler/compiler.gd")
5
+ const Model = preload("model.gd")
6
+ const Compiler = preload("compiler.gd")
7
7
 
8
8
  class Validation extends RefCounted:
9
9
  var generated_script: GDScript
@@ -19,7 +19,7 @@ static func _capture(path: String) -> Object:
19
19
  if not OS.has_method("add_logger") or not OS.has_method("remove_logger"):
20
20
  return null
21
21
  var factory := GDScript.new()
22
- factory.source_code = FileAccess.get_file_as_string("res://addons/estragon/compiler/diagnostic_capture.gd.txt")
22
+ factory.source_code = FileAccess.get_file_as_string((Compiler as Script).resource_path.get_base_dir().path_join("diagnostic_capture.gd.txt"))
23
23
  if factory.reload() != OK: return null # Native errors remain visible.
24
24
  var logger = factory.new()
25
25
  logger.path = path
@@ -1,21 +1,30 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  ## Source ranges use code-point indexes internally and compatible UTF-16 externally.
4
- const Model = preload("res://addons/estragon/compiler/model.gd")
4
+ const Model = preload("model.gd")
5
5
  var text: String
6
6
  var name: String
7
+ var output_path: String
8
+ var project
7
9
  var diagnostics: Array[Model.Diagnostic] = []
8
10
  var _lines: PackedInt32Array = [0]
9
11
  var _utf16: PackedInt32Array = [0]
10
12
 
11
- func _init(value: String, source_name: String = "<source>") -> void:
13
+ func _init(value: String, source_name: String = "<source>", generated_path: String = "", project_sources = null) -> void:
12
14
  text = value
13
15
  name = source_name
16
+ output_path = generated_path
17
+ project = project_sources
14
18
  for index in range(text.length()):
15
19
  _utf16.append(_utf16[-1] + (2 if text.unicode_at(index) > 0xffff else 1))
16
20
  if text[index] == "\n" or text[index] == "\r" and (index + 1 == text.length() or text[index + 1] != "\n"):
17
21
  _lines.append(index + 1)
18
22
 
23
+ func generated_path() -> String:
24
+ if not output_path.is_empty(): return output_path
25
+ if not "/" in name: return "res://Generated.gd"
26
+ return name.get_base_dir().path_join("generated").path_join(name.get_file().get_basename() + ".gd")
27
+
19
28
  func position(index: int) -> Model.Position:
20
29
  index = clampi(index, 0, text.length())
21
30
  var low: int = 0
@@ -63,3 +72,11 @@ func index_at_offset(offset_value: int) -> int:
63
72
 
64
73
  func offset(line: int, column: int = 1) -> int:
65
74
  return mini(_utf16[-1], _utf16[line_start(line)] + maxi(0, column - 1))
75
+
76
+ ## Relative resource references shared by emission and editor starter templates.
77
+ static func relative_path(directory: String, resource_path: String) -> String:
78
+ var origin := ProjectSettings.globalize_path(directory).simplify_path().split("/", false)
79
+ var target := ProjectSettings.globalize_path(resource_path).simplify_path().split("/", false)
80
+ var shared := 0
81
+ while shared < mini(origin.size(), target.size()) and origin[shared] == target[shared]: shared += 1
82
+ return "../".repeat(origin.size() - shared) + "/".join(target.slice(shared))
@@ -1,8 +1,8 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  ## Version-1 range maps, shared by native generation and diagnostic consumers.
4
- const Model = preload("res://addons/estragon/compiler/model.gd")
5
- const Source = preload("res://addons/estragon/compiler/source.gd")
4
+ const Model = preload("model.gd")
5
+ const Source = preload("source.gd")
6
6
  var source: Source
7
7
  var code: String
8
8
  var segments: Array[Dictionary] = []
@@ -53,7 +53,7 @@ func to_dictionary() -> Dictionary:
53
53
  var ranges: Array[Dictionary] = []
54
54
  for segment in segments:
55
55
  ranges.append({"generated": _span(segment.generated), "original": _span(segment.original), "kind": segment.kind})
56
- return {"format": "estragon.gogo.source-map", "version": 1, "sourceName": source.name, "sourceContent": source.text, "segments": ranges}
56
+ return {"format": "estragon.gogo.source-map", "version": 1, "sourceName": source.name, "sourceContent": source.text, "generatedHash": code.sha256_text(), "segments": ranges}
57
57
 
58
58
  func serialize() -> String:
59
59
  return JSON.stringify(to_dictionary()) + "\n"
@@ -1,10 +1,14 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  ## Static native Node property/signal contracts; no SceneTree or editor dependency.
4
- const Model = preload("res://addons/estragon/compiler/model.gd")
5
- const Source = preload("res://addons/estragon/compiler/source.gd")
6
- const Resolver = preload("res://addons/estragon/compiler/native/resolver.gd")
7
- const Lexer = preload("res://addons/estragon/compiler/lexer.gd")
4
+ const Element = preload("../runtime/composition/element.gd")
5
+ const Model = preload("model.gd")
6
+ const Source = preload("source.gd")
7
+ const Resolver = preload("native/resolver.gd")
8
+ const StackContract = preload("../runtime/node/internal/stack_contract.gd")
9
+ const VisualStyle = preload("../runtime/node/internal/visual_style_2d.gd")
10
+ const Length = preload("../runtime/node/internal/length.gd")
11
+ const Lexer = preload("lexer.gd")
8
12
  var file: Source
9
13
  var resolver
10
14
  var current_module
@@ -26,7 +30,7 @@ func _error(message: String, span: Model.Span) -> void:
26
30
  func _component(node: Model.Component) -> void:
27
31
  var resolved: Dictionary = resolver.resolve(node.name, node.name_span)
28
32
  if resolved.is_empty(): return
29
- node.runtime_class = node.name
33
+ node.runtime_class = resolved.get("project_alias",resolved.get("native_alias",node.name))
30
34
  var properties: Dictionary = {}
31
35
  var signals: Dictionary = {}
32
36
  for property in ClassDB.class_get_property_list(resolved.native): properties[property.name] = property
@@ -40,9 +44,16 @@ func _component(node: Model.Component) -> void:
40
44
  script = script.get_base_script()
41
45
  properties.merge(resolved.get("properties",{}),true)
42
46
  signals.merge(resolved.get("signals",{}),true)
47
+ var stack_direction := StackContract.preset(resolved.script)
48
+ if stack_direction.is_empty(): stack_direction = "row"
49
+ for attribute in node.attributes:
50
+ if attribute.name=="direction": stack_direction = str(attribute.value.value) if attribute.value is Model.Literal else StackContract.preset(resolved.script)
43
51
  var seen: Dictionary = {}
44
52
  for attribute in node.attributes:
45
53
  var name := attribute.name
54
+ if VisualStyle.property(name) and VisualStyle.has_api(resolved.script) and not VisualStyle.supported(resolved.script):
55
+ _error("Shared visual styling on Text/Rect/Button is deferred to S02; use the existing local widget properties",attribute.name_span)
56
+ return
46
57
  if seen.has(name):
47
58
  _error("Duplicate Node property or signal " + name, attribute.name_span)
48
59
  return
@@ -74,14 +85,30 @@ func _component(node: Model.Component) -> void:
74
85
  return
75
86
  index = token.span.end.index
76
87
  elif properties.has(name) and name not in ["owner", "script"] and not name.contains("/") and not (int(properties[name].usage) & PROPERTY_USAGE_READ_ONLY):
77
- attribute.type_name = _native_type(properties[name])
88
+ attribute.type_name = "Variant" if Length.registered(resolved.script,name) or VisualStyle.registered(resolved.script,name) else _native_type(properties[name])
78
89
  if attribute.type_name.is_empty():
79
90
  _error("Unsupported Node property metadata: " + name, attribute.name_span)
80
91
  return
81
92
  else:
82
- _error("Unknown, read-only or reserved Node property/signal " + name, attribute.name_span)
93
+ _error("Removed layout API "+name+": use unit dimensions, grow and stretch" if name in ["flex","fill_width","fill_height","viewport_width_scale","viewport_height_scale"] else "Unknown, read-only or reserved Node property/signal " + name, attribute.name_span)
83
94
  return
95
+ if StackContract.registered(resolved.script) and attribute.value is Model.Literal:
96
+ var message := StackContract.error(name,attribute.value.value,stack_direction,StackContract.preset(resolved.script))
97
+ if not message.is_empty():
98
+ _error(message,attribute.value.span)
99
+ return
100
+ var is_color := VisualStyle.registered(resolved.script,name)
101
+ if is_color:
102
+ _color(attribute)
103
+ if not file.diagnostics.is_empty(): return
104
+ var is_length := Length.registered(resolved.script,name)
105
+ if is_length:
106
+ _length(attribute,Length.domain(name))
107
+ if not file.diagnostics.is_empty(): return
84
108
  if attribute.value is Model.Literal:
109
+ if is_length or is_color:
110
+ attribute.value.kind = "string-literal"
111
+ continue
85
112
  if attribute.type_name not in ["String", "StringName"]:
86
113
  _error("Typed Node values require {GDScript expressions}; only strings may be quoted", attribute.value.span)
87
114
  return
@@ -225,15 +252,15 @@ func _child_result(tokens: Array, span) -> void:
225
252
  if begin<tokens.size()-1: _child_result(tokens.slice(begin,tokens.size()-1),span)
226
253
  return
227
254
  # Unknown native expressions (locals, typed helper returns, Array.map) are
228
- # runtime-validated as a complete desired tree. Obvious scalar/live Node
255
+ # runtime-validated as a complete desired tree. Obvious scalar/newly-created Node
229
256
  # leaves fail at their authored span, including conditional alternatives.
230
257
  if not tokens.is_empty():
231
258
  var first: String = tokens[0].text
232
259
  var constructor: bool = tokens.size()>3 and tokens[1].text=="." and tokens[2].text=="new" and tokens[3].text=="(" and _direct_call(tokens,3)
233
260
  var scalar_call: bool = tokens.size()>1 and tokens[1].text=="(" and _direct_call(tokens,1) and first in ["int","float","bool","String","StringName","Vector2","Vector3","Color","Dictionary","NodePath"]
234
- if tokens[0].kind=="identifier" and first not in ["true","false"] and not scalar_call and (not constructor or resolver.aliases.get(first,"")=="res://addons/estragon/runtime/composition/element.gd"):
261
+ if tokens[0].kind=="identifier" and first not in ["true","false"] and not scalar_call and (not constructor or resolver.aliases.get(first,"")==(Element as Script).resource_path):
235
262
  return
236
- _error("GGX children require Element, null or nested Arrays of descriptions; scalars/live Nodes reject",tokens[0].span if not tokens.is_empty() else span)
263
+ _error("GGX children require Element, null, nested Arrays or borrowed scene children; scalars/newly constructed Nodes reject",tokens[0].span if not tokens.is_empty() else span)
237
264
 
238
265
  func _native_type(property: Dictionary) -> String:
239
266
  if property.type == TYPE_OBJECT:
@@ -275,3 +302,37 @@ func _binding(attribute, node, properties: Dictionary, signals: Dictionary) -> v
275
302
  attribute.kind = "binding"
276
303
  attribute.type_name = "Variant"
277
304
  attribute.binding_path = names
305
+
306
+ func _length(attribute, domain: String) -> void:
307
+ var value = attribute.value
308
+ if value is Model.Literal:
309
+ var parsed := Length.parse(value.value,domain)
310
+ if parsed.has("error"): _error(parsed.error,value.span)
311
+ return
312
+ var tokens := _expression_tokens(value)
313
+ var text := ""
314
+ if tokens.size()==1: text = tokens[0].text
315
+ elif tokens.size()==2 and tokens[0].text in ["+","-"] and tokens[1].kind=="number": text = tokens[0].text+tokens[1].text
316
+ if tokens.size()==1 and tokens[0].kind=="string":
317
+ var parsed := Length.parse(text.substr(1,text.length()-2).c_unescape(),domain)
318
+ if parsed.has("error"): _error(parsed.error,value.span)
319
+ elif text in ["true","false","null"]:
320
+ _error("Length requires int, float or a unit string",value.span)
321
+ elif text in ["NAN","INF","-INF","+INF"]:
322
+ _error("Length must be finite",value.span)
323
+ elif text.is_valid_float():
324
+ var parsed := Length.parse(float(text),domain)
325
+ if parsed.has("error"): _error(parsed.error,value.span)
326
+
327
+ func _color(attribute) -> void:
328
+ var value = attribute.value
329
+ if value is Model.Literal:
330
+ var parsed := VisualStyle.parse_color(value.value)
331
+ if parsed.has("error"): _error(parsed.error,value.span)
332
+ return
333
+ var tokens := _expression_tokens(value)
334
+ if tokens.size()==1 and tokens[0].kind=="string":
335
+ var parsed := VisualStyle.parse_color(tokens[0].text.substr(1,tokens[0].text.length()-2).c_unescape())
336
+ if parsed.has("error"): _error(parsed.error,value.span)
337
+ elif tokens.size()==1 and (tokens[0].kind=="number" or tokens[0].text in ["true","false","null","NAN","INF"]):
338
+ _error("Style color requires a native Color or validated hex/transparent string",value.span)
@@ -1,13 +1,15 @@
1
1
  @tool
2
2
  extends RefCounted
3
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")
4
+ const Compiler = preload("../compiler/compiler.gd")
5
+ const Validation = preload("../compiler/script_validation.gd")
6
+ const Dependencies = preload("script_dependencies.gd")
7
+ const ProjectSources = preload("../compiler/project_sources.gd")
7
8
  const CONFIG := "gogo.config.json"
9
+ var _project_sources
8
10
  const EXCLUDED := ["generated", "node_modules", "tests", "vendor"]
9
11
  var _project: String
10
- var _report := {"ok": false, "outputs": [], "changed": [], "diagnostics": [], "isolated_preflight": {"status": "UNTESTED"}}
12
+ var _report := {"ok": false, "outputs": [], "changed": [], "diagnostics": [], "source_diagnostics": [], "isolated_preflight": {"status": "UNTESTED"}}
11
13
  var _sources: Dictionary = {}
12
14
  var _staging: String
13
15
  var _previous_code: Dictionary = {}
@@ -20,63 +22,25 @@ static func run_build(project: String = "res://") -> Dictionary:
20
22
  func _fail(message: String) -> void:
21
23
  _report.diagnostics.append(message)
22
24
 
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
25
+ func _fail_source(diagnostic) -> void:
26
+ _fail(diagnostic.format())
27
+ _report.source_diagnostics.append({"source":diagnostic.source_name,"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})
35
28
 
29
+ func _scope():
30
+ if _project_sources == null: _project_sources = ProjectSources.new(_project)
31
+ return _project_sources
32
+ func _safe(path: String) -> bool:
33
+ var scope = _scope()
34
+ var before: int = scope.errors.size()
35
+ var valid: bool = scope.safe(path)
36
+ _report.diagnostics.append_array(scope.errors.slice(before))
37
+ return valid
36
38
  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")
39
+ var scope = _scope()
40
+ scope.discover()
41
+ _sources = scope.sources
42
+ _report.diagnostics.append_array(scope.errors)
43
+ static func output_for(source: String) -> String: return ProjectSources.output_for(source)
80
44
 
81
45
  func _run() -> Dictionary:
82
46
  var directory := DirAccess.open(_project)
@@ -86,16 +50,22 @@ func _run() -> Dictionary:
86
50
  var sources := _sources.keys()
87
51
  sources.sort()
88
52
  var compiled: Array[Dictionary] = []
53
+ # Metadata resolution and code generation must read the same source snapshot.
89
54
  for source in sources:
90
55
  var input := FileAccess.open(_project.path_join(source), FileAccess.READ)
91
56
  if input == null:
92
57
  _fail(source + ": cannot read source (" + error_string(FileAccess.get_open_error()) + ")")
93
58
  continue
94
- var result := Compiler.compile(input.get_as_text(), source)
59
+ _scope().texts[source] = input.get_as_text()
60
+ if not _report.diagnostics.is_empty(): return _report
61
+ for source in sources:
62
+ var result := Compiler.compile(_scope().read(source), source, _resource_path(output_for(source)), _scope())
95
63
  if not result.ok:
96
- for diagnostic in result.diagnostics: _fail(diagnostic.format())
64
+ for diagnostic in result.diagnostics: _fail_source(diagnostic)
97
65
  else: compiled.append({"source": source, "output": output_for(source), "result": result})
98
66
  if not _report.diagnostics.is_empty(): return _report
67
+ compiled = _validation_order(compiled)
68
+ if not _report.diagnostics.is_empty(): return _report
99
69
  var writes: Dictionary = {}
100
70
  for item in compiled:
101
71
  _report.outputs.append(item.output)
@@ -162,11 +132,10 @@ func _run() -> Dictionary:
162
132
  var isolated := Validation.supports_isolated_path()
163
133
  _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
134
  if _report.diagnostics.is_empty():
165
- compiled = _validation_order(compiled)
166
135
  for item in compiled:
167
136
  if isolated:
168
137
  var checked := Validation.validate(item.result, _resource_path(item.output))
169
- for diagnostic in checked.diagnostics: _fail(diagnostic.format())
138
+ for diagnostic in checked.diagnostics: _fail_source(diagnostic)
170
139
  if not checked.ok:
171
140
  _report.isolated_preflight.status = "FAIL"
172
141
  break
@@ -223,7 +192,7 @@ func _refresh_cache(item: Dictionary, state: Array[Dictionary]) -> void:
223
192
  # Reload the actual Script even on no-op builds; keep_state preserves owners.
224
193
  state.append({"script": script, "previous": script.source_code if was_cached else _previous_code.get(item.output), "output": item.output})
225
194
  var checked := Validation.reload_script(item.result, script, true)
226
- for diagnostic in checked.diagnostics: _fail(diagnostic.format())
195
+ for diagnostic in checked.diagnostics: _fail_source(diagnostic)
227
196
 
228
197
  func _restore_cache(state: Array[Dictionary]) -> void:
229
198
  for item in state:
@@ -238,15 +207,65 @@ func _validation_order(compiled: Array[Dictionary]) -> Array[Dictionary]:
238
207
  var by_path: Dictionary = {}
239
208
  for item in compiled:
240
209
  by_path[_resource_path(item.output)] = item
241
- item.dependencies = Dependencies.paths(item.result.code, _resource_path(item.output))
210
+ item.dependency_locations = {}
211
+ item.dependencies = Dependencies.paths(item.result.code, _resource_path(item.output),item.dependency_locations)
242
212
  var ordered: Array[Dictionary] = []
243
213
  var visited: Dictionary = {}
244
- for item in compiled: _visit_dependencies(item, by_path, visited, ordered)
214
+ for item in compiled: _visit_dependencies(_resource_path(item.output),item,by_path,visited,[],ordered)
245
215
  return ordered
246
216
 
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)
217
+ func _dependency_error(item: Dictionary, path: String, message: String) -> void:
218
+ var generated = item.dependency_locations.get(path)
219
+ var point = item.result.source_map.original_position(generated.line,generated.column) if generated != null else null
220
+ var source = item.result.source_map.source
221
+ source.fail(message,point.index if point != null else 0)
222
+ _fail_source(source.diagnostics[0])
223
+
224
+ func _visit_dependencies(path: String, origin: Dictionary, by_path: Dictionary, visited: Dictionary, chain: Array, ordered: Array[Dictionary]) -> void:
225
+ if not _report.diagnostics.is_empty(): return
226
+ if visited.get(path,0)==1:
227
+ _dependency_error(origin,path,"Cyclic Gogo/source preload dependency: "+" -> ".join(chain+[path]))
228
+ return
229
+ if visited.get(path,0)==2: return
230
+ visited[path] = 1
231
+ var dependencies: PackedStringArray = []
232
+ if by_path.has(path):
233
+ origin = by_path[path]
234
+ dependencies = origin.dependencies
235
+ elif path.get_base_dir().get_file()=="generated" and (FileAccess.file_exists(path+".map.json") or FileAccess.file_exists(path.get_base_dir().get_base_dir().path_join(path.get_file().get_basename()+".gogo"))):
236
+ _dependency_error(origin,path,"Gogo dependency is missing or outside configured source roots: "+path)
237
+ return
238
+ elif path.ends_with(".gd") and FileAccess.file_exists(path) and ProjectSettings.globalize_path(path).begins_with(_project+"/"):
239
+ if not _safe(ProjectSettings.globalize_path(path)): return
240
+ dependencies = Dependencies.paths(FileAccess.get_file_as_string(path),path)
241
+ for dependency in dependencies: _visit_dependencies(dependency,origin,by_path,visited,chain+[path],ordered)
242
+ visited[path] = 2
243
+ if by_path.has(path): ordered.append(by_path[path])
244
+
245
+ ## Same discovery exclusions/containment as builds; no writes or config changes.
246
+ static func creation_check(path: String) -> Dictionary:
247
+ var relative := path.trim_prefix("res://")
248
+ if not path.begins_with("res://") or path.get_extension() != "gogo" or "\\" in relative or ":" in relative:
249
+ return {"ok":false,"message":"Choose a .gogo file beneath res://."}
250
+ for part in relative.split("/"):
251
+ if part.is_empty() or not part.is_valid_filename() or part.begins_with(".") or part in EXCLUDED: return {"ok":false,"message":"This path is invalid or excluded from Gogo compilation. Choose a valid filename in a configured source root."}
252
+ if FileAccess.file_exists(path) or DirAccess.dir_exists_absolute(path):
253
+ return {"ok":false,"message":"A file or directory already exists. New Gogo Component never overwrites existing source; choose another filename."}
254
+ if not DirAccess.dir_exists_absolute(path.get_base_dir()): return {"ok":false,"message":"Create/select an existing project directory first."}
255
+ var check := new()
256
+ check._project = ProjectSettings.globalize_path("res://").trim_suffix("/")
257
+ if not check._safe(ProjectSettings.globalize_path(path)): return {"ok":false,"message":"Unsafe source path: "+str(check._report.diagnostics)}
258
+ if not FileAccess.file_exists("res://"+CONFIG):
259
+ return {"ok":not relative.begins_with("addons/"),"message":"Default discovery excludes the top-level addons directory; choose a project source directory."}
260
+ var json := JSON.new()
261
+ if json.parse(FileAccess.get_file_as_string("res://"+CONFIG)) != OK: return {"ok":false,"message":CONFIG+": "+json.get_error_message()}
262
+ var config: Variant = json.data
263
+ 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():
264
+ return {"ok":false,"message":CONFIG+": expected version 1 and nonempty source_roots."}
265
+ var eligible := false
266
+ for root in config.source_roots:
267
+ if not root is String or root.is_empty() or root.is_absolute_path() or ":" in root or "\\" in root: return {"ok":false,"message":CONFIG+": invalid source root"}
268
+ for part in root.split("/"):
269
+ if part.begins_with(".") or part in EXCLUDED: return {"ok":false,"message":CONFIG+": invalid source root"}
270
+ if relative == root or relative.begins_with(root.trim_suffix("/")+"/"): eligible = true
271
+ return {"ok":eligible,"message":"Choose a location included by gogo.config.json source_roots: "+str(config.source_roots)}
@@ -0,0 +1,37 @@
1
+ @tool
2
+ extends EditorProperty
3
+ const Style = preload("../runtime/node/internal/visual_style_2d.gd")
4
+ var input := LineEdit.new()
5
+ var picker := ColorPickerButton.new()
6
+ var _updating := false
7
+ func _init() -> void:
8
+ var row := HBoxContainer.new()
9
+ input.placeholder_text = "#rrggbb or transparent"
10
+ input.size_flags_horizontal = Control.SIZE_EXPAND_FILL
11
+ row.add_child(input)
12
+ row.add_child(picker)
13
+ add_child(row)
14
+ add_focusable(input)
15
+ input.text_submitted.connect(_submit)
16
+ picker.color_changed.connect(_picked)
17
+ func _submit(text: String) -> void:
18
+ var parsed := Style.parse_color(text)
19
+ if parsed.has("error"):
20
+ input.tooltip_text = parsed.error
21
+ input.modulate = Color(1,0.5,0.5)
22
+ return
23
+ input.modulate = Color.WHITE
24
+ input.tooltip_text = ""
25
+ emit_changed(get_edited_property(),text)
26
+ func _picked(value: Color) -> void:
27
+ if not _updating: emit_changed(get_edited_property(),value)
28
+ func _update_property() -> void:
29
+ _updating = true
30
+ var value = get_edited_object().get(get_edited_property())
31
+ input.text = "#"+value.to_html() if value is Color else str(value)
32
+ var parsed := Style.parse_color(value)
33
+ if not parsed.has("error"):
34
+ picker.color = parsed.color
35
+ input.modulate = Color.WHITE
36
+ input.tooltip_text = ""
37
+ _updating = false
@@ -0,0 +1 @@
1
+ uid://59799a75e034