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

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.
@@ -261,9 +261,9 @@ static func creation_check(path: String) -> Dictionary:
261
261
  if not path.begins_with("res://") or path.get_extension() != "gogo" or "\\" in relative or ":" in relative:
262
262
  return {"ok":false,"message":"Choose a .gogo file beneath res://."}
263
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."}
264
+ 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."}
265
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."}
266
+ return {"ok":false,"message":"A file or directory already exists. New Gogo Component never overwrites existing source; choose another filename."}
267
267
  if not DirAccess.dir_exists_absolute(path.get_base_dir()): return {"ok":false,"message":"Create/select an existing project directory first."}
268
268
  var check := new()
269
269
  check._project = ProjectSettings.globalize_path("res://").trim_suffix("/")
@@ -1,9 +1,15 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  ## Lexical declarations + public ClassDB metadata. No authored Script loads/new().
4
+ const Validator = preload("../compiler/validator.gd")
5
+ const Source = preload("../compiler/source.gd")
4
6
  const Context = preload("lexical_context.gd")
7
+ const Catalog = preload("components.gd")
8
+ const Imports = preload("imports.gd")
5
9
  const Build = preload("build_service.gd")
6
10
  var sources: Dictionary = {}
11
+ var metadata: Dictionary = {}
12
+ var metadata_reads := 0
7
13
  var _script_cache: Dictionary = {}
8
14
  var _classes: PackedStringArray = []
9
15
  var _text := ""
@@ -13,6 +19,7 @@ var _aliases: Dictionary = {}
13
19
  var _owners: Dictionary = {}
14
20
  var _base := "Node"
15
21
  var _native_cache: Dictionary = {}
22
+ var _types = Validator.new(Source.new(""))
16
23
 
17
24
  func _init() -> void:
18
25
  _classes = ClassDB.get_class_list()
@@ -20,6 +27,7 @@ func invalidate() -> void:
20
27
  _text = ""
21
28
  _native_cache.clear()
22
29
  _script_cache.clear()
30
+ metadata.clear()
23
31
  func _tokens(text: String) -> Array:
24
32
  var context := Context.new()
25
33
  context.update(text)
@@ -67,6 +75,7 @@ func _declarations(text: String, source: String) -> Dictionary:
67
75
  var type := ""
68
76
  if index+3 < tokens.size() and tokens[index+2].text == ":": type = tokens[index+3].text
69
77
  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))))}
78
+ if word == "func": symbols[name].hint = text.split("\n")[tokens[index].row].strip_edges().trim_prefix("func ").trim_suffix(":")
70
79
  if word == "signal":
71
80
  var args: Array = []
72
81
  for cursor in range(index+2,mini(index+28,tokens.size()-1)):
@@ -86,7 +95,7 @@ func _declarations(text: String, source: String) -> Dictionary:
86
95
  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)
87
96
  # Typed arguments/local declarations also contribute names, never inferred values.
88
97
  for index in range(1,tokens.size()-2):
89
- if tokens[index].text == ":" and tokens[index-1].text.is_valid_identifier() and tokens[index+1].text.is_valid_identifier():
98
+ 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:
90
99
  var name: String = tokens[index-1].text
91
100
  if not symbols.has(name): symbols[name] = {"type":tokens[index+1].text,"owner":owners.get(tokens[index].row,""),"kind":CodeEdit.KIND_VARIABLE}
92
101
  return {"symbols":symbols,"aliases":aliases,"base":base,"owners":owners,"required_initializer":required_initializer}
@@ -104,6 +113,37 @@ func _script(path: String) -> Dictionary:
104
113
  if not _script_cache.has(path) or _script_cache[path].text != text:
105
114
  _script_cache[path] = {"text":text,"declarations":_declarations(text,path)}
106
115
  return _script_cache[path].declarations
116
+ func _type_name(info: Dictionary) -> String:
117
+ var class_name_value: String = str(info.get("class_name",""))
118
+ if not class_name_value.is_empty(): return class_name_value
119
+ if info.get("type",TYPE_NIL) == TYPE_NIL: return "Variant" if int(info.get("usage",0)) & PROPERTY_USAGE_NIL_IS_VARIANT else "void"
120
+ var normalized := info.duplicate()
121
+ normalized.type = info.get("type",TYPE_NIL)
122
+ return _types._native_type(normalized)
123
+ func _method_hint(method: Dictionary) -> String:
124
+ var args: Array = []
125
+ for arg in method.get("args",[]): args.append(str(arg.name)+": "+_type_name(arg))
126
+ return str(method.name)+"("+", ".join(args)+") -> "+_type_name(method.get("return",{}))
127
+ func call_hint(text: String, source: String, lexical: RefCounted, row: int, column: int) -> String:
128
+ _index(text,source)
129
+ lexical.update(text)
130
+ var state: Dictionary = lexical.context(row,column)
131
+ if state.suppressed or state.mode != "gd": return ""
132
+ var tokens := _tokens(lexical.lines[row].left(column))
133
+ var depth := 0
134
+ for index in range(tokens.size()-1,-1,-1):
135
+ if tokens[index].text == ")": depth += 1
136
+ if tokens[index].text != "(": continue
137
+ if depth > 0: depth -= 1; continue
138
+ if index == 0: return ""
139
+ var name: String = tokens[index-1].text
140
+ var members := _members(_base,_aliases)
141
+ if index >= 3 and tokens[index-2].text == ".":
142
+ var receiver: String = tokens[index-3].text
143
+ if receiver != "self": members = _members(str(_symbols.get(receiver,{}).get("type",receiver)),_aliases)
144
+ else: members.merge(_symbols,true)
145
+ return str(members.get(name,{}).get("hint",""))
146
+ return ""
107
147
  func _members(type: String, aliases: Dictionary, visited: Array = []) -> Dictionary:
108
148
  var name: String = aliases.get(type,type)
109
149
  if name.is_empty() or name in visited or visited.size() >= 12: return {}
@@ -111,9 +151,9 @@ func _members(type: String, aliases: Dictionary, visited: Array = []) -> Diction
111
151
  if _native_cache.has(name): return _native_cache[name]
112
152
  var result: Dictionary = {}
113
153
  for prop in ClassDB.class_get_property_list(name):
114
- if not str(prop.name).contains("/"):
115
- result[prop.name] = {"type":str(prop.get("class_name","")),"kind":CodeEdit.KIND_MEMBER,"value_type":prop.type,"writable":not (int(prop.usage)&PROPERTY_USAGE_READ_ONLY)}
116
- for method in ClassDB.class_get_method_list(name): result[method.name] = {"type":"","kind":CodeEdit.KIND_FUNCTION}
154
+ if str(prop.name).is_valid_identifier() and not (int(prop.usage) & (PROPERTY_USAGE_CATEGORY|PROPERTY_USAGE_GROUP|PROPERTY_USAGE_SUBGROUP)):
155
+ result[prop.name] = {"type":_type_name(prop),"kind":CodeEdit.KIND_MEMBER,"value_type":prop.type,"writable":not (int(prop.usage)&PROPERTY_USAGE_READ_ONLY)}
156
+ 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)}
117
157
  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)}
118
158
  _native_cache[name] = result
119
159
  return result
@@ -126,6 +166,15 @@ func _members(type: String, aliases: Dictionary, visited: Array = []) -> Diction
126
166
  if not FileAccess.file_exists(name): return {}
127
167
  var declarations := _script(name)
128
168
  var result := _members(declarations.base,declarations.aliases,visited+[name])
169
+ # Existing cached metadata only; never reload/new authored scripts.
170
+ if not sources.has(name):
171
+ var cached = metadata.get(name)
172
+ if cached == null and ResourceLoader.has_method("get_cached_ref"): cached = ResourceLoader.call("get_cached_ref",name)
173
+ if cached is Script and cached.source_code == _script_cache[name].text:
174
+ metadata_reads += 1
175
+ for prop in cached.get_script_property_list():
176
+ 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)}
177
+ 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)}
129
178
  for field in declarations.symbols:
130
179
  if declarations.symbols[field].owner.is_empty(): result[field] = declarations.symbols[field]
131
180
  return result
@@ -142,11 +191,76 @@ func _node_type(type: String, aliases: Dictionary, visited: Array = []) -> bool:
142
191
  if not FileAccess.file_exists(name): return false
143
192
  var declarations := _script(name)
144
193
  return not declarations.required_initializer and _node_type(declarations.base,declarations.aliases,visited+[name])
194
+ func _catalog_options(prefix: String, tags: bool) -> Dictionary:
195
+ var result: Dictionary = {}
196
+ var dimension := 3 if _base == "Node3D" or ClassDB.class_exists(_base) and ClassDB.is_parent_class(_base,"Node3D") else (2 if _base == "Node2D" or ClassDB.class_exists(_base) and ClassDB.is_parent_class(_base,"Node2D") else 0)
197
+ for item in Catalog.ITEMS:
198
+ if tags and (item.dimension == 0 or dimension != 0 and item.dimension != dimension): continue
199
+ if not tags and item.dimension != 0: continue
200
+ var alias: String = Imports.alias_for(item,_symbols,_aliases)
201
+ var label: String = item.canonical if str(item.canonical).begins_with(prefix) and not str(item.alias).begins_with(prefix) else item.alias
202
+ if not label.begins_with(prefix) and not alias.begins_with(prefix): continue
203
+ if alias != item.alias: label += " (as "+alias+")"
204
+ result[label+" — "+item.canonical+" ("+item.origin+")"] = {"kind":CodeEdit.KIND_CLASS,"insert":alias,"import":{"alias":alias,"path":Catalog.path(item)},"match":prefix}
205
+ return result
206
+ func _path_options(left: String, context: Dictionary, source: String, row: int, column: int) -> Array:
207
+ if context.quote.length() != 1: return []
208
+ var start := -1
209
+ for token in context.tokens:
210
+ if token.kind == "string" and token.text == context.quote: start = token.start
211
+ if start < 0: return []
212
+ var before := left.left(start).strip_edges()
213
+ var tokens := _tokens(before)
214
+ if tokens.is_empty(): return []
215
+ var allowed: bool = tokens[-1].text == "extends" or tokens.size() >= 2 and tokens[-1].text == "(" and tokens[-2].text in ["load","preload"]
216
+ if not allowed: return []
217
+ var value := left.substr(start+1)
218
+ if "\\" in value or value.contains("\"") or value.contains("'") or value.begins_with("user://") or value.is_absolute_path() and not value.begins_with("res://"): return []
219
+ var base := Build.output_for(source).get_base_dir()
220
+ var slash := value.rfind("/")
221
+ var directory := value.left(slash+1) if slash >= 0 else ""
222
+ var prefix := value.substr(slash+1)
223
+ var target := directory if directory.begins_with("res://") else base.path_join(directory).simplify_path()
224
+ if not target.begins_with("res://") or target.contains("/../"): return []
225
+ for part in target.trim_prefix("res://").split("/"):
226
+ if part.begins_with("."): return []
227
+ if target != "res://":
228
+ var containment := Build.new()
229
+ containment._project = ProjectSettings.globalize_path("res://").trim_suffix("/")
230
+ if not containment._safe(ProjectSettings.globalize_path(target).trim_suffix("/")): return []
231
+ var access := DirAccess.open(target)
232
+ if access == null: return []
233
+ var result: Array = []
234
+ var extensions := ResourceLoader.get_recognized_extensions_for_type("")
235
+ access.list_dir_begin()
236
+ var name := access.get_next()
237
+ while not name.is_empty() and result.size() < 256:
238
+ if not name.begins_with(".") and name.begins_with(prefix) and (not access.has_method("is_link") or not access.call("is_link",name)) and (access.current_is_dir() or name.get_extension() in extensions):
239
+ var is_dir := access.current_is_dir()
240
+ var insert: String = context.quote+directory+name+("/" if is_dir else context.quote)
241
+ result.append({"text":insert,"insert":insert,"kind":CodeEdit.KIND_FILE_PATH,"row":row,"start":start,"column":column,"path":true})
242
+ name = access.get_next()
243
+ access.list_dir_end()
244
+ return result
245
+ func import_plan(text: String, source: String, requests: Array = []) -> Dictionary:
246
+ _index(text,source)
247
+ if requests.is_empty():
248
+ var lexical := Context.new()
249
+ lexical.update(text)
250
+ for row in range(lexical.lines.size()):
251
+ for token in lexical.line(row).tokens:
252
+ if token.kind != "tag" or not token.text.is_valid_identifier(): continue
253
+ var item := Catalog.named(token.text)
254
+ if not item.is_empty() and item.dimension != 0 and not _symbols.has(token.text): requests.append({"alias":token.text,"path":Catalog.path(item)})
255
+ return Imports.plan(text,source,requests,_symbols,_aliases,_tokens(text))
256
+ func definition(text: String, source: String, symbol: String) -> String:
257
+ _index(text,source)
258
+ return _aliases.get(symbol,"")
145
259
  func candidates(text: String, source: String, lexical: RefCounted, row: int, column: int) -> Array:
146
260
  _index(text,source)
147
261
  lexical.update(text)
148
262
  var context: Dictionary = lexical.context(row,column)
149
- if context.suppressed: return []
263
+ if context.suppressed: return _path_options(lexical.lines[row].left(column),context,source,row,column)
150
264
  var left: String = lexical.lines[row].left(column)
151
265
  var prefix := ""
152
266
  var cursor := left.length()-1
@@ -162,9 +276,15 @@ func candidates(text: String, source: String, lexical: RefCounted, row: int, col
162
276
  for name in _classes:
163
277
  if ClassDB.is_parent_class(name,"Node") and ClassDB.can_instantiate(name): offered[name] = {"kind":CodeEdit.KIND_CLASS}
164
278
  for name in _aliases:
165
- if _node_type(name,_aliases): offered[name] = {"kind":CodeEdit.KIND_CLASS}
279
+ if _node_type(name,_aliases): offered[name] = {"kind":CodeEdit.KIND_CLASS,"origin":"explicit Node preload"}
166
280
  for entry in ProjectSettings.get_global_class_list():
167
- if str(entry["class"]).begins_with(prefix) and _node_type(str(entry["class"]),{}): offered[entry["class"]] = {"kind":CodeEdit.KIND_CLASS}
281
+ var known := Catalog.named(str(entry["class"]))
282
+ if not known.is_empty() and Catalog.path(known) == str(entry.path): continue
283
+ if str(entry["class"]).begins_with(prefix) and _node_type(str(entry["class"]),{}): offered[entry["class"]] = {"kind":CodeEdit.KIND_CLASS,"origin":"project Node"}
284
+ for item in Catalog.ITEMS:
285
+ for alias in _aliases:
286
+ if _aliases[alias] == Catalog.path(item): offered.erase(alias)
287
+ offered.merge(_catalog_options(prefix,true))
168
288
  else:
169
289
  if not _node_type(context.tag,_aliases): return []
170
290
  var members := _members(context.tag,_aliases)
@@ -190,16 +310,25 @@ func candidates(text: String, source: String, lexical: RefCounted, row: int, col
190
310
  else:
191
311
  for word in Context.KEYWORDS: offered[word] = {"kind":CodeEdit.KIND_PLAIN_TEXT}
192
312
  for name in _classes: offered[name] = {"kind":CodeEdit.KIND_CLASS}
313
+ for native_type in range(1,TYPE_MAX):
314
+ var type_name: String = _types._native_type({"type":native_type})
315
+ if not type_name.is_empty(): offered[type_name] = {"kind":CodeEdit.KIND_CLASS}
316
+ offered.Variant = {"kind":CodeEdit.KIND_CLASS}
193
317
  for entry in ProjectSettings.get_global_class_list(): offered[entry["class"]] = {"kind":CodeEdit.KIND_CLASS}
194
318
  for field in _symbols:
195
319
  if _symbols[field].owner.is_empty() or _symbols[field].owner == _owners.get(row,""): offered[field] = _symbols[field]
196
320
  offered.merge(_members(_base,_aliases),false)
321
+ offered.merge(_catalog_options(prefix,false))
197
322
  if cursor >= 0 and left[cursor] == "@":
198
323
  offered.clear()
199
324
  for name in ["bindable","tool","export","export_range","onready","warning_ignore"]: offered[name] = {"kind":CodeEdit.KIND_PLAIN_TEXT}
200
325
  var result: Array = []
201
326
  for name in offered:
202
- if str(name).begins_with(prefix) and (not str(name).begins_with("_") or prefix.begins_with("_") or _symbols.has(name)):
203
- result.append({"text":str(name).trim_prefix("bind:") if prefix.begins_with("bind:") else str(name),"kind":offered[name].kind})
327
+ 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)):
328
+ var item: Dictionary = offered[name]
329
+ var insert: String = item.get("insert",str(name).trim_prefix("bind:") if prefix.begins_with("bind:") else str(name))
330
+ var display: String = str(name) if item.has("import") else (insert+" — "+str(item.origin) if item.has("origin") else insert)
331
+ if context.mode == "tag" and not item.has("import") and ClassDB.class_exists(insert): display += " — Godot "+ClassDB.get_parent_class(insert)
332
+ 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 []})
204
333
  result.sort_custom(func(a,b): return a.text < b.text)
205
334
  return result
@@ -0,0 +1,7 @@
1
+ @tool
2
+ extends CodeEdit
3
+ ## Documented public virtual. Attached only to otherwise scriptless Gogo editors.
4
+ ## Popup navigation and confirmation gestures remain native; commit is synchronous.
5
+ var estragon_accept: Callable
6
+ func _confirm_code_completion(replace: bool) -> void:
7
+ if estragon_accept.is_valid(): estragon_accept.call(replace)
@@ -0,0 +1 @@
1
+ uid://6anm2in7ldm
@@ -0,0 +1,18 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Trusted installed resources, not guessed global classes or installation roots.
4
+ const ITEMS := [
5
+ {"alias":"Text","canonical":"EstragonText","script":preload("../runtime/node/text.gd"),"dimension":2,"origin":"native widget"},
6
+ {"alias":"Rect","canonical":"EstragonRect","script":preload("../runtime/node/rect.gd"),"dimension":2,"origin":"native widget"},
7
+ {"alias":"UiButton","canonical":"EstragonButton","script":preload("../runtime/node/button.gd"),"dimension":2,"origin":"native widget"},
8
+ {"alias":"VBox","canonical":"EstragonVBox","script":preload("../runtime/node/vbox.gd"),"dimension":2,"origin":"native layout"},
9
+ {"alias":"HBox","canonical":"EstragonHBox","script":preload("../runtime/node/hbox.gd"),"dimension":2,"origin":"native layout"},
10
+ {"alias":"Entry2D","canonical":"Estragon2D","script":preload("../runtime/node/estragon_2d.gd"),"dimension":2,"origin":"layout entry"},
11
+ {"alias":"Entry3D","canonical":"Estragon3D","script":preload("../runtime/node/estragon_3d.gd"),"dimension":3,"origin":"layout entry"},
12
+ {"alias":"Element","canonical":"Element","script":preload("../runtime/composition/element.gd"),"dimension":0,"origin":"GGX description type"}
13
+ ]
14
+ static func path(item: Dictionary) -> String: return (item.script as Script).resource_path
15
+ static func named(name: String) -> Dictionary:
16
+ for item in ITEMS:
17
+ if name in [item.alias,item.canonical]: return item
18
+ return {}
@@ -0,0 +1 @@
1
+ uid://1lt6a67tepd
@@ -0,0 +1,12 @@
1
+ @tool
2
+ extends EditorContextMenuPlugin
3
+ ## Parsed only when the public native context-menu API is available.
4
+ var create: Callable
5
+ var root_context := false
6
+ func _popup_menu(paths: PackedStringArray) -> void:
7
+ root_context = paths.is_empty()
8
+ add_context_menu_item("New Gogo Component…" if paths.is_empty() else "Gogo Component…",_selected)
9
+ func _selected(paths: PackedStringArray) -> void:
10
+ # The engine supplies a current directory to callbacks even when popup
11
+ # paths were empty. Empty-space creation deliberately starts at project root.
12
+ if create.is_valid(): create.call(paths[0] if not root_context and not paths.is_empty() else "res://")
@@ -12,6 +12,8 @@ const EXPRESSION := Color("eed49f")
12
12
  var settings: EditorSettings
13
13
  var lexical = Context.new()
14
14
  var _version := -1
15
+ var _preview: TextEdit
16
+ var _native: SyntaxHighlighter
15
17
  const PALETTE := {"code":["text_color",CODE], "keyword":["keyword_color",KEYWORD], "tag":["user_type_color",TAG], "property":["member_variable_color",PROPERTY], "string":["string_color",STRING], "comment":["comment_color",COMMENT], "expression":["symbol_color",EXPRESSION], "symbol":["symbol_color",EXPRESSION], "number":["number_color",Color("a1ffe0")], "type":["base_type_color",TAG], "function":["function_color",Color("57b3ff")], "annotation":["annotation_color",KEYWORD]}
16
18
 
17
19
  func _init(editor_settings: EditorSettings = null) -> void:
@@ -20,19 +22,54 @@ func _create() -> EditorSyntaxHighlighter:
20
22
  return get_script().new(settings)
21
23
  func _get_name() -> String: return "Gogo"
22
24
  func _get_supported_languages() -> PackedStringArray: return PackedStringArray(["gogo"])
23
- func _clear_highlighting_cache() -> void: _version = -1
25
+ func _clear_highlighting_cache() -> void:
26
+ _version = -1
27
+ if _native != null: _native.update_cache()
24
28
  func color(kind: String) -> Color:
25
29
  var entry: Array = PALETTE.get(kind,PALETTE.code)
26
30
  var key: String = "text_editor/theme/highlighting/"+entry[0]
27
31
  return settings.get_setting(key) if settings != null and settings.has_setting(key) else entry[1]
32
+ func _notification(what: int) -> void:
33
+ if what == NOTIFICATION_PREDELETE and is_instance_valid(_preview):
34
+ _preview.free()
35
+ _preview = null
36
+ func uses_native() -> bool: return _native != null
37
+ func _ensure_native() -> void:
38
+ if _native != null or not Engine.is_editor_hint(): return
39
+ if ClassDB.class_exists("GDScriptSyntaxHighlighter") and ClassDB.can_instantiate("GDScriptSyntaxHighlighter"):
40
+ _native = ClassDB.instantiate("GDScriptSyntaxHighlighter")
41
+ _preview = TextEdit.new()
42
+ _preview.syntax_highlighter = _native
43
+ func _native_color(colors: Dictionary, column: int) -> Color:
44
+ var result := color("code")
45
+ var keys := colors.keys()
46
+ keys.sort()
47
+ for key in keys:
48
+ if key > column: break
49
+ result = colors[key].color
50
+ return result
28
51
  func _get_line_syntax_highlighting(index: int) -> Dictionary:
29
52
  var edit := get_text_edit()
30
53
  if edit == null: return {}
54
+ _ensure_native()
31
55
  if _version != edit.get_version():
32
56
  lexical.update(edit.text)
33
57
  _version = edit.get_version()
34
- var result := {0:{"color":color("code")}}
58
+ if _native != null:
59
+ var masked: Array = []
60
+ for row in range(lexical.lines.size()):
61
+ var line: String = lexical.lines[row]
62
+ # Keep all code-point columns/newlines; markup cannot poison native
63
+ # GDScript string/comment state across a GGX island. No compilation.
64
+ for token in lexical.line(row).tokens:
65
+ if not token.native: line = line.left(token.start)+" ".repeat(token.end-token.start)+line.substr(token.end)
66
+ masked.append(line)
67
+ _preview.text = "\n".join(masked)
68
+ _native.update_cache()
69
+ var native_colors: Dictionary = _native.get_line_syntax_highlighting(index) if _native != null else {}
70
+ var result: Dictionary = native_colors.duplicate(true) if _native != null else {0:{"color":color("code")}}
35
71
  for token in lexical.line(index).tokens:
72
+ if _native != null and token.native and not (token.kind == "annotation" and token.text == "bindable"): continue
36
73
  result[token.start] = {"color":color(token.kind)}
37
- result[token.end] = {"color":color("code")}
74
+ result[token.end] = {"color":_native_color(native_colors,token.end) if _native != null else color("code")}
38
75
  return result
@@ -0,0 +1,47 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Pure bounded edit plans. No saves, generated writes or authored Script loads.
4
+ const Build = preload("build_service.gd")
5
+ const Source = preload("../compiler/source.gd")
6
+ const Catalog = preload("components.gd")
7
+ static func occupied(name: String, resource: String, symbols: Dictionary) -> bool:
8
+ if symbols.has(name) or ClassDB.class_exists(name): return true
9
+ for entry in ProjectSettings.get_global_class_list():
10
+ if str(entry["class"]) == name and str(entry.path) != resource: return true
11
+ return false
12
+ static func alias_for(item: Dictionary, symbols: Dictionary, aliases: Dictionary) -> String:
13
+ for name in aliases:
14
+ if aliases[name] == Catalog.path(item): return name
15
+ var name: String = item.alias
16
+ if occupied(name,Catalog.path(item),symbols): name = item.canonical
17
+ var stem := name
18
+ var suffix := 2
19
+ while occupied(name,Catalog.path(item),symbols):
20
+ name = stem+str(suffix)
21
+ suffix += 1
22
+ return name
23
+ static func declaration(name: String, resource: String, source: String) -> String:
24
+ return "const "+name+" = preload("+JSON.stringify(Source.relative_path(Build.output_for(source).get_base_dir(),resource))+")\n"
25
+ static func plan(text: String, source: String, requested: Array, symbols: Dictionary, aliases: Dictionary, tokens: Array) -> Dictionary:
26
+ var declarations: Array = []
27
+ var names: Dictionary = aliases.duplicate()
28
+ for request in requested:
29
+ if names.get(request.alias) == request.path: continue
30
+ # Caller resolves collisions explicitly; never replace an authored name.
31
+ if occupied(request.alias,request.path,symbols) or names.has(request.alias): continue
32
+ declarations.append(declaration(request.alias,request.path,source))
33
+ names[request.alias] = request.path
34
+ # A first build_view()->Element needs the explicit composition resource too.
35
+ if not occupied("Element",Catalog.path(Catalog.named("Element")),symbols) and not names.has("Element"):
36
+ for index in range(tokens.size()-1):
37
+ if tokens[index].text == "->" and tokens[index+1].text == "Element":
38
+ declarations.push_front(declaration("Element",Catalog.path(Catalog.named("Element")),source))
39
+ break
40
+ var row := 0
41
+ for token in tokens:
42
+ if token.indent == 0 and token.text in ["extends","class_name"]: row = maxi(row,int(token.row)+1)
43
+ # Preserve file-level tool/icon annotations when no extends header exists yet.
44
+ if row == 0:
45
+ var lines := text.split("\n")
46
+ while row < lines.size() and (lines[row].strip_edges().is_empty() or lines[row].strip_edges().begins_with("#") or lines[row].begins_with("@tool") or lines[row].begins_with("@icon")): row += 1
47
+ return {"row":mini(row,text.count("\n")),"text":"".join(declarations)}
@@ -0,0 +1 @@
1
+ uid://ckzxzc2w16s
@@ -3,6 +3,8 @@ extends Node
3
3
  ## Owns only authenticated Gogo CodeEdit connections and a dedicated gutter.
4
4
  signal diagnostics_changed(records, phase)
5
5
  const Context = preload("lexical_context.gd")
6
+ const Acceptance = preload("completion_edit.gd")
7
+ const Catalog = preload("components.gd")
6
8
  const Completion = preload("completion.gd")
7
9
  const Source = preload("../compiler/source.gd")
8
10
  const Parser = preload("../compiler/parser.gd")
@@ -30,7 +32,13 @@ func attach(editor: ScriptEditorBase, code: CodeEdit, path: String) -> void:
30
32
  if entries[id].path == path: return
31
33
  _detach(id)
32
34
  if not path.ends_with(".gogo"): return
33
- entries[id] = {"code":weakref(code),"editor":weakref(editor),"path":path,"model":Completion.new(),"lexical":Context.new(),"records":[],"pending":true,"marked":[],"line_count":code.get_line_count(),"enabled":code.code_completion_enabled,"prefixes":code.code_completion_prefixes,"request":_complete.bind(id),"edit":_changed.bind(id),"gutter":_gutter_clicked.bind(id),"theme":_theme_changed.bind(id),"closing":_closed.bind(id)}
35
+ entries[id] = {"code":weakref(code),"editor":weakref(editor),"path":path,"model":Completion.new(),"lexical":Context.new(),"records":[],"pending":true,"marked":[],"line_count":code.get_line_count(),"mutating":false,"snapshot":-1,"script":code.get_script(),"lookup_enabled":code.symbol_lookup_on_click,"lookup":_lookup.bind(id),"caret":_hint.bind(id),"enabled":code.code_completion_enabled,"prefixes":code.code_completion_prefixes,"request":_complete.bind(id),"edit":_changed.bind(id),"gutter":_gutter_clicked.bind(id),"theme":_theme_changed.bind(id),"closing":_closed.bind(id)}
36
+ if code.get_script() == null:
37
+ code.set_script(Acceptance)
38
+ code.set("estragon_accept",_accept.bind(id))
39
+ code.symbol_lookup_on_click = true
40
+ code.symbol_lookup.connect(entries[id].lookup)
41
+ code.caret_changed.connect(entries[id].caret)
34
42
  code.code_completion_enabled = true
35
43
  code.code_completion_prefixes = PackedStringArray([".","<","/","@","{"])
36
44
  code.code_completion_requested.connect(entries[id].request)
@@ -39,8 +47,10 @@ func attach(editor: ScriptEditorBase, code: CodeEdit, path: String) -> void:
39
47
  code.gutter_clicked.connect(entries[id].gutter)
40
48
  code.theme_changed.connect(entries[id].theme)
41
49
  code.tree_exiting.connect(entries[id].closing)
42
- code.add_gutter()
43
- var gutter := code.get_gutter_count()-1
50
+ # Native Text storage compares a removed gutter index to line count.
51
+ # Index zero is valid even for empty/single-line tabs (4.0/4.7 bridge).
52
+ code.add_gutter(0)
53
+ var gutter := 0
44
54
  code.set_gutter_name(gutter,GUTTER)
45
55
  code.set_gutter_type(gutter,TextEdit.GUTTER_TYPE_STRING)
46
56
  code.set_gutter_width(gutter,20)
@@ -54,13 +64,16 @@ func _detach(id: int) -> void:
54
64
  var entry: Dictionary = entries[id]
55
65
  var code = entry.code.get_ref()
56
66
  if code != null:
57
- for pair in [["code_completion_requested","request"],["text_changed","edit"],["text_set","edit"],["gutter_clicked","gutter"],["theme_changed","theme"],["tree_exiting","closing"]]:
67
+ for pair in [["code_completion_requested","request"],["text_changed","edit"],["text_set","edit"],["gutter_clicked","gutter"],["theme_changed","theme"],["tree_exiting","closing"],["symbol_lookup","lookup"],["caret_changed","caret"]]:
58
68
  if code.is_connected(pair[0],entry[pair[1]]): code.disconnect(pair[0],entry[pair[1]])
69
+ code.set_code_hint("")
70
+ code.symbol_lookup_on_click = entry.lookup_enabled
59
71
  code.cancel_code_completion()
60
72
  code.code_completion_enabled = entry.enabled
61
73
  code.code_completion_prefixes = entry.prefixes
62
74
  var index := _gutter_index(code)
63
75
  if index >= 0: code.remove_gutter(index)
76
+ if code.get_script() == Acceptance: code.set_script(entry.script)
64
77
  entries.erase(id)
65
78
  func _closed(id: int) -> void:
66
79
  if entries.has(id): _detach(id)
@@ -76,8 +89,8 @@ func _theme_changed(id: int) -> void:
76
89
  var code = entries[id].code.get_ref()
77
90
  if code != null and code.syntax_highlighter != null: code.syntax_highlighter.update_cache()
78
91
  _mark(entries[id])
79
- func _changed(id: int) -> void:
80
- if not _active or not entries.has(id): return
92
+ func _changed(id: int, request_completion: bool = true) -> void:
93
+ if not _active or not entries.has(id) or entries[id].mutating: return
81
94
  var entry: Dictionary = entries[id]
82
95
  entry.pending = true
83
96
  entry.records = []
@@ -85,26 +98,113 @@ func _changed(id: int) -> void:
85
98
  var code = entry.code.get_ref()
86
99
  if code != null and code.syntax_highlighter != null: code.syntax_highlighter.clear_highlighting_cache()
87
100
  _timer.start()
88
- _auto_complete.call_deferred(id)
101
+ if request_completion: _auto_complete.call_deferred(id)
89
102
  func _auto_complete(id: int) -> void:
90
103
  if not _active or not entries.has(id): return
91
104
  var code = entries[id].code.get_ref()
92
105
  if code == null or not code.has_focus(): return
93
106
  var left: String = code.get_line(code.get_caret_line()).left(code.get_caret_column())
94
- if not left.is_empty() and (left[-1] in [".","<","/","@","{"] or left.length() >= 2 and left[-1].is_valid_identifier()): code.request_code_completion(false)
107
+ if not left.is_empty() and (left[-1] in [".","<","/","@","{","("] or left.length() >= 2 and left[-1].is_valid_identifier()): code.request_code_completion(false)
95
108
  func _complete(id: int) -> void:
96
109
  if not _active or not entries.has(id): return
97
110
  var entry: Dictionary = entries[id]
98
111
  var code = entry.code.get_ref()
99
112
  if code == null: return
100
113
  code.cancel_code_completion()
114
+ entry.model.metadata = {}
115
+ for script in interface.get_script_editor().get_open_scripts(): entry.model.metadata[script.resource_path] = script
116
+ for item in Catalog.ITEMS: entry.model.metadata[Catalog.path(item)] = item.script
101
117
  entry.model.sources = {}
102
118
  for other in entries.values():
103
119
  var buffer = other.code.get_ref()
104
120
  if buffer != null: entry.model.sources[other.path] = buffer.text
105
121
  var options: Array = entry.model.candidates(code.text,entry.path,entry.lexical,code.get_caret_line(),code.get_caret_column())
106
- for option in options: code.add_code_completion_option(option.kind,option.text,option.text,code.get_theme_color("font_color"))
122
+ entry.snapshot = code.get_version()
123
+ for option in options:
124
+ if code.get_script() != Acceptance and not option.get("imports",[]).is_empty(): continue
125
+ code.add_code_completion_option(option.kind,option.text,option.get("insert",option.text),code.get_theme_color("font_color"),null,option)
107
126
  code.update_code_completion_options(true)
127
+ _hint(id)
128
+ func _apply_imports(code: CodeEdit, plan: Dictionary) -> void:
129
+ if plan.text.is_empty(): return
130
+ var row := code.get_caret_line()
131
+ var column := code.get_caret_column()
132
+ code.set_caret_line(plan.row)
133
+ code.set_caret_column(0)
134
+ code.insert_text_at_caret(plan.text)
135
+ code.set_caret_line(row+plan.text.count("\n") if row >= plan.row else row)
136
+ code.set_caret_column(column)
137
+ func _accept(replace: bool, id: int) -> void:
138
+ if not _active or not entries.has(id): return
139
+ var entry: Dictionary = entries[id]
140
+ var code = entry.code.get_ref()
141
+ if code == null: return
142
+ var selected: int = code.get_code_completion_selected_index()
143
+ if selected < 0 or code.get_caret_count() != 1 or entry.snapshot != code.get_version():
144
+ code.cancel_code_completion()
145
+ return
146
+ var selected_option: Dictionary = code.get_code_completion_option(selected)
147
+ var option = selected_option.get("default_value")
148
+ if not option is Dictionary or not option.has("start"):
149
+ code.cancel_code_completion()
150
+ return
151
+ var row: int = option.row
152
+ var start: int = option.start
153
+ var end: int = code.get_caret_column()
154
+ if row != code.get_caret_line() or start < 0 or start > end: code.cancel_code_completion(); return
155
+ var line: String = code.get_line(row)
156
+ var insert: String = option.get("insert",option.text)
157
+ var remaining := insert.substr(end-start)
158
+ if replace and not option.get("path",false):
159
+ while end < line.length() and (line[end].is_valid_identifier() or line[end].is_valid_int()): end += 1
160
+ else:
161
+ var matched := 0
162
+ while end < line.length() and matched < remaining.length() and line[end] == remaining[matched]: end += 1; matched += 1
163
+ if option.get("path",false) and insert[-1] in ['"',"'"] and end < line.length() and line[end] == insert[-1]: end += 1
164
+ var requests: Array = option.get("imports",[])
165
+ var plan: Dictionary = entry.model.import_plan(code.text,entry.path,requests) if not requests.is_empty() else {"row":0,"text":""}
166
+ code.cancel_code_completion()
167
+ entry.mutating = true
168
+ code.begin_complex_operation()
169
+ if code.has_selection():
170
+ code.insert_text_at_caret(insert)
171
+ else:
172
+ code.remove_text(row,start,row,end)
173
+ code.set_caret_line(row)
174
+ code.set_caret_column(start)
175
+ code.insert_text_at_caret(insert)
176
+ _apply_imports(code,plan)
177
+ code.end_complex_operation()
178
+ entry.mutating = false
179
+ _changed(id,false)
180
+ if insert.ends_with("/"): code.request_code_completion(false)
181
+ func add_missing_imports() -> void:
182
+ for id in entries:
183
+ var entry: Dictionary = entries[id]
184
+ var code = entry.code.get_ref()
185
+ if code == null or not code.is_visible_in_tree(): continue
186
+ var plan: Dictionary = entry.model.import_plan(code.text,entry.path)
187
+ entry.mutating = true
188
+ code.begin_complex_operation()
189
+ _apply_imports(code,plan)
190
+ code.end_complex_operation()
191
+ entry.mutating = false
192
+ _changed(id,false)
193
+ return
194
+ func _hint(id: int) -> void:
195
+ if not _active or not entries.has(id) or entries[id].mutating: return
196
+ var entry: Dictionary = entries[id]
197
+ var code = entry.code.get_ref()
198
+ if code == null: return
199
+ entry.hint = entry.model.call_hint(code.text,entry.path,entry.lexical,code.get_caret_line(),code.get_caret_column())
200
+ code.set_code_hint(entry.hint)
201
+ func _lookup(symbol: String, _row: int, _column: int, id: int) -> void:
202
+ if not entries.has(id): return
203
+ var entry: Dictionary = entries[id]
204
+ var code = entry.code.get_ref()
205
+ if code == null: return
206
+ var path: String = entry.model.definition(code.text,entry.path,symbol)
207
+ if not path.is_empty(): navigation.open(path)
108
208
  func _analyze() -> void:
109
209
  if not _active: return
110
210
  var records: Array = []
@@ -36,8 +36,8 @@ func context(index: int, column: int) -> Dictionary:
36
36
  end["suppressed"] = end.comment or not end.quote.is_empty()
37
37
  return end
38
38
 
39
- static func _add(tokens: Array, kind: String, start: int, end: int, word: String) -> void:
40
- if end > start: tokens.append({"kind":kind, "start":start, "end":end, "text":word})
39
+ static func _add(tokens: Array, kind: String, start: int, end: int, word: String, native: bool = true) -> void:
40
+ if end > start: tokens.append({"kind":kind, "start":start, "end":end, "text":word,"native":native})
41
41
 
42
42
  func scan(text: String, state: Dictionary, newline: bool = true) -> Dictionary:
43
43
  var tokens: Array = []
@@ -50,7 +50,7 @@ func scan(text: String, state: Dictionary, newline: bool = true) -> Dictionary:
50
50
  if state.comment:
51
51
  var end := text.find("-->", i)
52
52
  i = text.length() if end < 0 else end + 3
53
- _add(tokens,"comment",start,i,text.substr(start,i-start))
53
+ _add(tokens,"comment",start,i,text.substr(start,i-start),false)
54
54
  if end >= 0: state.comment = false
55
55
  continue
56
56
  if not state.quote.is_empty():
@@ -62,14 +62,14 @@ func scan(text: String, state: Dictionary, newline: bool = true) -> Dictionary:
62
62
  state.quote = ""
63
63
  break
64
64
  else: i += 1
65
- _add(tokens,"string",start,i,text.substr(start,i-start))
65
+ _add(tokens,"string",start,i,text.substr(start,i-start),state.mode == "gd")
66
66
  state.operand = false
67
67
  continue
68
68
  if ch in [" ","\t","\r"]: i += 1; continue
69
69
  if state.mode != "gd" and text.substr(i,4) == "<!--":
70
70
  state.comment = true
71
71
  i += 4
72
- _add(tokens,"comment",start,i,"<!--")
72
+ _add(tokens,"comment",start,i,"<!--",false)
73
73
  continue
74
74
  if state.mode == "gd" and ch == "#":
75
75
  _add(tokens,"comment",i,text.length(),text.substr(i))
@@ -88,7 +88,7 @@ func scan(text: String, state: Dictionary, newline: bool = true) -> Dictionary:
88
88
  state.tag = ""
89
89
  state.name_pending = true
90
90
  i += 2 if state.closing else 1
91
- _add(tokens,"tag",start,i,text.substr(start,i-start))
91
+ _add(tokens,"tag",start,i,text.substr(start,i-start),false)
92
92
  continue
93
93
  if state.mode == "tag":
94
94
  if text.substr(i,2) == "/>" or ch == ">":
@@ -108,7 +108,7 @@ func scan(text: String, state: Dictionary, newline: bool = true) -> Dictionary:
108
108
  i += 1
109
109
  while i < text.length() and (lexer.identifier_part(text[i]) or text[i] in [".",":","-"]): i += 1
110
110
  var name := text.substr(start,i-start)
111
- _add(tokens,"tag" if state.name_pending else "property",start,i,name)
111
+ _add(tokens,"tag" if state.name_pending else "property",start,i,name,false)
112
112
  if state.name_pending: state.tag = name; state.name_pending = false
113
113
  continue
114
114
  if state.mode != "gd" and ch == "{":
@@ -116,7 +116,7 @@ func scan(text: String, state: Dictionary, newline: bool = true) -> Dictionary:
116
116
  state.mode = "gd"
117
117
  state.depth = 0
118
118
  state.operand = true
119
- _add(tokens,"expression",i,i+1,ch)
119
+ _add(tokens,"expression",i,i+1,ch,false)
120
120
  i += 1
121
121
  continue
122
122
  if state.mode == "gd" and ch == "}" and state.depth == 0 and not state.frames.is_empty():
@@ -130,7 +130,7 @@ func scan(text: String, state: Dictionary, newline: bool = true) -> Dictionary:
130
130
  i += 1
131
131
  continue
132
132
  if state.mode == "body":
133
- _add(tokens,"code",i,i+1,ch)
133
+ _add(tokens,"code",i,i+1,ch,false)
134
134
  i += 1
135
135
  continue
136
136
  var token = lexer.next_token(i)
@@ -142,7 +142,7 @@ func scan(text: String, state: Dictionary, newline: bool = true) -> Dictionary:
142
142
  kind = "keyword" if word in KEYWORDS else "code"
143
143
  if previous == "@": kind = "annotation"
144
144
  elif previous in ["func","signal"] or text.substr(i).strip_edges().begins_with("(") and kind == "code": kind = "function"
145
- elif ClassDB.class_exists(word) or word in state.declared or word in ["int","float","bool","String","Array","Dictionary","Vector2","Vector3","Color","Callable","StringName","NodePath"] or previous in [":","->","extends","class_name","class"]: kind = "type"
145
+ elif kind == "code" and (ClassDB.class_exists(word) or word in state.declared or word in ["int","float","bool","String","Array","Dictionary","Vector2","Vector3","Color","Callable","StringName","NodePath"] or previous in [":","->","extends","class_name","class"]): kind = "type"
146
146
  if previous in ["class_name","class"] or previous == "const" and text.substr(i).strip_edges().begins_with("= preload("):
147
147
  if word not in state.declared: state.declared.append(word)
148
148
  state.operand = word in Parser.OPERANDS
@@ -151,7 +151,7 @@ func scan(text: String, state: Dictionary, newline: bool = true) -> Dictionary:
151
151
  if word in ["(","[","{"]: state.depth += 1
152
152
  elif word in [")","]","}"]: state.depth = maxi(0,state.depth-1)
153
153
  state.operand = word not in [".",")","]","}"]
154
- _add(tokens,kind,start,i,word)
154
+ _add(tokens,kind,start,i,word,state.mode == "gd")
155
155
  previous = word
156
156
  if newline:
157
157
  if state.quote.length() == 1: state.quote = ""
@@ -20,13 +20,15 @@ func start(parent: Node) -> void:
20
20
  # 4.0 registers EditorFileDialog abstract; do not reference its unavailable
21
21
  # constructor even in a dead branch. Both paths use public native dialogs.
22
22
  dialog = ClassDB.instantiate("EditorFileDialog") if ClassDB.can_instantiate("EditorFileDialog") else FileDialog.new()
23
- dialog.name = "NewGogoScript"
23
+ dialog.name = "NewGogoComponent"
24
24
  if dialog is FileDialog: dialog.mode_overrides_title = false
25
- dialog.title = "New Gogo Script (never overwrites source)"
25
+ dialog.title = "New Gogo Component"
26
26
  dialog.access = EditorFileDialog.ACCESS_RESOURCES
27
27
  dialog.file_mode = EditorFileDialog.FILE_MODE_SAVE_FILE
28
28
  if dialog is EditorFileDialog: dialog.disable_overwrite_warning = true
29
- dialog.add_filter("*.gogo","Gogo Script")
29
+ # Native save filters append their suffix even to explicit wrong extensions
30
+ # (Bad.txt becomes Bad.txt.gogo). Let the shared validator own suffixes.
31
+ dialog.add_filter("*","Gogo Component (.gogo)")
30
32
  dimension = OptionButton.new()
31
33
  dimension.name = "GogoTemplate"
32
34
  dimension.add_item("Node2D — native layout and text")
@@ -35,22 +37,14 @@ func start(parent: Node) -> void:
35
37
  dialog.file_selected.connect(_selected)
36
38
  parent.add_child(dialog)
37
39
  error = AcceptDialog.new()
38
- error.title = "New Gogo Script"
40
+ error.title = "New Gogo Component"
39
41
  parent.add_child(error)
40
- func show_dialog() -> void:
42
+ func show_dialog(context_directory: String = "") -> void:
41
43
  if not active: return
42
- var directory := interface.get_current_directory()
43
- if not directory.begins_with("res://"): directory = "res://"
44
- if FileAccess.file_exists("res://gogo.config.json"):
45
- var config = JSON.parse_string(FileAccess.get_file_as_string("res://gogo.config.json"))
46
- if config is Dictionary and config.get("source_roots") is Array and not config.source_roots.is_empty():
47
- var root = config.source_roots[0]
48
- if root is String:
49
- var preferred: String = "res://"+root
50
- if preferred.ends_with(".gogo"): preferred = preferred.get_base_dir()
51
- if DirAccess.dir_exists_absolute(preferred): directory = preferred
44
+ var directory := context_directory if not context_directory.is_empty() else interface.get_current_directory()
45
+ if not directory.begins_with("res://") or not DirAccess.dir_exists_absolute(directory): directory = "res://"
52
46
  dialog.current_dir = directory
53
- dialog.current_file = "NewScript.gogo"
47
+ dialog.current_file = "NewComponent.gogo"
54
48
  dialog.popup_centered_ratio(0.65)
55
49
  static func template(path: String, spatial: bool) -> String:
56
50
  var directory := Build.output_for(path).get_base_dir()
@@ -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.5"
6
+ version="0.1.0-beta.7"
7
7
  script="plugin.gd"
@@ -12,6 +12,7 @@ const NewScript = preload("new_script.gd")
12
12
  var _services: Node
13
13
  var _navigation: RefCounted
14
14
  var _new_script: RefCounted
15
+ var _creation_menu: RefCounted
15
16
  const TEXT_EXTENSIONS_SETTING := "docks/filesystem/textfile_extensions"
16
17
 
17
18
  var _highlighter: EditorSyntaxHighlighter
@@ -54,7 +55,16 @@ func _enter_tree() -> void:
54
55
  _highlighter_association.start(_interface)
55
56
  _new_script = NewScript.new(_interface,_navigation)
56
57
  _new_script.start(self)
57
- add_tool_menu_item("New Gogo Script…",_new_script.show_dialog)
58
+ add_tool_menu_item("New Gogo Component…",_new_script.show_dialog)
59
+ # Never parse a script extending a newer native class on Godot 4.0.
60
+ if has_method("add_context_menu_plugin") and has_method("remove_context_menu_plugin") and ClassDB.class_exists("EditorContextMenuPlugin") and "CONTEXT_SLOT_FILESYSTEM_CREATE" in ClassDB.class_get_integer_constant_list("EditorContextMenuPlugin"):
61
+ var adapter := GDScript.new()
62
+ adapter.source_code = FileAccess.get_file_as_string((get_script() as Script).resource_path.get_base_dir().path_join("creation_menu.gd.txt"))
63
+ if adapter.reload() == OK:
64
+ _creation_menu = adapter.new()
65
+ _creation_menu.create = _new_script.show_dialog
66
+ call("add_context_menu_plugin",3,_creation_menu) # CONTEXT_SLOT_FILESYSTEM_CREATE
67
+ add_tool_menu_item("Add Missing Gogo Imports",_services.add_missing_imports)
58
68
  _timer = Timer.new()
59
69
  _timer.one_shot = true
60
70
  _timer.wait_time = 0.4
@@ -234,7 +244,12 @@ func _show_report() -> void:
234
244
 
235
245
  func _exit_tree() -> void:
236
246
  _active = false
237
- remove_tool_menu_item("New Gogo Script…")
247
+ remove_tool_menu_item("New Gogo Component…")
248
+ if _creation_menu != null:
249
+ call("remove_context_menu_plugin",_creation_menu)
250
+ _creation_menu.create = Callable()
251
+ _creation_menu = null
252
+ remove_tool_menu_item("Add Missing Gogo Imports")
238
253
  if _navigation != null: _navigation.stop()
239
254
  if _new_script != null: _new_script.stop(); _new_script = null
240
255
  if _services != null: _services.stop(); _services.free(); _services = null
package/package.json CHANGED
@@ -29,5 +29,5 @@
29
29
  "tag": "beta",
30
30
  "registry": "https://registry.npmjs.org/"
31
31
  },
32
- "version": "0.1.0-beta.5"
32
+ "version": "0.1.0-beta.7"
33
33
  }