@papercraftgames/estragon 0.1.0-beta.4 → 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.
package/CHANGELOG.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # Release notes
2
2
 
3
- ## Next automated prerelease
3
+ ## Gogo editor experience — upcoming beta
4
4
 
5
- P02 makes runtime/compiler/editor dependencies location-independent and derives injected Gogo dependencies from the installed Resources and actual generated destination. Yarn packages run directly in node_modules; full-path plugin activation, cold editor/Play, nonstandard relocation and standard addon placement are covered by native consumer acceptance. This change is not yet published. 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
 
package/README.md CHANGED
@@ -2,6 +2,8 @@
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
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:
@@ -49,11 +49,7 @@ func _init(module: Model.Module, file: Source) -> void:
49
49
  while _module.identifiers.has(_element_class): _element_class += "_"
50
50
 
51
51
  func _resource(resource: Resource) -> String:
52
- var origin := ProjectSettings.globalize_path(_output_directory).simplify_path().split("/", false)
53
- var target := ProjectSettings.globalize_path(resource.resource_path).simplify_path().split("/", false)
54
- var shared := 0
55
- while shared < mini(origin.size(), target.size()) and origin[shared] == target[shared]: shared += 1
56
- return _string("../".repeat(origin.size() - shared) + "/".join(target.slice(shared)))
52
+ return _string(Source.relative_path(_output_directory,resource.resource_path))
57
53
 
58
54
  func emit() -> MappedWriter:
59
55
  _parts(_module.parts)
@@ -70,3 +70,11 @@ func index_at_offset(offset_value: int) -> int:
70
70
 
71
71
  func offset(line: int, column: int = 1) -> int:
72
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))
@@ -7,7 +7,7 @@ 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)
@@ -93,7 +97,7 @@ func _run() -> Dictionary:
93
97
  continue
94
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)}
@@ -0,0 +1,205 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Lexical declarations + public ClassDB metadata. No authored Script loads/new().
4
+ const Context = preload("lexical_context.gd")
5
+ const Build = preload("build_service.gd")
6
+ var sources: Dictionary = {}
7
+ var _script_cache: Dictionary = {}
8
+ var _classes: PackedStringArray = []
9
+ var _text := ""
10
+ var _path := ""
11
+ var _symbols: Dictionary = {}
12
+ var _aliases: Dictionary = {}
13
+ var _owners: Dictionary = {}
14
+ var _base := "Node"
15
+ var _native_cache: Dictionary = {}
16
+
17
+ func _init() -> void:
18
+ _classes = ClassDB.get_class_list()
19
+ func invalidate() -> void:
20
+ _text = ""
21
+ _native_cache.clear()
22
+ _script_cache.clear()
23
+ func _tokens(text: String) -> Array:
24
+ var context := Context.new()
25
+ context.update(text)
26
+ var result: Array = []
27
+ for index in range(context.lines.size()):
28
+ for token in context.line(index).tokens:
29
+ if token.kind in ["comment","tag","property"]: continue
30
+ if token.kind == "string" and not result.is_empty() and result[-1].kind == "string" and result[-1].row == index and result[-1].end == token.start:
31
+ result[-1].text += token.text
32
+ result[-1].end = token.end
33
+ else:
34
+ var item: Dictionary = token.duplicate()
35
+ item.row = index
36
+ item.indent = context.lines[index].length()-context.lines[index].strip_edges(true,false).length()
37
+ result.append(item)
38
+ return result
39
+ func _resolve_path(raw: String, source: String) -> String:
40
+ if raw.length() < 2: return ""
41
+ var value := raw.substr(1,raw.length()-2).c_unescape()
42
+ if value.is_absolute_path(): return value.simplify_path()
43
+ var output := Build.output_for(source) if source.ends_with(".gogo") else source
44
+ return output.get_base_dir().path_join(value).simplify_path()
45
+ func _declarations(text: String, source: String) -> Dictionary:
46
+ var tokens := _tokens(text)
47
+ var symbols: Dictionary = {}
48
+ var aliases: Dictionary = {}
49
+ var base := ""
50
+ var owner := ""
51
+ var owners: Dictionary = {}
52
+ var required_initializer := false
53
+ for index in range(tokens.size()):
54
+ var word: String = tokens[index].text
55
+ if tokens[index].indent == 0: owners[tokens[index].row] = ""
56
+ elif not owners.has(tokens[index].row): owners[tokens[index].row] = owner
57
+ if word == "extends" and tokens[index].indent == 0 and index+1 < tokens.size():
58
+ base = _resolve_path(tokens[index+1].text,source) if tokens[index+1].kind == "string" else tokens[index+1].text
59
+ if word not in ["var","const","func","signal","class_name","class"] or index+1 >= tokens.size(): continue
60
+ var name: String = tokens[index+1].text
61
+ if not name.is_valid_identifier(): continue
62
+ var scope: String = owner if tokens[index].indent > 0 else ""
63
+ if word == "func" and tokens[index].indent == 0:
64
+ owner = name
65
+ owners[tokens[index].row] = owner
66
+ if name == "_init" and index+3 < tokens.size() and tokens[index+3].text != ")": required_initializer = true
67
+ var type := ""
68
+ if index+3 < tokens.size() and tokens[index+2].text == ":": type = tokens[index+3].text
69
+ 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))))}
70
+ if word == "signal":
71
+ var args: Array = []
72
+ for cursor in range(index+2,mini(index+28,tokens.size()-1)):
73
+ if tokens[cursor].text == ")": break
74
+ if tokens[cursor].text == ":": args.append(tokens[cursor+1].text)
75
+ symbols[name].args = args
76
+ if word == "var":
77
+ var getter := false
78
+ var setter := false
79
+ for cursor in range(index+2,tokens.size()-1):
80
+ if tokens[cursor].row > tokens[index].row and tokens[cursor].indent <= tokens[index].indent: break
81
+ if tokens[cursor].text == "get" and tokens[cursor+1].text == ":": getter = true
82
+ if tokens[cursor].text == "set": setter = true
83
+ symbols[name].writable = not getter or setter
84
+ if word == "const" and scope.is_empty():
85
+ for cursor in range(index+2,mini(index+7,tokens.size()-2)):
86
+ 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
+ # Typed arguments/local declarations also contribute names, never inferred values.
88
+ 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():
90
+ var name: String = tokens[index-1].text
91
+ if not symbols.has(name): symbols[name] = {"type":tokens[index+1].text,"owner":owners.get(tokens[index].row,""),"kind":CodeEdit.KIND_VARIABLE}
92
+ return {"symbols":symbols,"aliases":aliases,"base":base,"owners":owners,"required_initializer":required_initializer}
93
+ func _index(text: String, source: String) -> void:
94
+ if text == _text and source == _path: return
95
+ _text = text
96
+ _path = source
97
+ var declarations := _declarations(text,source)
98
+ _symbols = declarations.symbols
99
+ _owners = declarations.owners
100
+ _aliases = declarations.aliases
101
+ _base = declarations.base
102
+ func _script(path: String) -> Dictionary:
103
+ var text: String = sources[path] if sources.has(path) else FileAccess.get_file_as_string(path)
104
+ if not _script_cache.has(path) or _script_cache[path].text != text:
105
+ _script_cache[path] = {"text":text,"declarations":_declarations(text,path)}
106
+ return _script_cache[path].declarations
107
+ func _members(type: String, aliases: Dictionary, visited: Array = []) -> Dictionary:
108
+ var name: String = aliases.get(type,type)
109
+ if name.is_empty() or name in visited or visited.size() >= 12: return {}
110
+ if ClassDB.class_exists(name):
111
+ if _native_cache.has(name): return _native_cache[name]
112
+ var result: Dictionary = {}
113
+ 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}
117
+ 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
+ _native_cache[name] = result
119
+ return result
120
+ if not name.begins_with("res://"):
121
+ for entry in ProjectSettings.get_global_class_list():
122
+ if entry["class"] == name: return _members(str(entry.path),{},visited+[name])
123
+ return {}
124
+ var authored := name.get_base_dir().get_base_dir().path_join(name.get_file().get_basename()+".gogo")
125
+ if name.get_base_dir().get_file() == "generated" and FileAccess.file_exists(authored): name = authored
126
+ if not FileAccess.file_exists(name): return {}
127
+ var declarations := _script(name)
128
+ var result := _members(declarations.base,declarations.aliases,visited+[name])
129
+ for field in declarations.symbols:
130
+ if declarations.symbols[field].owner.is_empty(): result[field] = declarations.symbols[field]
131
+ return result
132
+ func _node_type(type: String, aliases: Dictionary, visited: Array = []) -> bool:
133
+ var name: String = aliases.get(type,type)
134
+ if name in visited or visited.size() >= 12: return false
135
+ if ClassDB.class_exists(name): return ClassDB.is_parent_class(name,"Node") and ClassDB.can_instantiate(name)
136
+ if not name.begins_with("res://"):
137
+ for entry in ProjectSettings.get_global_class_list():
138
+ if entry["class"] == name: return _node_type(str(entry.path),{},visited+[name])
139
+ return false
140
+ var authored := name.get_base_dir().get_base_dir().path_join(name.get_file().get_basename()+".gogo")
141
+ if name.get_base_dir().get_file() == "generated" and FileAccess.file_exists(authored): name = authored
142
+ if not FileAccess.file_exists(name): return false
143
+ var declarations := _script(name)
144
+ return not declarations.required_initializer and _node_type(declarations.base,declarations.aliases,visited+[name])
145
+ func candidates(text: String, source: String, lexical: RefCounted, row: int, column: int) -> Array:
146
+ _index(text,source)
147
+ lexical.update(text)
148
+ var context: Dictionary = lexical.context(row,column)
149
+ if context.suppressed: return []
150
+ var left: String = lexical.lines[row].left(column)
151
+ var prefix := ""
152
+ var cursor := left.length()-1
153
+ while cursor >= 0 and (left[cursor].is_valid_identifier() or left[cursor].is_valid_int() or left[cursor] == ":"):
154
+ prefix = left[cursor]+prefix
155
+ cursor -= 1
156
+ if context.mode == "tag" and context.closing: prefix = "/"+prefix
157
+ var offered: Dictionary = {}
158
+ if context.mode == "tag":
159
+ if context.closing:
160
+ if not context.tags.is_empty(): offered["/"+context.tags[-1]] = {"kind":CodeEdit.KIND_CLASS}
161
+ elif context.name_pending or not left.substr(maxi(0,left.rfind("<"))+1).contains(" ") and not left.substr(maxi(0,left.rfind("<"))+1).contains("\t"):
162
+ for name in _classes:
163
+ if ClassDB.is_parent_class(name,"Node") and ClassDB.can_instantiate(name): offered[name] = {"kind":CodeEdit.KIND_CLASS}
164
+ for name in _aliases:
165
+ if _node_type(name,_aliases): offered[name] = {"kind":CodeEdit.KIND_CLASS}
166
+ 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}
168
+ else:
169
+ if not _node_type(context.tag,_aliases): return []
170
+ var members := _members(context.tag,_aliases)
171
+ for name in members:
172
+ if members[name].kind in [CodeEdit.KIND_MEMBER,CodeEdit.KIND_SIGNAL] and members[name].get("writable",true) and name not in ["owner","script"]: offered[name] = members[name]
173
+ if _node_type(context.tag,_aliases): offered.key = {"kind":CodeEdit.KIND_MEMBER}
174
+ 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}
175
+ elif context.mode == "body": return []
176
+ elif cursor >= 0 and left[cursor] == ".":
177
+ var begin := cursor-1
178
+ while begin >= 0 and (left[begin].is_valid_identifier() or left[begin].is_valid_int() or left[begin] == "."): begin -= 1
179
+ var receiver := left.substr(begin+1,cursor-begin-1)
180
+ var chain := receiver.split(".")
181
+ var members: Dictionary = {}
182
+ if chain[0] == "self":
183
+ for field in _symbols:
184
+ if _symbols[field].owner.is_empty(): members[field] = _symbols[field]
185
+ if chain[0] == "self": members.merge(_members(_base,_aliases),false)
186
+ elif _symbols.has(chain[0]): members = _members(_symbols[chain[0]].type,_aliases)
187
+ else: members = _members(chain[0],_aliases)
188
+ for index in range(1,chain.size()): members = _members(str(members.get(chain[index],{}).get("type","")),_aliases)
189
+ offered = members
190
+ else:
191
+ for word in Context.KEYWORDS: offered[word] = {"kind":CodeEdit.KIND_PLAIN_TEXT}
192
+ for name in _classes: offered[name] = {"kind":CodeEdit.KIND_CLASS}
193
+ for entry in ProjectSettings.get_global_class_list(): offered[entry["class"]] = {"kind":CodeEdit.KIND_CLASS}
194
+ for field in _symbols:
195
+ if _symbols[field].owner.is_empty() or _symbols[field].owner == _owners.get(row,""): offered[field] = _symbols[field]
196
+ offered.merge(_members(_base,_aliases),false)
197
+ if cursor >= 0 and left[cursor] == "@":
198
+ offered.clear()
199
+ for name in ["bindable","tool","export","export_range","onready","warning_ignore"]: offered[name] = {"kind":CodeEdit.KIND_PLAIN_TEXT}
200
+ var result: Array = []
201
+ 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})
204
+ result.sort_custom(func(a,b): return a.text < b.text)
205
+ return result
@@ -0,0 +1 @@
1
+ uid://bajyq4kqi1
@@ -1,7 +1,7 @@
1
1
  @tool
2
2
  extends EditorSyntaxHighlighter
3
- ## Presentation-only lexical coloring. The native compiler owns diagnostics.
4
-
3
+ ## Native theme palette + edit-invalidated tolerant line contexts.
4
+ const Context = preload("lexical_context.gd")
5
5
  const CODE := Color("dedede")
6
6
  const KEYWORD := Color("ff7085")
7
7
  const TAG := Color("8bd5ff")
@@ -9,108 +9,30 @@ const PROPERTY := Color("c6a0f6")
9
9
  const STRING := Color("a6da95")
10
10
  const COMMENT := Color("808790")
11
11
  const EXPRESSION := Color("eed49f")
12
- const KEYWORDS := ["extends", "class_name", "class", "func", "static", "var", "const", "return", "if", "elif", "else", "for", "in", "while", "await", "signal", "true", "false", "null", "pass", "and", "or", "not", "as", "is", "self"]
13
- var _lines: Array[Dictionary] = []
14
-
12
+ var settings: EditorSettings
13
+ var lexical = Context.new()
14
+ var _version := -1
15
+ 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]}
15
16
 
17
+ func _init(editor_settings: EditorSettings = null) -> void:
18
+ settings = editor_settings
16
19
  func _create() -> EditorSyntaxHighlighter:
17
- return get_script().new()
18
-
19
-
20
- func _get_name() -> String:
21
- return "Gogo"
22
-
23
-
24
- func _get_supported_languages() -> PackedStringArray:
25
- return PackedStringArray(["gogo"])
26
-
27
-
28
- func _clear_highlighting_cache() -> void:
29
- _lines.clear()
30
-
31
-
32
- func _get_line_syntax_highlighting(line: int) -> Dictionary:
33
- if _lines.is_empty():
34
- _scan()
35
- return _lines[line] if line < _lines.size() else {}
36
-
37
-
38
- func _scan() -> void:
20
+ return get_script().new(settings)
21
+ func _get_name() -> String: return "Gogo"
22
+ func _get_supported_languages() -> PackedStringArray: return PackedStringArray(["gogo"])
23
+ func _clear_highlighting_cache() -> void: _version = -1
24
+ func color(kind: String) -> Color:
25
+ var entry: Array = PALETTE.get(kind,PALETTE.code)
26
+ var key: String = "text_editor/theme/highlighting/"+entry[0]
27
+ return settings.get_setting(key) if settings != null and settings.has_setting(key) else entry[1]
28
+ func _get_line_syntax_highlighting(index: int) -> Dictionary:
39
29
  var edit := get_text_edit()
40
- if edit == null:
41
- return
42
- var quote := ""
43
- var xml_comment := false
44
- var tag_depths: Array[int] = []
45
- var braces: int = 0
46
- for line_index in range(edit.get_line_count()):
47
- var text := edit.get_line(line_index)
48
- var colors: Dictionary = {0: {"color": CODE}}
49
- var i: int = 0
50
- while i < text.length():
51
- if xml_comment:
52
- colors[i] = {"color": COMMENT}
53
- var end := text.find("-->", i)
54
- if end < 0:
55
- break
56
- i = end + 3
57
- xml_comment = false
58
- colors[i] = {"color": CODE}
59
- continue
60
- if not quote.is_empty():
61
- colors[i] = {"color": STRING}
62
- while i < text.length():
63
- if text[i] == "\\":
64
- i += 2
65
- continue
66
- if text.substr(i, quote.length()) == quote:
67
- i += quote.length()
68
- quote = ""
69
- break
70
- i += 1
71
- colors[i] = {"color": CODE}
72
- continue
73
- var character := text[i]
74
- if text.substr(i, 4) == "<!--":
75
- xml_comment = true
76
- continue
77
- if character == "#" and (tag_depths.is_empty() or braces > tag_depths[-1]):
78
- colors[i] = {"color": COMMENT}
79
- break
80
- if character == '"' or character == "'":
81
- quote = character.repeat(3) if text.substr(i, 3) == character.repeat(3) else character
82
- colors[i] = {"color": STRING}
83
- i += quote.length()
84
- continue
85
- if character == "<" and i + 1 < text.length() and (text[i + 1] == "/" or text[i + 1].to_upper() == text[i + 1] and text[i + 1].to_lower() != text[i + 1]):
86
- tag_depths.append(braces)
87
- var end := i + 1
88
- while end < text.length() and text[end] not in [" ", "\t", ">"]:
89
- end += 1
90
- colors[i] = {"color": TAG}
91
- i = end
92
- colors[i] = {"color": CODE}
93
- continue
94
- if character == ">" and not tag_depths.is_empty() and braces == tag_depths[-1]:
95
- colors[i] = {"color": TAG}
96
- tag_depths.pop_back()
97
- colors[i + 1] = {"color": CODE}
98
- if character == "{" or character == "}":
99
- braces += 1 if character == "{" else -1
100
- braces = maxi(0, braces)
101
- colors[i] = {"color": EXPRESSION}
102
- colors[i + 1] = {"color": CODE}
103
- if character.is_valid_identifier() and not character.is_valid_int():
104
- var end := i + 1
105
- while end < text.length() and (text[end].is_valid_identifier() or text[end].is_valid_int()):
106
- end += 1
107
- var word := text.substr(i, end - i)
108
- if word in KEYWORDS or not tag_depths.is_empty() and braces == tag_depths[-1]:
109
- colors[i] = {"color": KEYWORD if word in KEYWORDS else PROPERTY}
110
- colors[end] = {"color": CODE}
111
- i = end
112
- continue
113
- i += 1
114
- if quote.length() == 1:
115
- quote = ""
116
- _lines.append(colors)
30
+ if edit == null: return {}
31
+ if _version != edit.get_version():
32
+ lexical.update(edit.text)
33
+ _version = edit.get_version()
34
+ var result := {0:{"color":color("code")}}
35
+ for token in lexical.line(index).tokens:
36
+ result[token.start] = {"color":color(token.kind)}
37
+ result[token.end] = {"color":color("code")}
38
+ return result
@@ -3,6 +3,8 @@ extends RefCounted
3
3
  ## Repair extension association after native tab creation / cached state restore.
4
4
  ## Kept separate from compilation; no timer, file writes or editor preferences.
5
5
  const Highlighter = preload("highlighter.gd")
6
+ signal associated(editor, code, path)
7
+ var _settings: EditorSettings
6
8
  const PATH_META := "estragon_gogo_path"
7
9
  var _scripts: ScriptEditor
8
10
  var _tree: SceneTree
@@ -11,6 +13,7 @@ var _pending: bool = false
11
13
  var _tested_adapter: bool = false
12
14
 
13
15
  func start(interface: EditorInterface) -> void:
16
+ _settings = interface.get_editor_settings()
14
17
  var version := Engine.get_version_info()
15
18
  _tested_adapter = version.major == 4 and version.minor >= 0 and version.minor <= 7
16
19
  if not _tested_adapter:
@@ -49,13 +52,19 @@ func _refresh() -> void:
49
52
  var code := editor.get_base_editor() as TextEdit
50
53
  if code == null: continue
51
54
  var path := _path(editor, code)
55
+ associated.emit(editor,code,path)
52
56
  if path.get_extension() != "gogo": continue
53
57
  code.set_meta(PATH_META, path)
54
58
  if code.syntax_highlighter != null and code.syntax_highlighter.get_script() == Highlighter:
59
+ # 4.0 clones the script directly; its native _create is not a
60
+ # script virtual, so constructor arguments are not preserved.
61
+ if code.syntax_highlighter.settings != _settings:
62
+ code.syntax_highlighter.settings = _settings
63
+ code.syntax_highlighter.update_cache()
55
64
  continue
56
65
  # A fresh instance per CodeEdit. Do not add duplicate native menu entries
57
66
  # or rewrite the per-file cache; normal editor persistence handles state.
58
- code.syntax_highlighter = Highlighter.new()
67
+ code.syntax_highlighter = Highlighter.new(_settings)
59
68
 
60
69
  func _path(editor: ScriptEditorBase, code: TextEdit, allow_cached: bool = true) -> String:
61
70
  if code.syntax_highlighter is EditorSyntaxHighlighter and code.syntax_highlighter.has_method("_get_edited_resource"):
@@ -0,0 +1,186 @@
1
+ @tool
2
+ extends Node
3
+ ## Owns only authenticated Gogo CodeEdit connections and a dedicated gutter.
4
+ signal diagnostics_changed(records, phase)
5
+ const Context = preload("lexical_context.gd")
6
+ const Completion = preload("completion.gd")
7
+ const Source = preload("../compiler/source.gd")
8
+ const Parser = preload("../compiler/parser.gd")
9
+ const Bindable = preload("../compiler/bindable.gd")
10
+ const GUTTER := "Estragon diagnostics"
11
+ var interface: EditorInterface
12
+ var navigation: RefCounted
13
+ var entries: Dictionary = {}
14
+ var _timer: Timer
15
+ var _active := true
16
+ var _generation := 0
17
+ func _init(editor_interface: EditorInterface, navigator: RefCounted) -> void:
18
+ interface = editor_interface
19
+ navigation = navigator
20
+ func _ready() -> void:
21
+ _timer = Timer.new()
22
+ _timer.one_shot = true
23
+ _timer.wait_time = 0.45
24
+ _timer.timeout.connect(_analyze)
25
+ add_child(_timer)
26
+ func attach(editor: ScriptEditorBase, code: CodeEdit, path: String) -> void:
27
+ if not _active: return
28
+ var id := code.get_instance_id()
29
+ if entries.has(id):
30
+ if entries[id].path == path: return
31
+ _detach(id)
32
+ 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)}
34
+ code.code_completion_enabled = true
35
+ code.code_completion_prefixes = PackedStringArray([".","<","/","@","{"])
36
+ code.code_completion_requested.connect(entries[id].request)
37
+ code.text_changed.connect(entries[id].edit)
38
+ code.text_set.connect(entries[id].edit)
39
+ code.gutter_clicked.connect(entries[id].gutter)
40
+ code.theme_changed.connect(entries[id].theme)
41
+ code.tree_exiting.connect(entries[id].closing)
42
+ code.add_gutter()
43
+ var gutter := code.get_gutter_count()-1
44
+ code.set_gutter_name(gutter,GUTTER)
45
+ code.set_gutter_type(gutter,TextEdit.GUTTER_TYPE_STRING)
46
+ code.set_gutter_width(gutter,20)
47
+ code.set_gutter_draw(gutter,true)
48
+ _timer.start()
49
+ func _gutter_index(code: CodeEdit) -> int:
50
+ for index in range(code.get_gutter_count()):
51
+ if code.get_gutter_name(index) == GUTTER: return index
52
+ return -1
53
+ func _detach(id: int) -> void:
54
+ var entry: Dictionary = entries[id]
55
+ var code = entry.code.get_ref()
56
+ 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"]]:
58
+ if code.is_connected(pair[0],entry[pair[1]]): code.disconnect(pair[0],entry[pair[1]])
59
+ code.cancel_code_completion()
60
+ code.code_completion_enabled = entry.enabled
61
+ code.code_completion_prefixes = entry.prefixes
62
+ var index := _gutter_index(code)
63
+ if index >= 0: code.remove_gutter(index)
64
+ entries.erase(id)
65
+ func _closed(id: int) -> void:
66
+ if entries.has(id): _detach(id)
67
+ func stop() -> void:
68
+ _active = false
69
+ _generation += 1
70
+ if _timer != null: _timer.stop()
71
+ for id in entries.keys(): _detach(id)
72
+ func invalidate() -> void:
73
+ for entry in entries.values(): entry.model.invalidate()
74
+ func _theme_changed(id: int) -> void:
75
+ if not entries.has(id): return
76
+ var code = entries[id].code.get_ref()
77
+ if code != null and code.syntax_highlighter != null: code.syntax_highlighter.update_cache()
78
+ _mark(entries[id])
79
+ func _changed(id: int) -> void:
80
+ if not _active or not entries.has(id): return
81
+ var entry: Dictionary = entries[id]
82
+ entry.pending = true
83
+ entry.records = []
84
+ _mark(entry)
85
+ var code = entry.code.get_ref()
86
+ if code != null and code.syntax_highlighter != null: code.syntax_highlighter.clear_highlighting_cache()
87
+ _timer.start()
88
+ _auto_complete.call_deferred(id)
89
+ func _auto_complete(id: int) -> void:
90
+ if not _active or not entries.has(id): return
91
+ var code = entries[id].code.get_ref()
92
+ if code == null or not code.has_focus(): return
93
+ 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)
95
+ func _complete(id: int) -> void:
96
+ if not _active or not entries.has(id): return
97
+ var entry: Dictionary = entries[id]
98
+ var code = entry.code.get_ref()
99
+ if code == null: return
100
+ code.cancel_code_completion()
101
+ entry.model.sources = {}
102
+ for other in entries.values():
103
+ var buffer = other.code.get_ref()
104
+ if buffer != null: entry.model.sources[other.path] = buffer.text
105
+ 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"))
107
+ code.update_code_completion_options(true)
108
+ func _analyze() -> void:
109
+ if not _active: return
110
+ var records: Array = []
111
+ for id in entries.keys():
112
+ var entry: Dictionary = entries[id]
113
+ var code = entry.code.get_ref()
114
+ if code == null: entries.erase(id); continue
115
+ if entry.pending:
116
+ entry.pending = false
117
+ var source := Source.new(code.text,entry.path)
118
+ var module = Parser.new(source).parse()
119
+ if module != null: Bindable.new(source).apply(module)
120
+ entry.records = []
121
+ for diagnostic in source.diagnostics:
122
+ entry.records.append({"source":entry.path,"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})
123
+ _mark(entry)
124
+ records.append_array(entry.records)
125
+ diagnostics_changed.emit(records,"Typing feedback — syntax only; save/Play validates semantics")
126
+ func report_build(report: Dictionary) -> void:
127
+ for entry in entries.values():
128
+ entry.records = []
129
+ entry.pending = false
130
+ for item in report.get("source_diagnostics",[]):
131
+ var record: Dictionary = item.duplicate()
132
+ if not record.source.begins_with("res://"): record.source = "res://"+record.source
133
+ for entry in entries.values():
134
+ if entry.path == record.source: entry.records.append(record)
135
+ for entry in entries.values(): _mark(entry)
136
+ func _mark(entry: Dictionary) -> void:
137
+ var code = entry.code.get_ref()
138
+ if code == null: return
139
+ var gutter := _gutter_index(code)
140
+ if gutter < 0: return
141
+ var stale: Array = entry.marked if entry.line_count == code.get_line_count() else range(code.get_line_count())
142
+ for line in stale:
143
+ code.set_line_gutter_text(line,gutter,"")
144
+ code.set_line_gutter_metadata(line,gutter,null)
145
+ code.set_line_gutter_clickable(line,gutter,false)
146
+ entry.marked = []
147
+ entry.line_count = code.get_line_count()
148
+ for record in entry.records:
149
+ var row := clampi(record.line-1,0,code.get_line_count()-1)
150
+ if row not in entry.marked: entry.marked.append(row)
151
+ code.set_line_gutter_text(row,gutter,"!")
152
+ code.set_line_gutter_item_color(row,gutter,code.get_theme_color("error_color","Editor"))
153
+ code.set_line_gutter_metadata(row,gutter,record)
154
+ code.set_line_gutter_clickable(row,gutter,true)
155
+ func _gutter_clicked(line: int, gutter: int, id: int) -> void:
156
+ if not entries.has(id): return
157
+ var code = entries[id].code.get_ref()
158
+ if code != null and _gutter_index(code) == gutter:
159
+ var record = code.get_line_gutter_metadata(line,gutter)
160
+ if record is Dictionary: navigate(record)
161
+ static func scalar_column(text: String, column: int) -> int:
162
+ var units := 0
163
+ var index := 0
164
+ while index < text.length() and units < maxi(0,column-1):
165
+ units += 2 if text.unicode_at(index) > 0xffff else 1
166
+ index += 1
167
+ return index
168
+ func navigate(record: Dictionary) -> void:
169
+ var target := str(record.source)
170
+ if not target.begins_with("res://"): target = "res://"+target
171
+ var generation := _generation
172
+ await navigation.open(target)
173
+ var deadline := Time.get_ticks_msec()+5000
174
+ while _active and generation == _generation and Time.get_ticks_msec() < deadline:
175
+ for entry in entries.values():
176
+ if entry.path != target: continue
177
+ var code = entry.code.get_ref()
178
+ if code == null or not code.is_visible_in_tree(): continue
179
+ var row := clampi(int(record.line)-1,0,code.get_line_count()-1)
180
+ var column := scalar_column(code.get_line(row),int(record.column))
181
+ code.set_caret_line(row)
182
+ code.set_caret_column(column)
183
+ code.set_line_as_center_visible(row)
184
+ code.grab_focus()
185
+ return
186
+ await get_tree().process_frame
@@ -0,0 +1 @@
1
+ uid://c59p2w2nmld
@@ -0,0 +1,159 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Tolerant, line-cached editor contexts. Shares native identifier/operator and
4
+ ## expression-start rules; never substitutes source or executes authored code.
5
+ const Lexer = preload("../compiler/lexer.gd")
6
+ const Source = preload("../compiler/source.gd")
7
+ const Parser = preload("../compiler/parser.gd")
8
+ const KEYWORDS := ["extends", "class_name", "class", "func", "static", "var", "const", "return", "if", "elif", "else", "for", "in", "while", "await", "signal", "true", "false", "null", "pass", "and", "or", "not", "as", "is", "self", "match", "break", "continue", "assert", "enum", "preload", "load", "super", "get", "set", "when", "void"]
9
+ var lines: PackedStringArray = []
10
+ var records: Array = []
11
+ var scanned_lines := 0
12
+
13
+ func update(text: String) -> void:
14
+ var next := text.split("\n")
15
+ var same := 0
16
+ while same < mini(lines.size(), next.size()) and lines[same] == next[same]: same += 1
17
+ records.resize(mini(same, records.size()))
18
+ lines = next
19
+
20
+ static func initial() -> Dictionary:
21
+ return {"mode":"gd", "quote":"", "comment":false, "tags":[], "islands":[], "frames":[], "operand":true, "depth":0, "declared":[], "tag":"", "closing":false, "name_pending":false}
22
+
23
+ func line(index: int) -> Dictionary:
24
+ while records.size() <= index and records.size() < lines.size():
25
+ var state: Dictionary = initial() if records.is_empty() else records[-1].state.duplicate(true)
26
+ records.append(scan(lines[records.size()], state))
27
+ scanned_lines += 1
28
+ return records[index] if index >= 0 and index < records.size() else {"tokens":[], "state":initial()}
29
+
30
+ func context(index: int, column: int) -> Dictionary:
31
+ if index > 0: line(index - 1)
32
+ var state: Dictionary = initial() if index == 0 else records[index - 1].state.duplicate(true)
33
+ var result := scan(lines[index].left(column), state, false)
34
+ var end: Dictionary = result.state
35
+ end["tokens"] = result.tokens
36
+ end["suppressed"] = end.comment or not end.quote.is_empty()
37
+ return end
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})
41
+
42
+ func scan(text: String, state: Dictionary, newline: bool = true) -> Dictionary:
43
+ var tokens: Array = []
44
+ var lexer := Lexer.new(Source.new(text))
45
+ var i := 0
46
+ var previous := ""
47
+ while i < text.length():
48
+ var start := i
49
+ var ch := text[i]
50
+ if state.comment:
51
+ var end := text.find("-->", i)
52
+ i = text.length() if end < 0 else end + 3
53
+ _add(tokens,"comment",start,i,text.substr(start,i-start))
54
+ if end >= 0: state.comment = false
55
+ continue
56
+ if not state.quote.is_empty():
57
+ var delimiter: String = state.quote
58
+ while i < text.length():
59
+ if text[i] == "\\": i = mini(text.length(), i + 2)
60
+ elif text.substr(i,delimiter.length()) == delimiter:
61
+ i += delimiter.length()
62
+ state.quote = ""
63
+ break
64
+ else: i += 1
65
+ _add(tokens,"string",start,i,text.substr(start,i-start))
66
+ state.operand = false
67
+ continue
68
+ if ch in [" ","\t","\r"]: i += 1; continue
69
+ if state.mode != "gd" and text.substr(i,4) == "<!--":
70
+ state.comment = true
71
+ i += 4
72
+ _add(tokens,"comment",start,i,"<!--")
73
+ continue
74
+ if state.mode == "gd" and ch == "#":
75
+ _add(tokens,"comment",i,text.length(),text.substr(i))
76
+ if not newline: state.comment = true
77
+ i = text.length()
78
+ continue
79
+ if ch in ['"',"'"]:
80
+ state.quote = ch.repeat(3) if text.substr(i,3) == ch.repeat(3) else ch
81
+ i += state.quote.length()
82
+ _add(tokens,"string",start,i,text.substr(start,i-start))
83
+ continue
84
+ if ch == "<" and (state.mode == "body" or state.mode == "gd" and state.operand and (i+1 == text.length() or lexer.identifier_start(lexer.char_at(i+1)))):
85
+ if state.mode == "gd": state.islands.append(state.tags.size())
86
+ state.mode = "tag"
87
+ state.closing = text.substr(i,2) == "</"
88
+ state.tag = ""
89
+ state.name_pending = true
90
+ i += 2 if state.closing else 1
91
+ _add(tokens,"tag",start,i,text.substr(start,i-start))
92
+ continue
93
+ if state.mode == "tag":
94
+ if text.substr(i,2) == "/>" or ch == ">":
95
+ var self_closing := text.substr(i,2) == "/>"
96
+ i += 2 if self_closing else 1
97
+ _add(tokens,"tag",start,i,text.substr(start,i-start))
98
+ if state.closing:
99
+ if not state.tags.is_empty(): state.tags.pop_back()
100
+ elif not self_closing: state.tags.append(state.tag)
101
+ if not state.islands.is_empty() and state.tags.size() == state.islands[-1]:
102
+ state.islands.pop_back()
103
+ state.mode = "gd"
104
+ else: state.mode = "body" if not state.tags.is_empty() else "gd"
105
+ state.operand = false
106
+ continue
107
+ if lexer.identifier_start(ch):
108
+ i += 1
109
+ while i < text.length() and (lexer.identifier_part(text[i]) or text[i] in [".",":","-"]): i += 1
110
+ var name := text.substr(start,i-start)
111
+ _add(tokens,"tag" if state.name_pending else "property",start,i,name)
112
+ if state.name_pending: state.tag = name; state.name_pending = false
113
+ continue
114
+ if state.mode != "gd" and ch == "{":
115
+ state.frames.append({"mode":state.mode,"depth":state.depth,"tag":state.tag,"closing":state.closing,"name_pending":state.name_pending})
116
+ state.mode = "gd"
117
+ state.depth = 0
118
+ state.operand = true
119
+ _add(tokens,"expression",i,i+1,ch)
120
+ i += 1
121
+ continue
122
+ if state.mode == "gd" and ch == "}" and state.depth == 0 and not state.frames.is_empty():
123
+ var frame: Dictionary = state.frames.pop_back()
124
+ state.mode = frame.mode
125
+ state.depth = frame.depth
126
+ state.tag = frame.tag
127
+ state.closing = frame.closing
128
+ state.name_pending = frame.name_pending
129
+ _add(tokens,"expression",i,i+1,ch)
130
+ i += 1
131
+ continue
132
+ if state.mode == "body":
133
+ _add(tokens,"code",i,i+1,ch)
134
+ i += 1
135
+ continue
136
+ var token = lexer.next_token(i)
137
+ if token == null: i += 1; continue
138
+ i = token.span.end.index
139
+ var word: String = token.text
140
+ var kind := "symbol"
141
+ if token.kind == "identifier":
142
+ kind = "keyword" if word in KEYWORDS else "code"
143
+ if previous == "@": kind = "annotation"
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"
146
+ if previous in ["class_name","class"] or previous == "const" and text.substr(i).strip_edges().begins_with("= preload("):
147
+ if word not in state.declared: state.declared.append(word)
148
+ state.operand = word in Parser.OPERANDS
149
+ elif token.kind == "number": kind = "number"; state.operand = false
150
+ else:
151
+ if word in ["(","[","{"]: state.depth += 1
152
+ elif word in [")","]","}"]: state.depth = maxi(0,state.depth-1)
153
+ state.operand = word not in [".",")","]","}"]
154
+ _add(tokens,kind,start,i,word)
155
+ previous = word
156
+ if newline:
157
+ if state.quote.length() == 1: state.quote = ""
158
+ if state.mode == "gd" and state.depth == 0 and state.frames.is_empty(): state.operand = true
159
+ return {"tokens":tokens,"state":state}
@@ -0,0 +1 @@
1
+ uid://8z7w8jx076b
@@ -0,0 +1,30 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## TextFile opening has no public ScriptEditor entry point on 4.0.
4
+ ## Activate only a native FileSystemDock item authenticated by its full path.
5
+ ## No private method, guessed basename/index, or menu injection is used.
6
+ var interface: EditorInterface
7
+ var active := true
8
+ func _init(editor_interface: EditorInterface) -> void: interface = editor_interface
9
+ func stop() -> void: active = false
10
+ func open(path: String) -> void:
11
+ if not active or not path.begins_with("res://") or not FileAccess.file_exists(path): return
12
+ var version := Engine.get_version_info()
13
+ if version.major != 4 or version.minor > 7:
14
+ interface.select_file(path)
15
+ return
16
+ var dock := interface.get_file_system_dock()
17
+ dock.navigate_to_path(path)
18
+ var deadline := Time.get_ticks_msec()+5000
19
+ while active and Time.get_ticks_msec() < deadline:
20
+ for tree in dock.find_children("*","Tree",true,false):
21
+ var selected: TreeItem = tree.get_selected()
22
+ if selected != null and selected.get_metadata(0) is String and selected.get_metadata(0) == path:
23
+ tree.item_activated.emit()
24
+ return
25
+ for list in dock.find_children("*","ItemList",true,false):
26
+ for index in list.get_selected_items():
27
+ if list.get_item_metadata(index) is String and list.get_item_metadata(index) == path:
28
+ list.item_activated.emit(index)
29
+ return
30
+ await dock.get_tree().process_frame
@@ -0,0 +1 @@
1
+ uid://i3yzit6qp5q
@@ -0,0 +1,88 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## User-invoked creation only. Never overwrites source or edits project config.
4
+ const Build = preload("build_service.gd")
5
+ const Source = preload("../compiler/source.gd")
6
+ const Element = preload("../runtime/composition/element.gd")
7
+ const Entry2D = preload("../runtime/node/estragon_2d.gd")
8
+ const Entry3D = preload("../runtime/node/estragon_3d.gd")
9
+ const Text = preload("../runtime/node/text.gd")
10
+ var dialog: Variant
11
+ var dimension: OptionButton
12
+ var error: AcceptDialog
13
+ var interface: EditorInterface
14
+ var navigation: RefCounted
15
+ var active := true
16
+ func _init(editor_interface: EditorInterface, navigator: RefCounted) -> void:
17
+ interface = editor_interface
18
+ navigation = navigator
19
+ func start(parent: Node) -> void:
20
+ # 4.0 registers EditorFileDialog abstract; do not reference its unavailable
21
+ # constructor even in a dead branch. Both paths use public native dialogs.
22
+ dialog = ClassDB.instantiate("EditorFileDialog") if ClassDB.can_instantiate("EditorFileDialog") else FileDialog.new()
23
+ dialog.name = "NewGogoScript"
24
+ if dialog is FileDialog: dialog.mode_overrides_title = false
25
+ dialog.title = "New Gogo Script (never overwrites source)"
26
+ dialog.access = EditorFileDialog.ACCESS_RESOURCES
27
+ dialog.file_mode = EditorFileDialog.FILE_MODE_SAVE_FILE
28
+ if dialog is EditorFileDialog: dialog.disable_overwrite_warning = true
29
+ dialog.add_filter("*.gogo","Gogo Script")
30
+ dimension = OptionButton.new()
31
+ dimension.name = "GogoTemplate"
32
+ dimension.add_item("Node2D — native layout and text")
33
+ dimension.add_item("Node3D — native spatial layout")
34
+ dialog.get_vbox().add_child(dimension)
35
+ dialog.file_selected.connect(_selected)
36
+ parent.add_child(dialog)
37
+ error = AcceptDialog.new()
38
+ error.title = "New Gogo Script"
39
+ parent.add_child(error)
40
+ func show_dialog() -> void:
41
+ 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
52
+ dialog.current_dir = directory
53
+ dialog.current_file = "NewScript.gogo"
54
+ dialog.popup_centered_ratio(0.65)
55
+ static func template(path: String, spatial: bool) -> String:
56
+ var directory := Build.output_for(path).get_base_dir()
57
+ var element := JSON.stringify(Source.relative_path(directory,(Element as Script).resource_path))
58
+ var entry := JSON.stringify(Source.relative_path(directory,((Entry3D if spatial else Entry2D) as Script).resource_path))
59
+ var result := "extends "+("Node3D" if spatial else "Node2D")+"\nconst Element = preload("+element+")\nconst Entry = preload("+entry+")\n"
60
+ if spatial:
61
+ return result+"\nfunc build_view() -> Element:\n\treturn <Entry name=\"Layout\" width={4.0} height={2.0} depth={1.0} />\n"
62
+ var text := JSON.stringify(Source.relative_path(directory,(Text as Script).resource_path))
63
+ return result+"const Text = preload("+text+")\n\nfunc build_view() -> Element:\n\treturn <Entry name=\"UI\" viewport_width_scale={0.9}>\n\t\t<Text name=\"Greeting\" text=\"Hello Gogo\" />\n\t</Entry>\n"
64
+ func _selected(path: String) -> void:
65
+ if not active: return
66
+ if path.get_extension().is_empty(): path += ".gogo"
67
+ var check := Build.creation_check(path)
68
+ if not check.ok:
69
+ error.dialog_text = check.message
70
+ error.popup_centered()
71
+ return
72
+ var file := FileAccess.open(path,FileAccess.WRITE)
73
+ if file == null:
74
+ error.dialog_text = "Cannot create "+path+": "+error_string(FileAccess.get_open_error())
75
+ error.popup_centered()
76
+ return
77
+ file.store_string(template(path,dimension.selected == 1))
78
+ file.close()
79
+ interface.get_resource_filesystem().scan()
80
+ _open_after_scan(path)
81
+ func _open_after_scan(path: String) -> void:
82
+ var filesystem := interface.get_resource_filesystem()
83
+ while active and filesystem.is_scanning(): await dialog.get_tree().process_frame
84
+ if active: navigation.open(path)
85
+ func stop() -> void:
86
+ active = false
87
+ if dialog != null: dialog.free(); dialog = null
88
+ if error != null: error.free(); error = null
@@ -0,0 +1 @@
1
+ uid://b96jihgasld
@@ -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.4"
6
+ version="0.1.0-beta.5"
7
7
  script="plugin.gd"
@@ -6,6 +6,12 @@ const BufferGuard = preload("buffer_guard.gd")
6
6
  const BuildService = preload("build_service.gd")
7
7
  const HighlighterAssociation = preload("highlighter_association.gd")
8
8
  const Highlighter = preload("highlighter.gd")
9
+ const Services = preload("language_services.gd")
10
+ const Navigation = preload("navigation.gd")
11
+ const NewScript = preload("new_script.gd")
12
+ var _services: Node
13
+ var _navigation: RefCounted
14
+ var _new_script: RefCounted
9
15
  const TEXT_EXTENSIONS_SETTING := "docks/filesystem/textfile_extensions"
10
16
 
11
17
  var _highlighter: EditorSyntaxHighlighter
@@ -37,10 +43,18 @@ func _enter_tree() -> void:
37
43
  registered = true
38
44
  if not registered:
39
45
  settings.set_setting(TEXT_EXTENSIONS_SETTING, existing + ("," if not existing.is_empty() else "") + "gogo")
40
- _highlighter = Highlighter.new()
46
+ _highlighter = Highlighter.new(settings)
41
47
  _interface.get_script_editor().register_syntax_highlighter(_highlighter)
42
48
  _highlighter_association = HighlighterAssociation.new()
49
+ _navigation = Navigation.new(_interface)
50
+ _services = Services.new(_interface,_navigation)
51
+ add_child(_services)
52
+ _services.diagnostics_changed.connect(_typing_report)
53
+ _highlighter_association.associated.connect(_services.attach)
43
54
  _highlighter_association.start(_interface)
55
+ _new_script = NewScript.new(_interface,_navigation)
56
+ _new_script.start(self)
57
+ add_tool_menu_item("New Gogo Script…",_new_script.show_dialog)
44
58
  _timer = Timer.new()
45
59
  _timer.one_shot = true
46
60
  _timer.wait_time = 0.4
@@ -50,9 +64,12 @@ func _enter_tree() -> void:
50
64
  _diagnostics.name = "EstragonDiagnostics"
51
65
  _diagnostics.custom_minimum_size = Vector2(0, 120)
52
66
  _diagnostics.selection_enabled = true
67
+ _diagnostics.bbcode_enabled = true
68
+ _diagnostics.meta_clicked.connect(_diagnostic_clicked)
53
69
  add_control_to_bottom_panel(_diagnostics, "Gogo")
54
- _interface.get_resource_filesystem().filesystem_changed.connect(_schedule)
70
+ _interface.get_resource_filesystem().filesystem_changed.connect(_filesystem_changed)
55
71
  _interface.get_resource_filesystem().sources_changed.connect(_sources_changed)
72
+ scene_changed.connect(_scene_context_changed)
56
73
  resource_saved.connect(_resource_saved)
57
74
  _interface.get_script_editor().editor_script_changed.connect(_script_changed)
58
75
  # Native GGX with explicit imports can build before the editor restores
@@ -128,7 +145,17 @@ func _refresh_generated_editors() -> void:
128
145
  code.tag_saved_version()
129
146
 
130
147
 
148
+ func _filesystem_changed() -> void:
149
+ if _services != null: _services.invalidate()
150
+ _schedule()
151
+
152
+
153
+ func _scene_context_changed(_root: Node) -> void:
154
+ if _services != null: _services.invalidate()
155
+
156
+
131
157
  func _sources_changed(_changed: bool) -> void:
158
+ _services.invalidate()
132
159
  _schedule()
133
160
 
134
161
 
@@ -183,8 +210,23 @@ func _compile() -> bool:
183
210
  return last_report.ok
184
211
 
185
212
 
213
+ func _typing_report(records: Array, phase: String) -> void:
214
+ if not _active or _building: return
215
+ _diagnostics.clear()
216
+ _diagnostics.add_text(phase+"\n")
217
+ for record in records: _diagnostic_link(record)
218
+ func _diagnostic_link(record: Dictionary) -> void:
219
+ _diagnostics.push_meta(record)
220
+ _diagnostics.add_text("%s:%d:%d: %s\n" % [record.source,record.line,record.column,record.message])
221
+ _diagnostics.pop()
222
+ func _diagnostic_clicked(record: Variant) -> void:
223
+ if record is Dictionary: _services.navigate(record)
186
224
  func _show_report() -> void:
225
+ _services.report_build(last_report)
187
226
  _diagnostics.text = "Gogo build succeeded." if last_report.ok else "\n\n".join(PackedStringArray(last_report.diagnostics))
227
+ if not last_report.get("source_diagnostics",[]).is_empty():
228
+ _diagnostics.clear()
229
+ for record in last_report.source_diagnostics: _diagnostic_link(record)
188
230
  if not last_report.ok:
189
231
  make_bottom_panel_item_visible(_diagnostics)
190
232
  push_warning("Estragon: Gogo compilation failed; Play blocked.\n" + _diagnostics.text)
@@ -192,13 +234,18 @@ func _show_report() -> void:
192
234
 
193
235
  func _exit_tree() -> void:
194
236
  _active = false
237
+ remove_tool_menu_item("New Gogo Script…")
238
+ if _navigation != null: _navigation.stop()
239
+ if _new_script != null: _new_script.stop(); _new_script = null
240
+ if _services != null: _services.stop(); _services.free(); _services = null
241
+ _navigation = null
195
242
  _building = false
196
243
  _rescan_pending = false
197
244
  _play_save_failed = false
198
245
  if is_instance_valid(_interface):
199
246
  var filesystem := _interface.get_resource_filesystem()
200
- if filesystem.filesystem_changed.is_connected(_schedule):
201
- filesystem.filesystem_changed.disconnect(_schedule)
247
+ if filesystem.filesystem_changed.is_connected(_filesystem_changed):
248
+ filesystem.filesystem_changed.disconnect(_filesystem_changed)
202
249
  if filesystem.sources_changed.is_connected(_sources_changed):
203
250
  filesystem.sources_changed.disconnect(_sources_changed)
204
251
  if is_instance_valid(_interface):
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.4"
32
+ "version": "0.1.0-beta.5"
33
33
  }