@papercraftgames/estragon 0.1.0-beta.10 → 0.1.0-beta.12

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 (25) hide show
  1. package/addons/estragon/compiler/source_map.gd +1 -1
  2. package/addons/estragon/compiler/validator.gd +2 -2
  3. package/addons/estragon/editor/completion.gd +157 -36
  4. package/addons/estragon/editor/generated_editors.gd +256 -0
  5. package/addons/estragon/editor/generated_editors.gd.uid +1 -0
  6. package/addons/estragon/editor/plugin.cfg +1 -1
  7. package/addons/estragon/editor/plugin.gd +18 -33
  8. package/addons/estragon/editor/scene_components.gd +4 -2
  9. package/addons/estragon/runtime/composition/computation.gd +87 -4
  10. package/addons/estragon/runtime/composition/element.gd +2 -0
  11. package/addons/estragon/runtime/composition/layout_host.gd +56 -0
  12. package/addons/estragon/runtime/composition/layout_host.gd.uid +1 -0
  13. package/addons/estragon/runtime/composition/projection.gd +32 -0
  14. package/addons/estragon/runtime/composition/projection.gd.uid +1 -0
  15. package/addons/estragon/runtime/composition/state.gd +11 -0
  16. package/addons/estragon/runtime/node/button.gd +7 -1
  17. package/addons/estragon/runtime/node/component_2d.gd +1 -1
  18. package/addons/estragon/runtime/node/component_3d.gd +1 -1
  19. package/addons/estragon/runtime/node/internal/composition_hosts.gd +124 -0
  20. package/addons/estragon/runtime/node/internal/composition_hosts.gd.uid +1 -0
  21. package/addons/estragon/runtime/node/internal/composition_hosts.tres +6 -0
  22. package/addons/estragon/runtime/node/internal/coordinator.gd +21 -9
  23. package/addons/estragon/runtime/node/native_2d.gd +1 -1
  24. package/addons/estragon/runtime/node/native_3d.gd +1 -1
  25. package/package.json +1 -1
@@ -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"
@@ -226,7 +226,7 @@ func _child_result(tokens: Array, span) -> void:
226
226
  if begin<tokens.size()-1: _child_result(tokens.slice(begin,tokens.size()-1),span)
227
227
  return
228
228
  # Unknown native expressions (locals, typed helper returns, Array.map) are
229
- # runtime-validated as a complete desired tree. Obvious scalar/live Node
229
+ # runtime-validated as a complete desired tree. Obvious scalar/newly-created Node
230
230
  # leaves fail at their authored span, including conditional alternatives.
231
231
  if not tokens.is_empty():
232
232
  var first: String = tokens[0].text
@@ -234,7 +234,7 @@ func _child_result(tokens: Array, span) -> void:
234
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"]
235
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):
236
236
  return
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
+ _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)
238
238
 
239
239
  func _native_type(property: Dictionary) -> String:
240
240
  if property.type == TYPE_OBJECT:
@@ -22,6 +22,8 @@ var _path := ""
22
22
  var _symbols: Dictionary = {}
23
23
  var _aliases: Dictionary = {}
24
24
  var _owners: Dictionary = {}
25
+ var _scoped: Dictionary = {}
26
+ var _blocks: Dictionary = {}
25
27
  var _base := "Node"
26
28
  var _native_cache: Dictionary = {}
27
29
  var _types = Validator.new(Source.new(""))
@@ -57,17 +59,35 @@ func _resolve_path(raw: String, source: String) -> String:
57
59
  if value.is_absolute_path(): return value.simplify_path()
58
60
  var output := Build.output_for(source) if source.ends_with(".gogo") else source
59
61
  return output.get_base_dir().path_join(value).simplify_path()
62
+ func _declared_type(tokens: Array, start: int) -> String:
63
+ if start>=tokens.size() or not tokens[start].text.is_valid_identifier(): return ""
64
+ var type: String = tokens[start].text
65
+ for index in range(start+1,mini(start+17,tokens.size()-1),2):
66
+ if tokens[index].text!="." or not tokens[index+1].text.is_valid_identifier(): break
67
+ type += "."+tokens[index+1].text
68
+ return type
60
69
  func _declarations(text: String, source: String) -> Dictionary:
61
70
  var tokens := _tokens(text)
71
+ # Indentation block identities distinguish a local declaration from names
72
+ # in an exited/sibling block. Compute once with the declaration index.
73
+ var blocks := {}
74
+ var stack: Array = []
75
+ for token in tokens:
76
+ if blocks.has(token.row): continue
77
+ while not stack.is_empty() and stack[-1].indent>token.indent: stack.pop_back()
78
+ if token.indent>0 and (stack.is_empty() or stack[-1].indent<token.indent): stack.append({"indent":token.indent,"id":token.row})
79
+ if token.indent==0: stack.clear()
80
+ blocks[token.row] = stack.map(func(block): return block.id)
62
81
  var symbols: Dictionary = {}
63
82
  var aliases: Dictionary = {}
64
83
  var base := ""
65
84
  var owner := ""
66
85
  var owners: Dictionary = {}
86
+ var scoped: Dictionary = {}
67
87
  var required_initializer := false
68
88
  for index in range(tokens.size()):
69
89
  var word: String = tokens[index].text
70
- if tokens[index].indent == 0: owners[tokens[index].row] = ""
90
+ if tokens[index].indent == 0 and not owners.has(tokens[index].row): owners[tokens[index].row] = ""
71
91
  elif not owners.has(tokens[index].row): owners[tokens[index].row] = owner
72
92
  if word == "extends" and tokens[index].indent == 0 and index+1 < tokens.size():
73
93
  base = _resolve_path(tokens[index+1].text,source) if tokens[index+1].kind == "string" else tokens[index+1].text
@@ -80,9 +100,18 @@ func _declarations(text: String, source: String) -> Dictionary:
80
100
  owners[tokens[index].row] = owner
81
101
  if name == "_init" and index+3 < tokens.size() and tokens[index+3].text != ")": required_initializer = true
82
102
  var type := ""
83
- if index+3 < tokens.size() and tokens[index+2].text == ":": type = tokens[index+3].text
84
- symbols[name] = {"type":type,"owner":scope,"writable":true,"kind":CodeEdit.KIND_FUNCTION if word == "func" else (CodeEdit.KIND_SIGNAL if word == "signal" else (CodeEdit.KIND_CONSTANT if word == "const" else (CodeEdit.KIND_CLASS if word in ["class","class_name"] else (CodeEdit.KIND_VARIABLE if not scope.is_empty() else CodeEdit.KIND_MEMBER))))}
85
- if word == "func": symbols[name].hint = text.split("\n")[tokens[index].row].strip_edges().trim_prefix("func ").trim_suffix(":")
103
+ if index+3 < tokens.size() and tokens[index+2].text == ":": type = _declared_type(tokens,index+3)
104
+ symbols[name] = {"type":type,"owner":scope,"row":tokens[index].row,"block":blocks.get(tokens[index].row,[]),"writable":true,"kind":CodeEdit.KIND_FUNCTION if word == "func" else (CodeEdit.KIND_SIGNAL if word == "signal" else (CodeEdit.KIND_CONSTANT if word == "const" else (CodeEdit.KIND_CLASS if word in ["class","class_name"] else (CodeEdit.KIND_VARIABLE if not scope.is_empty() else CodeEdit.KIND_MEMBER))))}
105
+ if word == "func":
106
+ symbols[name].hint = text.split("\n")[tokens[index].row].strip_edges().trim_prefix("func ").trim_suffix(":")
107
+ var depth := 0
108
+ for cursor in range(index+2,mini(index+258,tokens.size()-2)):
109
+ if tokens[cursor].text == "(": depth += 1
110
+ elif tokens[cursor].text == ")":
111
+ depth -= 1
112
+ if depth == 0:
113
+ if tokens[cursor+1].text == "->": symbols[name].type = _declared_type(tokens,cursor+2)
114
+ break
86
115
  if word == "signal":
87
116
  var args: Array = []
88
117
  for cursor in range(index+2,mini(index+28,tokens.size()-1)):
@@ -101,12 +130,17 @@ func _declarations(text: String, source: String) -> Dictionary:
101
130
  if index+3<tokens.size() and tokens[index+2].text=="=" and ClassDB.class_exists(tokens[index+3].text): aliases[name] = tokens[index+3].text
102
131
  for cursor in range(index+2,mini(index+7,tokens.size()-2)):
103
132
  if tokens[cursor].text == "preload" and tokens[cursor+1].text == "(" and tokens[cursor+2].kind == "string": aliases[name] = _resolve_path(tokens[cursor+2].text,source)
133
+ if not scoped.has(scope): scoped[scope] = {}
134
+ scoped[scope][name] = symbols[name]
104
135
  # Typed arguments/local declarations also contribute names, never inferred values.
105
136
  for index in range(1,tokens.size()-2):
106
137
  if tokens[index].text == ":" and tokens[index-1].text.is_valid_identifier() and tokens[index+1].text.is_valid_identifier() and tokens[index+1].kind != "keyword" and tokens[index].row == tokens[index+1].row:
107
138
  var name: String = tokens[index-1].text
108
- if not symbols.has(name): symbols[name] = {"type":tokens[index+1].text,"owner":owners.get(tokens[index].row,""),"kind":CodeEdit.KIND_VARIABLE}
109
- return {"symbols":symbols,"aliases":aliases,"base":base,"owners":owners,"required_initializer":required_initializer}
139
+ var scope: String = owners.get(tokens[index].row,"")
140
+ if not scoped.has(scope): scoped[scope] = {}
141
+ if not scoped[scope].has(name): scoped[scope][name] = {"type":_declared_type(tokens,index+1),"owner":scope,"row":tokens[index].row,"block":blocks.get(tokens[index].row,[]),"kind":CodeEdit.KIND_VARIABLE}
142
+ if not symbols.has(name): symbols[name] = scoped[scope][name]
143
+ return {"symbols":symbols,"scoped":scoped,"blocks":blocks,"aliases":aliases,"base":base,"owners":owners,"required_initializer":required_initializer}
110
144
  func _index(text: String, source: String) -> void:
111
145
  if text == _text and source == _path: return
112
146
  _text = text
@@ -114,6 +148,8 @@ func _index(text: String, source: String) -> void:
114
148
  var declarations := _declarations(text,source)
115
149
  _symbols = declarations.symbols
116
150
  _owners = declarations.owners
151
+ _scoped = declarations.scoped
152
+ _blocks = declarations.blocks
117
153
  _aliases = declarations.aliases
118
154
  _base = declarations.base
119
155
  func _script(path: String) -> Dictionary:
@@ -132,25 +168,111 @@ func _method_hint(method: Dictionary) -> String:
132
168
  var args: Array = []
133
169
  for arg in method.get("args",[]): args.append(str(arg.name)+": "+_type_name(arg))
134
170
  return str(method.name)+"("+", ".join(args)+") -> "+_type_name(method.get("return",{}))
171
+ # Bounded cached tokens at the caret. Strings stay opaque; comments and GGX
172
+ # delimiters cannot masquerade as code. Never parse the whole file per request.
173
+ func _chain_tokens(lexical: RefCounted, row: int, column: int) -> Array:
174
+ var result: Array = []
175
+ var budget := 4096
176
+ for line in range(row,maxi(-1,row-16),-1):
177
+ var limit: int = column if line==row else lexical.lines[line].length()
178
+ budget -= limit
179
+ if budget<0: return []
180
+ var tokens: Array = []
181
+ for token in lexical.line(line).tokens:
182
+ if token.start>=limit: break
183
+ if token.kind=="comment": continue
184
+ var item: Dictionary = token.duplicate()
185
+ if item.end>limit: item.text = item.text.left(limit-item.start)
186
+ if item.kind=="string" and not tokens.is_empty() and tokens[-1].kind=="string" and tokens[-1].end==item.start:
187
+ tokens[-1].text += item.text
188
+ tokens[-1].end = item.end
189
+ else: tokens.append(item)
190
+ result = tokens+result
191
+ if result.size()>256: return []
192
+ return result
193
+ func _scope_members(row: int, self_only: bool = false) -> Dictionary:
194
+ var result := _members(_base,_aliases).duplicate()
195
+ result.merge(_scoped.get("",{}),true)
196
+ if not self_only:
197
+ for name in _scoped.get(_owners.get(row,""),{}):
198
+ var item: Dictionary = _scoped[_owners.get(row,"")][name]
199
+ var visible: bool = item.get("row",0)<=row
200
+ for block in item.get("block",[]):
201
+ if not _blocks.get(row,[]).has(block): visible = false
202
+ if visible: result[name] = item
203
+ return result
204
+ func _value_members(value: Dictionary) -> Dictionary:
205
+ if value.get("self",false): return _scope_members(value.row,true)
206
+ var type: String = value.get("type","")
207
+ if type in ["","Variant","void"] or value.get("kind",-1)==CodeEdit.KIND_FUNCTION: return {}
208
+ return _members(type,value.get("aliases",_aliases))
209
+ # Parse only a postfix expression ending at 'end'. Calls skip balanced argument
210
+ # tokens, and use the callable's proven return declaration, never argument values.
211
+ func _chain(tokens: Array, end: int, row: int, depth: int = 0) -> Dictionary:
212
+ if end<0 or depth>=24: return {}
213
+ var token: Dictionary = tokens[end]
214
+ if token.text==")":
215
+ var closes := []
216
+ var opening := -1
217
+ for index in range(end,-1,-1):
218
+ var word: String = tokens[index].text
219
+ if tokens[index].kind=="string": continue
220
+ if word in [")","]","}"]: closes.append(word)
221
+ elif word in ["(","[","{"]:
222
+ if closes.is_empty() or closes.pop_back()!={"(":")","[":"]","{":"}"}[word]: return {}
223
+ if closes.is_empty(): opening = index; break
224
+ if opening<0: return {}
225
+ if opening>0 and (tokens[opening-1].text.is_valid_identifier() and tokens[opening-1].text not in Context.KEYWORDS or tokens[opening-1].text==")"):
226
+ var callable := _chain(tokens,opening-1,row,depth+1)
227
+ if callable.is_empty() or callable.value.get("kind",-1)!=CodeEdit.KIND_FUNCTION: return {}
228
+ var value: Dictionary = callable.value.duplicate()
229
+ value.kind = CodeEdit.KIND_VARIABLE
230
+ return {"start":callable.start,"value":value}
231
+ var grouped := _chain(tokens,end-1,row,depth+1)
232
+ if grouped.is_empty() or grouped.start!=opening+1: return {}
233
+ grouped.start = opening
234
+ return grouped
235
+ if not token.text.is_valid_identifier() or token.kind in ["string","tag","property"]: return {}
236
+ if end>0 and tokens[end-1].text==".":
237
+ var receiver := _chain(tokens,end-2,row,depth+1)
238
+ if receiver.is_empty(): return {}
239
+ var members := _value_members(receiver.value)
240
+ if not members.has(token.text): return {}
241
+ return {"start":receiver.start,"value":members[token.text]}
242
+ if token.text=="self": return {"start":end,"value":{"self":true,"row":row}}
243
+ var scope := _scope_members(row)
244
+ if scope.has(token.text): return {"start":end,"value":scope[token.text]}
245
+ if ClassDB.class_exists(token.text) or _aliases.has(token.text): return {"start":end,"value":{"type":token.text}}
246
+ return {}
247
+ func _receiver_members(tokens: Array, end: int, row: int) -> Dictionary:
248
+ var receiver := _chain(tokens,end,row)
249
+ if receiver.is_empty(): return {}
250
+ # Do not infer from a suffix of an unsupported binary/index/cast expression.
251
+ if receiver.start>0 and tokens[receiver.start-1].text in [".","]","+","-","*","/","%","as","is"]: return {}
252
+ return _value_members(receiver.value)
253
+ func _callable_attribute(lexical: RefCounted, context: Dictionary, row: int, column: int) -> bool:
254
+ if context.frames.is_empty() or context.frames[-1].mode!="tag": return false
255
+ var tokens := _chain_tokens(lexical,row,column)
256
+ for index in range(tokens.size()-1,-1,-1):
257
+ if tokens[index].kind!="expression" or tokens[index].text!="{": continue
258
+ if index<2 or tokens[index-1].text!="=" or tokens[index-2].kind!="property": return false
259
+ var member: Dictionary = _members(context.frames[-1].tag,_aliases).get(tokens[index-2].text,{})
260
+ return member.get("kind",-1)==CodeEdit.KIND_SIGNAL or member.get("type","")=="Callable"
261
+ return false
135
262
  func call_hint(text: String, source: String, lexical: RefCounted, row: int, column: int) -> String:
136
263
  _index(text,source)
137
264
  lexical.update(text)
138
265
  var state: Dictionary = lexical.context(row,column)
139
- if state.suppressed or state.mode != "gd": return ""
140
- var tokens := _tokens(lexical.lines[row].left(column))
266
+ if state.suppressed or state.mode!="gd": return ""
267
+ var tokens := _chain_tokens(lexical,row,column)
141
268
  var depth := 0
142
269
  for index in range(tokens.size()-1,-1,-1):
143
- if tokens[index].text == ")": depth += 1
144
- if tokens[index].text != "(": continue
145
- if depth > 0: depth -= 1; continue
146
- if index == 0: return ""
147
- var name: String = tokens[index-1].text
148
- var members := _members(_base,_aliases)
149
- if index >= 3 and tokens[index-2].text == ".":
150
- var receiver: String = tokens[index-3].text
151
- if receiver != "self": members = _members(str(_symbols.get(receiver,{}).get("type",receiver)),_aliases)
152
- else: members.merge(_symbols,true)
153
- return str(members.get(name,{}).get("hint",""))
270
+ if tokens[index].kind=="string": continue
271
+ if tokens[index].text==")": depth += 1
272
+ if tokens[index].text!="(": continue
273
+ if depth>0: depth -= 1; continue
274
+ var callable := _chain(tokens,index-1,row)
275
+ return str(callable.value.get("hint","")) if not callable.is_empty() and callable.value.get("kind",-1)==CodeEdit.KIND_FUNCTION else ""
154
276
  return ""
155
277
  func _members(type: String, aliases: Dictionary, visited: Array = []) -> Dictionary:
156
278
  var name: String = aliases.get(type,type)
@@ -166,6 +288,9 @@ func _members(type: String, aliases: Dictionary, visited: Array = []) -> Diction
166
288
  result[prop.name] = {"type":_type_name(prop),"kind":CodeEdit.KIND_MEMBER,"value_type":prop.type,"writable":not (int(prop.usage)&PROPERTY_USAGE_READ_ONLY)}
167
289
  for method in ClassDB.class_get_method_list(name): result[method.name] = {"type":_type_name(method.get("return",{})),"kind":CodeEdit.KIND_FUNCTION,"hint":_method_hint(method)}
168
290
  for sig in ClassDB.class_get_signal_list(name): result[sig.name] = {"type":"","kind":CodeEdit.KIND_SIGNAL,"args":sig.args.map(func(arg): return arg.type)}
291
+ # Native return/property identities cannot be redirected by an authored
292
+ # alias that happens to have the same spelling as the native class.
293
+ for member in result.values(): member.aliases = {}
169
294
  _native_cache[name] = result
170
295
  return result
171
296
  if not name.begins_with("res://"):
@@ -187,8 +312,9 @@ func _members(type: String, aliases: Dictionary, visited: Array = []) -> Diction
187
312
  for prop in cached.get_script_property_list():
188
313
  if str(prop.name).is_valid_identifier() and not (int(prop.usage) & (PROPERTY_USAGE_CATEGORY|PROPERTY_USAGE_GROUP|PROPERTY_USAGE_SUBGROUP)): result[prop.name] = {"type":_type_name(prop),"kind":CodeEdit.KIND_MEMBER,"writable":not (int(prop.usage)&PROPERTY_USAGE_READ_ONLY)}
189
314
  for method in cached.get_script_method_list(): result[method.name] = {"type":_type_name(method.get("return",{})),"kind":CodeEdit.KIND_FUNCTION,"hint":_method_hint(method)}
190
- for field in declarations.symbols:
191
- if declarations.symbols[field].owner.is_empty(): result[field] = declarations.symbols[field]
315
+ for field in declarations.scoped.get("",{}):
316
+ result[field] = declarations.scoped[""][field].duplicate()
317
+ result[field].aliases = declarations.aliases
192
318
  return result
193
319
  func _node_type(type: String, aliases: Dictionary, visited: Array = []) -> bool:
194
320
  var name: String = aliases.get(type,type)
@@ -331,6 +457,8 @@ func candidates(text: String, source: String, lexical: RefCounted, row: int, col
331
457
  prefix = left[cursor]+prefix
332
458
  cursor -= 1
333
459
  if context.mode == "tag" and context.closing: prefix = "/"+prefix
460
+ var member_cursor := cursor
461
+ while member_cursor>=0 and left[member_cursor] in [" ","\t"]: member_cursor -= 1
334
462
  var offered: Dictionary = {}
335
463
  if context.mode == "tag":
336
464
  if context.closing:
@@ -363,20 +491,10 @@ func candidates(text: String, source: String, lexical: RefCounted, row: int, col
363
491
  if _node_type(context.tag,_aliases): offered.key = {"kind":CodeEdit.KIND_MEMBER}
364
492
  if members.has("value") and (members.value.get("value_type") == TYPE_BOOL or members.value.get("type") == "bool") and members.has("value_changed") and members.value_changed.get("args",[]).size() == 1 and members.value_changed.args[0] in ["bool",TYPE_BOOL]: offered["bind:value"] = {"kind":CodeEdit.KIND_MEMBER}
365
493
  elif context.mode == "body": return []
366
- elif cursor >= 0 and left[cursor] == ".":
367
- var begin := cursor-1
368
- while begin >= 0 and (left[begin].is_valid_identifier() or left[begin].is_valid_int() or left[begin] == "."): begin -= 1
369
- var receiver := left.substr(begin+1,cursor-begin-1)
370
- var chain := receiver.split(".")
371
- var members: Dictionary = {}
372
- if chain[0] == "self":
373
- for field in _symbols:
374
- if _symbols[field].owner.is_empty(): members[field] = _symbols[field]
375
- if chain[0] == "self": members.merge(_members(_base,_aliases),false)
376
- elif _symbols.has(chain[0]): members = _members(_symbols[chain[0]].type,_aliases)
377
- else: members = _members(chain[0],_aliases)
378
- for index in range(1,chain.size()): members = _members(str(members.get(chain[index],{}).get("type","")),_aliases)
379
- offered = members
494
+ elif member_cursor >= 0 and left[member_cursor] == ".":
495
+ var tokens := _chain_tokens(lexical,row,member_cursor)
496
+ offered = _receiver_members(tokens,tokens.size()-1,row)
497
+
380
498
  else:
381
499
  for word in Context.KEYWORDS: offered[word] = {"kind":CodeEdit.KIND_PLAIN_TEXT}
382
500
  for name in _classes: offered[name] = {"kind":CodeEdit.KIND_CLASS}
@@ -393,11 +511,14 @@ func candidates(text: String, source: String, lexical: RefCounted, row: int, col
393
511
  offered.clear()
394
512
  for name in ["bindable","tool","export","export_range","onready","warning_ignore"]: offered[name] = {"kind":CodeEdit.KIND_PLAIN_TEXT}
395
513
  var result: Array = []
514
+ var callable_attribute: bool = context.mode=="gd" and _callable_attribute(lexical,context,row,column)
396
515
  for name in offered:
397
516
  if (str(name).begins_with(prefix) or offered[name].has("match")) and (not str(name).begins_with("_") or prefix.begins_with("_") or _symbols.has(name)):
398
517
  var item: Dictionary = offered[name]
399
518
  var insert: String = item.get("insert",str(name).trim_prefix("bind:") if prefix.begins_with("bind:") else str(name))
400
- var display: String = str(name) if item.has("import") else (insert+" — "+str(item.origin) if item.has("origin") else insert)
519
+ if context.mode=="gd" and member_cursor>=0 and left[member_cursor]=="." and item.kind==CodeEdit.KIND_FUNCTION and not callable_attribute and not lexical.lines[row].substr(column).strip_edges().begins_with("("):
520
+ insert += "()"
521
+ var display: String = str(name) if item.has("import") else (str(name)+" — "+str(item.origin) if item.has("origin") else str(name))
401
522
  if context.mode == "tag" and not item.has("import") and ClassDB.class_exists(insert): display += " — Godot "+ClassDB.get_parent_class(insert)
402
523
  result.append({"text":display,"insert":insert,"kind":item.kind,"row":row,"start":cursor if context.mode == "tag" and context.closing else cursor+1,"column":column,"hint":item.get("hint",""),"imports":[item["import"]] if item.has("import") else []})
403
524
  result.sort_custom(func(a,b): return a.text < b.text)
@@ -0,0 +1,256 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Authenticated compiled views. Native editing/debug navigation stays native;
4
+ ## only verified Estragon output is protected. Recovery precedes replacement.
5
+ const Components = preload("scene_components.gd")
6
+ const Compiler = preload("../compiler/compiler.gd")
7
+ const RECOVERY := "user://estragon/generated-edits"
8
+ var plugin: EditorPlugin
9
+ var interface: EditorInterface
10
+ var navigation: RefCounted
11
+ var association: RefCounted
12
+ var entries: Dictionary = {}
13
+ var panel: MenuButton
14
+ var viewer: AcceptDialog
15
+ var preview: TextEdit
16
+ var location: TextEdit
17
+ var selected := 0
18
+ var active := true
19
+ var mutating := false
20
+ var problem := ""
21
+ var presentation := ""
22
+ var action: Callable
23
+ func _init(owner: EditorPlugin, navigator: RefCounted, adapter: RefCounted) -> void:
24
+ plugin = owner
25
+ interface = owner.get_editor_interface()
26
+ navigation = navigator
27
+ association = adapter
28
+ panel = MenuButton.new()
29
+ panel.name = "GogoGeneratedView"
30
+ plugin.add_control_to_container(EditorPlugin.CONTAINER_TOOLBAR,panel)
31
+ panel.hide()
32
+ interface.get_script_editor().visibility_changed.connect(_present)
33
+ viewer = AcceptDialog.new()
34
+ viewer.title = "Recovered generated edit — copy changes into the Gogo source"
35
+ viewer.min_size = Vector2i(760,460)
36
+ var box := VBoxContainer.new()
37
+ viewer.add_child(box)
38
+ # A wrapping Label can feed an unbounded minimum height back into a
39
+ # native Window before its first layout. Keep the selectable path bounded.
40
+ location = TextEdit.new()
41
+ location.editable = false
42
+ location.wrap_mode = TextEdit.LINE_WRAPPING_BOUNDARY
43
+ location.custom_minimum_size = Vector2(740,110)
44
+ box.add_child(location)
45
+ preview = TextEdit.new()
46
+ preview.editable = false
47
+ preview.custom_minimum_size = Vector2(740,360)
48
+ preview.size_flags_vertical = Control.SIZE_EXPAND_FILL
49
+ box.add_child(preview)
50
+ plugin.add_child(viewer)
51
+ func _verified(path: String) -> String:
52
+ var source := Components.source_path(path)
53
+ if source.is_empty() or not FileAccess.file_exists(source) or not FileAccess.file_exists(path): return ""
54
+ var map = JSON.parse_string(FileAccess.get_file_as_string(path+".map.json"))
55
+ if not map is Dictionary: return ""
56
+ if not map.get("sourceContent") is String or not map.get("segments") is Array: return ""
57
+ var text := FileAccess.get_file_as_string(path)
58
+ if map.has("generatedHash"):
59
+ return source if map.generatedHash == text.sha256_text() else ""
60
+ # Older v1 maps have no output hash. Authenticate by deterministic native
61
+ # emission of their recorded source; never guess from a folder/basename.
62
+ var result := Compiler.compile(map.sourceContent,map.sourceName,path)
63
+ return source if result.ok and result.code == text else ""
64
+ func _display(path: String) -> String:
65
+ return FileAccess.get_file_as_string(path).replace("\r\n","\n")
66
+ func _recovery_prefix(path: String) -> String:
67
+ return (ProjectSettings.globalize_path("res://").simplify_path()+"|"+path).sha256_text()+"-"
68
+ func _latest(path: String) -> String:
69
+ var directory := DirAccess.open(RECOVERY)
70
+ if directory == null: return ""
71
+ var prefix := _recovery_prefix(path)
72
+ var latest := ""
73
+ for name in directory.get_files():
74
+ var file := RECOVERY.path_join(name)
75
+ if name.begins_with(prefix) and name.ends_with(".txt") and (latest.is_empty() or name>latest.get_file()): latest = file
76
+ return latest
77
+ func attach(editor: ScriptEditorBase, code: TextEdit, path: String) -> void:
78
+ if not active or not code is CodeEdit: return
79
+ _present()
80
+ if path.is_empty(): return
81
+ var id := code.get_instance_id()
82
+ if entries.has(id):
83
+ if entries[id].path == path: return
84
+ _detach(id)
85
+ var source := _verified(path)
86
+ if source.is_empty(): return
87
+ var changed := _changed.bind(id)
88
+ var closing := _closed.bind(id)
89
+ entries[id] = {"editor":weakref(editor),"code":weakref(code),"path":path,"source":source,"editable":code.editable,"baseline":_display(path),"recovery":_latest(path),"changed":changed,"closing":closing,"blocked":false}
90
+ code.editable = false
91
+ code.text_changed.connect(changed)
92
+ code.text_set.connect(changed)
93
+ code.tree_exiting.connect(closing)
94
+ # Includes a dirty tab restored before the addon is enabled. Native input
95
+ # is already read-only; no byte is cleared until recovery is verified.
96
+ _changed(id)
97
+ _present()
98
+ func _preserve(entry: Dictionary, text: String) -> bool:
99
+ var file := RECOVERY.path_join(_recovery_prefix(entry.path)+str(int(Time.get_unix_time_from_system()*1000000))+"-"+text.sha256_text()+".txt")
100
+ var error := DirAccess.make_dir_recursive_absolute(ProjectSettings.globalize_path(RECOVERY))
101
+ if error == OK:
102
+ var output := FileAccess.open(file,FileAccess.WRITE)
103
+ if output != null:
104
+ output.store_buffer(text.to_utf8_buffer())
105
+ output.flush()
106
+ error = output.get_error()
107
+ output.close()
108
+ else: error = FileAccess.get_open_error()
109
+ if error != OK or not FileAccess.file_exists(file) or FileAccess.get_file_as_bytes(file) != text.to_utf8_buffer():
110
+ entry.blocked = true
111
+ problem = entry.path+": Cannot preserve edited generated buffer. Save/Play blocked; copy the visible edit before continuing. Recovery: "+ProjectSettings.globalize_path(file)
112
+ return false
113
+ entry.recovery = file
114
+ entry.blocked = false
115
+ return true
116
+ func _changed(id: int) -> void:
117
+ if not active or mutating or not entries.has(id): return
118
+ var entry: Dictionary = entries[id]
119
+ var code = entry.code.get_ref()
120
+ if code == null: return
121
+ if code.text != entry.baseline:
122
+ # Native external reload can already contain a newly authenticated build.
123
+ if code.text == _display(entry.path) and not _verified(entry.path).is_empty(): entry.baseline = code.text
124
+ elif not _preserve(entry,code.text): _present(); return
125
+ else: _replace(entry,entry.baseline)
126
+ _present()
127
+ func _replace(entry: Dictionary, text: String) -> void:
128
+ text = text.replace("\r\n","\n")
129
+ var code = entry.code.get_ref()
130
+ if code == null: return
131
+ mutating = true
132
+ var line: int = code.get_caret_line()
133
+ var column: int = code.get_caret_column()
134
+ var vertical: float = code.scroll_vertical
135
+ var horizontal: int = code.scroll_horizontal
136
+ var breakpoints: PackedInt32Array = code.get_breakpointed_lines()
137
+ if code.text != text:
138
+ # Whole-buffer assignment clears CodeEdit gutters and emits native
139
+ # breakpoint removals. Update line contents instead, retaining native
140
+ # inspection state on existing lines (including unchanged breakpoints).
141
+ var lines := text.split("\n")
142
+ code.begin_complex_operation()
143
+ while code.get_line_count() < lines.size(): code.insert_line_at(code.get_line_count()-1,"")
144
+ while code.get_line_count() > lines.size():
145
+ var last: int = code.get_line_count()-1
146
+ code.remove_text(last-1,code.get_line(last-1).length(),last,code.get_line(last).length())
147
+ for index in range(lines.size()):
148
+ if code.get_line(index) != lines[index]: code.set_line(index,lines[index])
149
+ code.end_complex_operation()
150
+ for marked_line in breakpoints:
151
+ if marked_line < code.get_line_count() and not code.is_line_breakpointed(marked_line): code.set_line_as_breakpoint(marked_line,true)
152
+ code.set_caret_line(line)
153
+ code.set_caret_column(column)
154
+ code.scroll_vertical = vertical
155
+ code.scroll_horizontal = horizontal
156
+ code.tag_saved_version()
157
+ entry.baseline = text
158
+ mutating = false
159
+ func prepare() -> bool:
160
+ problem = ""
161
+ for editor in interface.get_script_editor().get_open_script_editors():
162
+ var code = editor.get_base_editor()
163
+ if code is CodeEdit: attach(editor,code,_path(editor,code))
164
+ for id in entries.keys():
165
+ _changed(id)
166
+ if entries.has(id) and entries[id].blocked:
167
+ if problem.is_empty(): problem = entries[id].path+": Generated edit recovery failed; save/build blocked."
168
+ _present()
169
+ return problem.is_empty()
170
+ func _path(editor: ScriptEditorBase, code: TextEdit) -> String:
171
+ var scripts := interface.get_script_editor()
172
+ var script := scripts.get_current_script()
173
+ if script != null and scripts.get_current_editor() == editor: return script.resource_path
174
+ return association._path(editor,code,false)
175
+ func refresh() -> void:
176
+ for entry in entries.values():
177
+ if not entry.blocked and not _verified(entry.path).is_empty(): _replace(entry,FileAccess.get_file_as_string(entry.path))
178
+ _present()
179
+ func _present() -> void:
180
+ if not active: return
181
+ selected = 0
182
+ var editor := interface.get_script_editor().get_current_editor()
183
+ for id in entries:
184
+ if entries[id].editor.get_ref() == editor: selected = id; break
185
+ panel.visible = selected != 0 and interface.get_script_editor().is_visible_in_tree()
186
+ if selected == 0:
187
+ # A missing source cannot authorize read-only or synchronization. Still
188
+ # explain its map claim on the selected native Script without redirecting.
189
+ var code = editor.get_base_editor() if editor != null else null
190
+ var source := Components.source_path(_path(editor,code)) if code is CodeEdit else ""
191
+ if not source.is_empty() and not FileAccess.file_exists(source):
192
+ panel.visible = interface.get_script_editor().is_visible_in_tree()
193
+ panel.text = "Gogo source missing"
194
+ panel.tooltip_text = "Unverified source association: "+source+". Restore the source; this tab remains editable."
195
+ if presentation != source:
196
+ presentation = source
197
+ var popup := panel.get_popup()
198
+ if action.is_valid() and popup.id_pressed.is_connected(action): popup.id_pressed.disconnect(action)
199
+ action = Callable()
200
+ popup.clear()
201
+ popup.add_item("Gogo source missing — restore "+source)
202
+ popup.set_item_disabled(0,true)
203
+ return
204
+ var entry: Dictionary = entries[selected]
205
+ var exists := FileAccess.file_exists(entry.source)
206
+ panel.text = "Generated: "+entry.source.get_file()
207
+ if not entry.recovery.is_empty(): panel.text = "Generated · edit recovered"
208
+ var status := "Read-only — edit the Gogo source"
209
+ if not exists: status = "Gogo source missing — restore it before editing"
210
+ elif _verified(entry.path).is_empty(): status = "Source map unavailable/changed — inspect only"
211
+ if entry.blocked:
212
+ status = "Recovery failed — Save/Play blocked"
213
+ panel.text = "Recovery failed!"
214
+ panel.tooltip_text = status+"\n"+entry.path+"\nGogo source: "+entry.source
215
+ var signature: String = str(selected)+status+entry.recovery+str(exists)
216
+ if signature == presentation: return
217
+ presentation = signature
218
+ var popup := panel.get_popup()
219
+ if action.is_valid() and popup.id_pressed.is_connected(action): popup.id_pressed.disconnect(action)
220
+ action = _action.bind(entry.source,entry.path,entry.recovery)
221
+ popup.id_pressed.connect(action,CONNECT_DEFERRED)
222
+ popup.clear()
223
+ popup.add_item(status,0)
224
+ popup.set_item_disabled(0,true)
225
+ popup.add_item("Open Gogo Source",1)
226
+ popup.set_item_disabled(1,not exists)
227
+ popup.add_separator()
228
+ popup.add_item("View Recovered Edit"+(" (preserved)" if not entry.recovery.is_empty() else ""),2)
229
+ popup.set_item_disabled(popup.get_item_index(2),entry.recovery.is_empty())
230
+ func _action(id: int, source: String, path: String, recovery: String) -> void:
231
+ if not active: return
232
+ if id == 1 and FileAccess.file_exists(source):
233
+ await navigation.open(source)
234
+ elif id == 2 and FileAccess.file_exists(recovery):
235
+ location.text = "Preserved edit for "+path+"\n"+ProjectSettings.globalize_path(recovery)+"\nOlder recovered versions remain in this directory. Copy intended changes into "+source+"."
236
+ preview.text = FileAccess.get_file_as_string(recovery)
237
+ viewer.popup_centered()
238
+ func _closed(id: int) -> void:
239
+ if entries.has(id): _detach(id)
240
+ func _detach(id: int) -> void:
241
+ var entry: Dictionary = entries[id]
242
+ var code = entry.code.get_ref()
243
+ if code != null:
244
+ for pair in [["text_changed","changed"],["text_set","changed"],["tree_exiting","closing"]]:
245
+ if code.is_connected(pair[0],entry[pair[1]]): code.disconnect(pair[0],entry[pair[1]])
246
+ code.editable = entry.editable
247
+ entries.erase(id)
248
+ func stop() -> void:
249
+ active = false
250
+ for id in entries.keys(): _detach(id)
251
+ interface.get_script_editor().visibility_changed.disconnect(_present)
252
+ if action.is_valid() and panel.get_popup().id_pressed.is_connected(action): panel.get_popup().id_pressed.disconnect(action)
253
+ action = Callable()
254
+ plugin.remove_control_from_container(EditorPlugin.CONTAINER_TOOLBAR,panel)
255
+ panel.free()
256
+ viewer.free()
@@ -0,0 +1 @@
1
+ uid://g6qi8b62ebi5
@@ -3,5 +3,5 @@
3
3
  name="Estragon"
4
4
  description="Native Gogo/GGX highlighting, compilation and validation before Play."
5
5
  author="Resist Design"
6
- version="0.1.0-beta.10"
6
+ version="0.1.0-beta.12"
7
7
  script="plugin.gd"