@papercraftgames/estragon 0.1.0-beta.3 → 0.1.0-beta.5

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 (51) 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 +18 -7
  7. package/addons/estragon/compiler/frontend.gd +8 -8
  8. package/addons/estragon/compiler/lexer.gd +2 -2
  9. package/addons/estragon/compiler/native/resolver.gd +7 -7
  10. package/addons/estragon/compiler/parser.gd +3 -3
  11. package/addons/estragon/compiler/script_validation.gd +3 -3
  12. package/addons/estragon/compiler/source.gd +17 -2
  13. package/addons/estragon/compiler/source_map.gd +2 -2
  14. package/addons/estragon/compiler/validator.gd +6 -5
  15. package/addons/estragon/editor/build_service.gd +40 -8
  16. package/addons/estragon/editor/completion.gd +205 -0
  17. package/addons/estragon/editor/completion.gd.uid +1 -0
  18. package/addons/estragon/editor/highlighter.gd +26 -104
  19. package/addons/estragon/editor/highlighter_association.gd +11 -2
  20. package/addons/estragon/editor/language_services.gd +186 -0
  21. package/addons/estragon/editor/language_services.gd.uid +1 -0
  22. package/addons/estragon/editor/lexical_context.gd +159 -0
  23. package/addons/estragon/editor/lexical_context.gd.uid +1 -0
  24. package/addons/estragon/editor/navigation.gd +30 -0
  25. package/addons/estragon/editor/navigation.gd.uid +1 -0
  26. package/addons/estragon/editor/new_script.gd +88 -0
  27. package/addons/estragon/editor/new_script.gd.uid +1 -0
  28. package/addons/estragon/editor/plugin.cfg +1 -1
  29. package/addons/estragon/editor/plugin.gd +55 -8
  30. package/addons/estragon/editor/script_dependencies.gd +2 -2
  31. package/addons/estragon/runtime/composition/binding.gd +1 -1
  32. package/addons/estragon/runtime/composition/computation.gd +3 -3
  33. package/addons/estragon/runtime/composition/element.gd +1 -1
  34. package/addons/estragon/runtime/composition/profile.tres +1 -1
  35. package/addons/estragon/runtime/composition/state.gd +2 -2
  36. package/addons/estragon/runtime/composition/state.tres +1 -1
  37. package/addons/estragon/runtime/node/button.gd +1 -1
  38. package/addons/estragon/runtime/node/component_2d.gd +1 -1
  39. package/addons/estragon/runtime/node/component_3d.gd +1 -1
  40. package/addons/estragon/runtime/node/estragon_2d.gd +2 -2
  41. package/addons/estragon/runtime/node/estragon_3d.gd +1 -1
  42. package/addons/estragon/runtime/node/hbox.gd +1 -1
  43. package/addons/estragon/runtime/node/internal/coordinator.gd +2 -2
  44. package/addons/estragon/runtime/node/internal/layout_core.gd +1 -1
  45. package/addons/estragon/runtime/node/native_2d.gd +2 -2
  46. package/addons/estragon/runtime/node/native_3d.gd +2 -2
  47. package/addons/estragon/runtime/node/rect.gd +1 -1
  48. package/addons/estragon/runtime/node/text.gd +1 -1
  49. package/addons/estragon/runtime/node/toggle.gd +1 -1
  50. package/addons/estragon/runtime/node/vbox.gd +1 -1
  51. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,11 +1,15 @@
1
1
  # Release notes
2
2
 
3
- ## Next automated prerelease
3
+ ## Gogo editor experience — upcoming beta
4
4
 
5
- No compiler/runtime behavior changes are introduced by the packaging and version-source correction. The **one** release version is set in the Godot plugin configuration; the npm manifest is generated from it during packaging. The owner-controlled GitHub prerelease will exercise npm OIDC trusted publishing, provenance, byte-for-byte package verification and the approved Linux Godot consumer checks. These publication checks remain pending until the release actually runs.
5
+ The native Gogo editor now provides theme-aware GDScript/GGX syntax highlighting, context-sensitive CodeEdit completion and insertion/undo, source-positioned diagnostics/navigation, and **Project > Tools > New Gogo Script** templates for 2D/3D. No external compiler, language server or custom Godot build is needed for editing and Play. Dedicated native editor and Play checks passed on the two approved Linux Godot engines. Completion intentionally supports bounded lexical/ClassDB information rather than full GDScript type inference; the documented hidden, never-associated tab exception remains.
6
+
7
+ ## Previous direct Yarn installation beta
8
+
9
+ P02 made compiler/runtime/editor dependencies location-independent: packages work directly from Yarn `node_modules` without addon copying/symlinks. Internal references and generated dependencies resolve against installed Resources and actual destinations; Godot's enabled-plugin project setting accepts the full addon configuration path. That previous beta was published using the owner-controlled GitHub prerelease, with npm trusted-publisher OIDC, provenance/byte checks and native registry consumers. CI02 subsequently reduced mandatory certification to bounded direct-install validation; the full native regression suite remains opt-in.
6
10
 
7
11
  ## Initial public beta
8
12
 
9
13
  The first curated `@papercraftgames/estragon` addon artifact was published locally after merged F01–F06. It includes the bundled Gogo/GGX compiler/editor, typed/class-wide bindables, a signal-driven description reconciler, conditional/keyed retained Nodes, a native boolean two-way toggle, layout-first 2D widgets, bounded 3D adapters, opt-in profiling and measured LIS/preflight improvements.
10
14
 
11
- No JavaScript compiler/runtime or lifecycle scripts. Yarn dependency acquisition requires an explicit copy to the Godot project's `addons/estragon` and a `node_modules/.gdignore`. This is an early beta, not complete UI framework or release certification. Verified source/engines/artifact evidence and limitations remain in issue #104.
15
+ No JavaScript compiler/runtime or lifecycle scripts. The initial artifact used the former relocated-addon install contract; P02 replaces it with direct Yarn consumption. This is an early beta, not complete UI framework or release certification. Verified source/engines/artifact evidence and limitations remain in issue #104.
package/README.md CHANGED
@@ -2,25 +2,28 @@
2
2
 
3
3
  Pre-1.0 Godot addon: native Gogo/GGX compilation/editor, signal-driven descriptions reconciled with retained Nodes, layout-first Node2D UI and bounded Node3D adapters. Godot owns rendering, physics and scene lifetime. No Node/Bun compiler or runtime is required for authoring or Play.
4
4
 
5
+ Tagged npm packages carry the exact GitHub prerelease-tag version in both npm and Godot plugin metadata. Git source checkouts use a development marker; a local development pack is not a tagged release.
6
+
5
7
  ## Install into a Godot project
6
8
 
7
- Install the currently published beta with Yarn. The `beta` dist-tag resolves to the published package; `--exact` pins its resolved version in the consumer's manifest:
9
+ P02 direct-install support is pending an owner-published release; earlier public betas may not contain this fix. The following contract applies to a package containing P02. Install the current beta in the Godot project root:
8
10
 
9
11
  ```sh
10
12
  yarn add --exact --ignore-scripts @papercraftgames/estragon@beta
11
13
  ```
12
14
 
13
- Yarn alone installs into `node_modules`; it does not register a Godot plugin. From the project root, with no existing `addons/estragon` directory:
15
+ Keep the package where Yarn installs it. Do not copy, symlink or ignore the addon. Before opening the editor, add its full configuration path to the existing `editor_plugins/enabled` list in `project.godot` (preserve other enabled plugins):
14
16
 
15
- ```sh
16
- touch node_modules/.gdignore
17
- mkdir -p addons
18
- cp -R node_modules/@papercraftgames/estragon/addons/estragon addons/estragon
17
+ ```ini
18
+ [editor_plugins]
19
+ enabled=PackedStringArray("res://node_modules/@papercraftgames/estragon/addons/estragon/editor/plugin.cfg")
19
20
  ```
20
21
 
21
- The `.gdignore` prevents Godot importing a duplicate copy from node_modules. Use a copy, not a source/output symlink. For upgrades, back up local addon modifications and deliberately replace the previous addon directory; do not nest/merge two addon versions. Commit the copied addon and its `.gd.uid` sidecars. A teammate receiving that project can edit/run with Godot alone; node_modules is not needed at runtime.
22
+ Godot's Plugins panel discovers candidates under `addons/`; the enabled-plugin project setting accepts a full `res://` configuration path outside that directory. Yarn installation alone does not enable the plugin. Install dependencies before opening Godot; keep only one Estragon tree to avoid duplicate classes/UIDs. Commit the package manifest/lockfile and plugin setting, retaining the package's stable `.gd.uid` sidecars. Godot alone handles editing and Play after installation.
23
+
24
+ Explicit authored preload aliases reference the chosen installation, for example `preload("../../../node_modules/@papercraftgames/estragon/addons/estragon/runtime/composition/element.gd")` in a Gogo file whose generated script lives three directories below the project root. As with ordinary GDScript, relative authored imports resolve from the **generated script's directory**. Canonical registered widget class names also work after Godot indexes the project. Internal dependencies are script-relative; compiler-injected dependencies are calculated from installed Resources and the actual output directory. A different project-relative installation needs only matching authored imports and the plugin configuration setting; no production source edits. Standard `addons/estragon` placement remains supported.
22
25
 
23
- Open Godot → Project Settings → Plugins and enable **Estragon** at `res://addons/estragon/editor/plugin.cfg`. Author `.gogo` files and normal `.tscn` hosts referencing the generated script. Optionally put `{"version":1,"source_roots":["src"]}` in project `gogo.config.json`. Normal save and both main/current Play paths compile and validate natively; invalid or unsavable source blocks stale Play and recovers after repair.
26
+ Author `.gogo` files and normal `.tscn` hosts referencing generated scripts. Optional `gogo.config.json`: `{"version":1,"source_roots":["src"]}`. Native save and main/current Play compile with actual-path validation, invalid/unsavable-source rejection, rollback and repair. Generated files must be rebuilt after relocating an installed addon, just as authored imports must be updated.
24
27
 
25
28
  [Source-authored Counter example](https://github.com/papercraftgames/Estragon/tree/main/examples/counter), [language](https://github.com/papercraftgames/Estragon/blob/main/docs/GOGO_LANGUAGE.md), [native UI](https://github.com/papercraftgames/Estragon/blob/main/docs/NODE_UI.md), [editor](https://github.com/papercraftgames/Estragon/blob/main/docs/EDITOR.md), [package/release contract](https://github.com/papercraftgames/Estragon/blob/main/docs/PACKAGING.md).
26
29
 
@@ -1,9 +1,9 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  ## One lexical property lowering for explicit and class-wide Gogo annotations.
4
- const Model = preload("res://addons/estragon/compiler/model.gd")
5
- const Source = preload("res://addons/estragon/compiler/source.gd")
6
- const Lexer = preload("res://addons/estragon/compiler/lexer.gd")
4
+ const Model = preload("model.gd")
5
+ const Source = preload("source.gd")
6
+ const Lexer = preload("lexer.gd")
7
7
  var file: Source
8
8
  var module: Model.Module
9
9
  var members: Dictionary = {}
@@ -1,11 +1,11 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  ## Pure native compilation. Semantic validation/loading is an explicit next step.
4
- const Model = preload("res://addons/estragon/compiler/model.gd")
5
- const Source = preload("res://addons/estragon/compiler/source.gd")
6
- const Frontend = preload("res://addons/estragon/compiler/frontend.gd")
7
- const Emitter = preload("res://addons/estragon/compiler/emitter.gd")
8
- const SourceMap = preload("res://addons/estragon/compiler/source_map.gd")
4
+ const Model = preload("model.gd")
5
+ const Source = preload("source.gd")
6
+ const Frontend = preload("frontend.gd")
7
+ const Emitter = preload("emitter.gd")
8
+ const SourceMap = preload("source_map.gd")
9
9
 
10
10
  class Compilation extends RefCounted:
11
11
  var code: String
@@ -14,11 +14,11 @@ class Compilation extends RefCounted:
14
14
  var ok: bool:
15
15
  get: return diagnostics.is_empty() and source_map != null
16
16
 
17
- static func compile(source: String, source_name: String = "<source>") -> Compilation:
17
+ static func compile(source: String, source_name: String = "<source>", output_path: String = "") -> Compilation:
18
18
  var result := Compilation.new()
19
- var frontend := Frontend.analyze(source, source_name)
19
+ var frontend := Frontend.analyze(source, source_name, output_path)
20
20
  result.diagnostics = frontend.diagnostics
21
21
  if not frontend.ok: return result
22
- result.source_map = Emitter.new(frontend.module, Source.new(source, source_name)).emit()
22
+ result.source_map = Emitter.new(frontend.module, Source.new(source, source_name, output_path)).emit()
23
23
  result.code = result.source_map.code
24
24
  return result
@@ -1,9 +1,10 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  ## Detect the automatic host entry. Every GGX expression is a description.
4
- const Model = preload("res://addons/estragon/compiler/model.gd")
5
- const Lexer = preload("res://addons/estragon/compiler/lexer.gd")
6
- const Resolver = preload("res://addons/estragon/compiler/native/resolver.gd")
4
+ const Element = preload("../runtime/composition/element.gd")
5
+ const Model = preload("model.gd")
6
+ const Lexer = preload("lexer.gd")
7
+ const Resolver = preload("native/resolver.gd")
7
8
  var file
8
9
  func _init(source) -> void:
9
10
  file = source
@@ -31,7 +32,7 @@ func apply(module) -> void:
31
32
  return
32
33
  continue
33
34
  var type: String = tokens[index+5].text
34
- if resolver.aliases.get(type,"")!="res://addons/estragon/runtime/composition/element.gd":
35
+ if resolver.aliases.get(type,"")!=(Element as Script).resource_path:
35
36
  if has_ggx and type in ["Node","Node2D","Node3D"]:
36
37
  file.fail("build_view must return Element descriptions; eager Node-returning GGX is unsupported",tokens[index+5].span.start.index,tokens[index+5].span.end.index)
37
38
  return
@@ -1,9 +1,12 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  ## Typed frontend -> ordinary GDScript. All output is range-mapped, never rewritten.
4
- const Model = preload("res://addons/estragon/compiler/model.gd")
5
- const Source = preload("res://addons/estragon/compiler/source.gd")
6
- const MappedWriter = preload("res://addons/estragon/compiler/source_map.gd")
4
+ const Element = preload("../runtime/composition/element.gd")
5
+ const State = preload("../runtime/composition/state.tres")
6
+ const Binding = preload("../runtime/composition/binding.gd")
7
+ const Model = preload("model.gd")
8
+ const Source = preload("source.gd")
9
+ const MappedWriter = preload("source_map.gd")
7
10
 
8
11
  class Argument extends RefCounted:
9
12
  var expression: Model.GdExpression
@@ -16,6 +19,7 @@ class Factory extends RefCounted:
16
19
  var root: Model.Component
17
20
  var arguments: Array[Argument] = []
18
21
 
22
+ var _output_directory: String
19
23
  var _module: Model.Module
20
24
  var _file: Source
21
25
  var _writer: MappedWriter
@@ -27,6 +31,10 @@ var _factory_class: String
27
31
  var _element_class: String
28
32
 
29
33
  func _init(module: Model.Module, file: Source) -> void:
34
+ # Paths are relative to the actual generated file, derived from installed Resources.
35
+ # Pathless in-memory callers use the project root, as native GDScript does.
36
+ _output_directory = file.generated_path().get_base_dir()
37
+ if not _output_directory.is_absolute_path(): _output_directory = "res://" + _output_directory
30
38
  _module = module
31
39
  _file = file
32
40
  _writer = MappedWriter.new(file)
@@ -40,14 +48,17 @@ func _init(module: Model.Module, file: Source) -> void:
40
48
  _element_class = "_GogoElement_0"
41
49
  while _module.identifiers.has(_element_class): _element_class += "_"
42
50
 
51
+ func _resource(resource: Resource) -> String:
52
+ return _string(Source.relative_path(_output_directory,resource.resource_path))
53
+
43
54
  func emit() -> MappedWriter:
44
55
  _parts(_module.parts)
45
56
  _writer.append("\n")
46
57
  if _module.composition:
47
- _writer.append("\nfunc _notification(_gogo_what: int) -> void:\n"+_module.indentation+"preload(\"res://addons/estragon/runtime/composition/state.tres\").lifecycle(self, _gogo_what)\n")
58
+ _writer.append("\nfunc _notification(_gogo_what: int) -> void:\n"+_module.indentation+"preload("+_resource(State)+").lifecycle(self, _gogo_what)\n")
48
59
  if not _factories.is_empty():
49
60
  _writer.append("\n\nclass " + _factory_class + ":", _factories[0].root.span)
50
- _writer.append("\n"+_module.indentation+"const "+_element_class+" = preload(\"res://addons/estragon/runtime/composition/element.gd\")\n")
61
+ _writer.append("\n"+_module.indentation+"const "+_element_class+" = preload("+_resource(Element)+")\n")
51
62
  # Calls in argument expressions may append additional factories.
52
63
  var index: int = 0
53
64
  while index < _factories.size():
@@ -190,7 +201,7 @@ func _bindable(property: Model.Bindable) -> void:
190
201
  _writer.append(indent.repeat(2)+"var "+previous+": "+property.type_name+" = "+property.name+"\n",property.name_span)
191
202
  _writer.append(indent.repeat(2)+property.name+" = "+incoming+"\n",property.name_span)
192
203
  _writer.append(indent.repeat(2)+property.signal_name+".emit("+previous+", "+incoming+")\n",property.name_span)
193
- _writer.append(indent+"get:\n"+indent.repeat(2)+"preload(\"res://addons/estragon/runtime/composition/state.tres\").observe(self, &"+_string(property.signal_name)+")\n"+indent.repeat(2)+"return "+property.name+"\n",property.name_span)
204
+ _writer.append(indent+"get:\n"+indent.repeat(2)+"preload("+_resource(State)+").observe(self, &"+_string(property.signal_name)+")\n"+indent.repeat(2)+"return "+property.name+"\n",property.name_span)
194
205
 
195
206
  func _binding_argument(argument: Argument) -> void:
196
207
  var path := argument.binding_path.duplicate()
@@ -206,4 +217,4 @@ func _binding_argument(argument: Argument) -> void:
206
217
  for name in path:
207
218
  endpoint += "."+str(name)
208
219
  checks.append(endpoint+" != null")
209
- _writer.append("preload(\"res://addons/estragon/runtime/composition/binding.gd\").new(self, func("+owner+"): return "+endpoint+" if "+" and ".join(checks)+" else null, "+_string(field)+", func("+source+", "+edit+": bool): "+source+"."+field+" = "+edit+", "+_string(".".join(argument.binding_path))+")",argument.expression.span)
220
+ _writer.append("preload("+_resource(Binding)+").new(self, func("+owner+"): return "+endpoint+" if "+" and ".join(checks)+" else null, "+_string(field)+", func("+source+", "+edit+": bool): "+source+"."+field+" = "+edit+", "+_string(".".join(argument.binding_path))+")",argument.expression.span)
@@ -1,15 +1,15 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  ## Native source -> typed frontend result. No emitter, subprocess or editor state.
4
- const Model = preload("res://addons/estragon/compiler/model.gd")
5
- const Source = preload("res://addons/estragon/compiler/source.gd")
6
- const Parser = preload("res://addons/estragon/compiler/parser.gd")
7
- const Bindable = preload("res://addons/estragon/compiler/bindable.gd")
8
- const Validator = preload("res://addons/estragon/compiler/validator.gd")
9
- const Composition = preload("res://addons/estragon/compiler/composition.gd")
4
+ const Model = preload("model.gd")
5
+ const Source = preload("source.gd")
6
+ const Parser = preload("parser.gd")
7
+ const Bindable = preload("bindable.gd")
8
+ const Validator = preload("validator.gd")
9
+ const Composition = preload("composition.gd")
10
10
 
11
- static func analyze(text: String, source_name: String = "<source>") -> Model.Result:
12
- var file := Source.new(text, source_name)
11
+ static func analyze(text: String, source_name: String = "<source>", output_path: String = "") -> Model.Result:
12
+ var file := Source.new(text, source_name, output_path)
13
13
  var parser := Parser.new(file)
14
14
  var result := Model.Result.new()
15
15
  var module := parser.parse()
@@ -2,8 +2,8 @@
2
2
  extends RefCounted
3
3
  ## Re-entrant token scanner: caller supplies the offset and lexical context.
4
4
  ## Regexes classify Unicode characters only; no source rewriting/evaluation.
5
- const Model = preload("res://addons/estragon/compiler/model.gd")
6
- const Source = preload("res://addons/estragon/compiler/source.gd")
5
+ const Model = preload("model.gd")
6
+ const Source = preload("source.gd")
7
7
  const OPERATORS := ["**=", "<<=", ">>=", ":=", "==", "!=", "<=", ">=", "<<", ">>", "**", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "&&", "||", "->"]
8
8
  var file: Source
9
9
  var tokens: Array[Model.Token] = []
@@ -1,11 +1,11 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  ## Static Node type metadata. Never instantiate authored classes or use editor/tree.
4
- const Model = preload("res://addons/estragon/compiler/model.gd")
5
- const Lexer = preload("res://addons/estragon/compiler/lexer.gd")
6
- const Source = preload("res://addons/estragon/compiler/source.gd")
7
- const Parser = preload("res://addons/estragon/compiler/parser.gd")
8
- const Bindable = preload("res://addons/estragon/compiler/bindable.gd")
4
+ const Model = preload("../model.gd")
5
+ const Lexer = preload("../lexer.gd")
6
+ const Source = preload("../source.gd")
7
+ const Parser = preload("../parser.gd")
8
+ const Bindable = preload("../bindable.gd")
9
9
  var visiting: Dictionary = {}
10
10
  var file
11
11
  var aliases: Dictionary = {}
@@ -48,9 +48,9 @@ func scan(module: Model.Module) -> void:
48
48
  return
49
49
  var path: String = literal.call("value")
50
50
  if not path.is_absolute_path():
51
- var output: String = file.name.get_base_dir().path_join("generated").path_join(file.name.get_file().get_basename() + ".gd")
51
+ var output: String = file.generated_path()
52
52
  path = output.get_base_dir().path_join(path).simplify_path()
53
- if not path.begins_with("res://"): path = "res://" + path
53
+ if not path.is_absolute_path(): path = "res://" + path
54
54
  aliases[name] = path
55
55
 
56
56
  func resolve(name: String, span: Model.Span) -> Dictionary:
@@ -1,9 +1,9 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  ## Recursive-descent component islands composed with lexically retained GDScript.
4
- const Model = preload("res://addons/estragon/compiler/model.gd")
5
- const Source = preload("res://addons/estragon/compiler/source.gd")
6
- const Lexer = preload("res://addons/estragon/compiler/lexer.gd")
4
+ const Model = preload("model.gd")
5
+ const Source = preload("source.gd")
6
+ const Lexer = preload("lexer.gd")
7
7
  const OPERANDS := ["return", "yield", "await", "if", "elif", "else", "while", "in", "and", "or", "not", "assert", "match"]
8
8
  const OPEN := {"(": ")", "[": "]", "{": "}"}
9
9
  var file: Source
@@ -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,28 @@
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
7
8
  var diagnostics: Array[Model.Diagnostic] = []
8
9
  var _lines: PackedInt32Array = [0]
9
10
  var _utf16: PackedInt32Array = [0]
10
11
 
11
- func _init(value: String, source_name: String = "<source>") -> void:
12
+ func _init(value: String, source_name: String = "<source>", generated_path: String = "") -> void:
12
13
  text = value
13
14
  name = source_name
15
+ output_path = generated_path
14
16
  for index in range(text.length()):
15
17
  _utf16.append(_utf16[-1] + (2 if text.unicode_at(index) > 0xffff else 1))
16
18
  if text[index] == "\n" or text[index] == "\r" and (index + 1 == text.length() or text[index + 1] != "\n"):
17
19
  _lines.append(index + 1)
18
20
 
21
+ func generated_path() -> String:
22
+ if not output_path.is_empty(): return output_path
23
+ if not "/" in name: return "res://Generated.gd"
24
+ return name.get_base_dir().path_join("generated").path_join(name.get_file().get_basename() + ".gd")
25
+
19
26
  func position(index: int) -> Model.Position:
20
27
  index = clampi(index, 0, text.length())
21
28
  var low: int = 0
@@ -63,3 +70,11 @@ func index_at_offset(offset_value: int) -> int:
63
70
 
64
71
  func offset(line: int, column: int = 1) -> int:
65
72
  return mini(_utf16[-1], _utf16[line_start(line)] + maxi(0, column - 1))
73
+
74
+ ## Relative resource references shared by emission and editor starter templates.
75
+ static func relative_path(directory: String, resource_path: String) -> String:
76
+ var origin := ProjectSettings.globalize_path(directory).simplify_path().split("/", false)
77
+ var target := ProjectSettings.globalize_path(resource_path).simplify_path().split("/", false)
78
+ var shared := 0
79
+ while shared < mini(origin.size(), target.size()) and origin[shared] == target[shared]: shared += 1
80
+ 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] = []
@@ -1,10 +1,11 @@
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 Lexer = preload("lexer.gd")
8
9
  var file: Source
9
10
  var resolver
10
11
  var current_module
@@ -231,7 +232,7 @@ func _child_result(tokens: Array, span) -> void:
231
232
  var first: String = tokens[0].text
232
233
  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
234
  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"):
235
+ 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
236
  return
236
237
  _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)
237
238
 
@@ -1,13 +1,13 @@
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
7
  const CONFIG := "gogo.config.json"
8
8
  const EXCLUDED := ["generated", "node_modules", "tests", "vendor"]
9
9
  var _project: String
10
- var _report := {"ok": false, "outputs": [], "changed": [], "diagnostics": [], "isolated_preflight": {"status": "UNTESTED"}}
10
+ var _report := {"ok": false, "outputs": [], "changed": [], "diagnostics": [], "source_diagnostics": [], "isolated_preflight": {"status": "UNTESTED"}}
11
11
  var _sources: Dictionary = {}
12
12
  var _staging: String
13
13
  var _previous_code: Dictionary = {}
@@ -20,6 +20,10 @@ static func run_build(project: String = "res://") -> Dictionary:
20
20
  func _fail(message: String) -> void:
21
21
  _report.diagnostics.append(message)
22
22
 
23
+ func _fail_source(diagnostic) -> void:
24
+ _fail(diagnostic.format())
25
+ _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})
26
+
23
27
  func _safe(path: String) -> bool:
24
28
  if not path.begins_with(_project + "/"):
25
29
  _fail("Generated/source path escapes the project: " + path)
@@ -91,9 +95,9 @@ func _run() -> Dictionary:
91
95
  if input == null:
92
96
  _fail(source + ": cannot read source (" + error_string(FileAccess.get_open_error()) + ")")
93
97
  continue
94
- var result := Compiler.compile(input.get_as_text(), source)
98
+ var result := Compiler.compile(input.get_as_text(), source, _resource_path(output_for(source)))
95
99
  if not result.ok:
96
- for diagnostic in result.diagnostics: _fail(diagnostic.format())
100
+ for diagnostic in result.diagnostics: _fail_source(diagnostic)
97
101
  else: compiled.append({"source": source, "output": output_for(source), "result": result})
98
102
  if not _report.diagnostics.is_empty(): return _report
99
103
  var writes: Dictionary = {}
@@ -166,7 +170,7 @@ func _run() -> Dictionary:
166
170
  for item in compiled:
167
171
  if isolated:
168
172
  var checked := Validation.validate(item.result, _resource_path(item.output))
169
- for diagnostic in checked.diagnostics: _fail(diagnostic.format())
173
+ for diagnostic in checked.diagnostics: _fail_source(diagnostic)
170
174
  if not checked.ok:
171
175
  _report.isolated_preflight.status = "FAIL"
172
176
  break
@@ -223,7 +227,7 @@ func _refresh_cache(item: Dictionary, state: Array[Dictionary]) -> void:
223
227
  # Reload the actual Script even on no-op builds; keep_state preserves owners.
224
228
  state.append({"script": script, "previous": script.source_code if was_cached else _previous_code.get(item.output), "output": item.output})
225
229
  var checked := Validation.reload_script(item.result, script, true)
226
- for diagnostic in checked.diagnostics: _fail(diagnostic.format())
230
+ for diagnostic in checked.diagnostics: _fail_source(diagnostic)
227
231
 
228
232
  func _restore_cache(state: Array[Dictionary]) -> void:
229
233
  for item in state:
@@ -250,3 +254,31 @@ func _visit_dependencies(item: Dictionary, by_path: Dictionary, visited: Diction
250
254
  for path in item.dependencies:
251
255
  if by_path.has(path): _visit_dependencies(by_path[path], by_path, visited, ordered)
252
256
  ordered.append(item)
257
+
258
+ ## Same discovery exclusions/containment as builds; no writes or config changes.
259
+ static func creation_check(path: String) -> Dictionary:
260
+ var relative := path.trim_prefix("res://")
261
+ if not path.begins_with("res://") or path.get_extension() != "gogo" or "\\" in relative or ":" in relative:
262
+ return {"ok":false,"message":"Choose a .gogo file beneath res://."}
263
+ for part in relative.split("/"):
264
+ if part.begins_with(".") or part in EXCLUDED: return {"ok":false,"message":"This path is excluded from Gogo compilation. Choose a configured source root."}
265
+ if FileAccess.file_exists(path) or DirAccess.dir_exists_absolute(path):
266
+ return {"ok":false,"message":"A file or directory already exists. New Gogo Script never overwrites existing source; choose another filename."}
267
+ if not DirAccess.dir_exists_absolute(path.get_base_dir()): return {"ok":false,"message":"Create/select an existing project directory first."}
268
+ var check := new()
269
+ check._project = ProjectSettings.globalize_path("res://").trim_suffix("/")
270
+ if not check._safe(ProjectSettings.globalize_path(path)): return {"ok":false,"message":"Unsafe source path: "+str(check._report.diagnostics)}
271
+ if not FileAccess.file_exists("res://"+CONFIG):
272
+ return {"ok":not relative.begins_with("addons/"),"message":"Default discovery excludes the top-level addons directory; choose a project source directory."}
273
+ var json := JSON.new()
274
+ if json.parse(FileAccess.get_file_as_string("res://"+CONFIG)) != OK: return {"ok":false,"message":CONFIG+": "+json.get_error_message()}
275
+ var config: Variant = json.data
276
+ 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():
277
+ return {"ok":false,"message":CONFIG+": expected version 1 and nonempty source_roots."}
278
+ var eligible := false
279
+ for root in config.source_roots:
280
+ 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"}
281
+ for part in root.split("/"):
282
+ if part.begins_with(".") or part in EXCLUDED: return {"ok":false,"message":CONFIG+": invalid source root"}
283
+ if relative == root or relative.begins_with(root.trim_suffix("/")+"/"): eligible = true
284
+ return {"ok":eligible,"message":"Choose a location included by gogo.config.json source_roots: "+str(config.source_roots)}