@papercraftgames/estragon 0.1.0-beta.3 → 0.1.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -3
- package/README.md +11 -8
- package/addons/estragon/compiler/bindable.gd +3 -3
- package/addons/estragon/compiler/compiler.gd +8 -8
- package/addons/estragon/compiler/composition.gd +5 -4
- package/addons/estragon/compiler/emitter.gd +18 -7
- package/addons/estragon/compiler/frontend.gd +8 -8
- package/addons/estragon/compiler/lexer.gd +2 -2
- package/addons/estragon/compiler/native/resolver.gd +7 -7
- package/addons/estragon/compiler/parser.gd +3 -3
- package/addons/estragon/compiler/script_validation.gd +3 -3
- package/addons/estragon/compiler/source.gd +17 -2
- package/addons/estragon/compiler/source_map.gd +2 -2
- package/addons/estragon/compiler/validator.gd +6 -5
- package/addons/estragon/editor/build_service.gd +40 -8
- package/addons/estragon/editor/completion.gd +205 -0
- package/addons/estragon/editor/completion.gd.uid +1 -0
- package/addons/estragon/editor/highlighter.gd +26 -104
- package/addons/estragon/editor/highlighter_association.gd +11 -2
- package/addons/estragon/editor/language_services.gd +186 -0
- package/addons/estragon/editor/language_services.gd.uid +1 -0
- package/addons/estragon/editor/lexical_context.gd +159 -0
- package/addons/estragon/editor/lexical_context.gd.uid +1 -0
- package/addons/estragon/editor/navigation.gd +30 -0
- package/addons/estragon/editor/navigation.gd.uid +1 -0
- package/addons/estragon/editor/new_script.gd +88 -0
- package/addons/estragon/editor/new_script.gd.uid +1 -0
- package/addons/estragon/editor/plugin.cfg +1 -1
- package/addons/estragon/editor/plugin.gd +55 -8
- package/addons/estragon/editor/script_dependencies.gd +2 -2
- package/addons/estragon/runtime/composition/binding.gd +1 -1
- package/addons/estragon/runtime/composition/computation.gd +3 -3
- package/addons/estragon/runtime/composition/element.gd +1 -1
- package/addons/estragon/runtime/composition/profile.tres +1 -1
- package/addons/estragon/runtime/composition/state.gd +2 -2
- package/addons/estragon/runtime/composition/state.tres +1 -1
- package/addons/estragon/runtime/node/button.gd +1 -1
- package/addons/estragon/runtime/node/component_2d.gd +1 -1
- package/addons/estragon/runtime/node/component_3d.gd +1 -1
- package/addons/estragon/runtime/node/estragon_2d.gd +2 -2
- package/addons/estragon/runtime/node/estragon_3d.gd +1 -1
- package/addons/estragon/runtime/node/hbox.gd +1 -1
- package/addons/estragon/runtime/node/internal/coordinator.gd +2 -2
- package/addons/estragon/runtime/node/internal/layout_core.gd +1 -1
- package/addons/estragon/runtime/node/native_2d.gd +2 -2
- package/addons/estragon/runtime/node/native_3d.gd +2 -2
- package/addons/estragon/runtime/node/rect.gd +1 -1
- package/addons/estragon/runtime/node/text.gd +1 -1
- package/addons/estragon/runtime/node/toggle.gd +1 -1
- package/addons/estragon/runtime/node/vbox.gd +1 -1
- package/package.json +1 -1
|
@@ -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
|
-
##
|
|
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
|
-
|
|
13
|
-
var
|
|
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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
func
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
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
|
-
const Highlighter = preload("
|
|
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
|