@papercraftgames/estragon 0.1.0-beta.4 → 0.1.0-beta.6
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 +6 -2
- package/README.md +2 -0
- package/addons/estragon/compiler/emitter.gd +1 -5
- package/addons/estragon/compiler/source.gd +8 -0
- package/addons/estragon/editor/build_service.gd +36 -4
- package/addons/estragon/editor/completion.gd +334 -0
- package/addons/estragon/editor/completion.gd.uid +1 -0
- package/addons/estragon/editor/completion_edit.gd +7 -0
- package/addons/estragon/editor/completion_edit.gd.uid +1 -0
- package/addons/estragon/editor/components.gd +18 -0
- package/addons/estragon/editor/components.gd.uid +1 -0
- package/addons/estragon/editor/highlighter.gd +62 -103
- package/addons/estragon/editor/highlighter_association.gd +10 -1
- package/addons/estragon/editor/imports.gd +47 -0
- package/addons/estragon/editor/imports.gd.uid +1 -0
- package/addons/estragon/editor/language_services.gd +286 -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 +53 -4
- package/package.json +1 -1
|
@@ -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,67 @@ 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
|
+
var _preview: TextEdit
|
|
16
|
+
var _native: SyntaxHighlighter
|
|
17
|
+
const PALETTE := {"code":["text_color",CODE], "keyword":["keyword_color",KEYWORD], "tag":["user_type_color",TAG], "property":["member_variable_color",PROPERTY], "string":["string_color",STRING], "comment":["comment_color",COMMENT], "expression":["symbol_color",EXPRESSION], "symbol":["symbol_color",EXPRESSION], "number":["number_color",Color("a1ffe0")], "type":["base_type_color",TAG], "function":["function_color",Color("57b3ff")], "annotation":["annotation_color",KEYWORD]}
|
|
15
18
|
|
|
19
|
+
func _init(editor_settings: EditorSettings = null) -> void:
|
|
20
|
+
settings = editor_settings
|
|
16
21
|
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
|
-
|
|
22
|
+
return get_script().new(settings)
|
|
23
|
+
func _get_name() -> String: return "Gogo"
|
|
24
|
+
func _get_supported_languages() -> PackedStringArray: return PackedStringArray(["gogo"])
|
|
28
25
|
func _clear_highlighting_cache() -> void:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
_version = -1
|
|
27
|
+
if _native != null: _native.update_cache()
|
|
28
|
+
func color(kind: String) -> Color:
|
|
29
|
+
var entry: Array = PALETTE.get(kind,PALETTE.code)
|
|
30
|
+
var key: String = "text_editor/theme/highlighting/"+entry[0]
|
|
31
|
+
return settings.get_setting(key) if settings != null and settings.has_setting(key) else entry[1]
|
|
32
|
+
func _notification(what: int) -> void:
|
|
33
|
+
if what == NOTIFICATION_PREDELETE and is_instance_valid(_preview):
|
|
34
|
+
_preview.free()
|
|
35
|
+
_preview = null
|
|
36
|
+
func uses_native() -> bool: return _native != null
|
|
37
|
+
func _ensure_native() -> void:
|
|
38
|
+
if _native != null or not Engine.is_editor_hint(): return
|
|
39
|
+
if ClassDB.class_exists("GDScriptSyntaxHighlighter") and ClassDB.can_instantiate("GDScriptSyntaxHighlighter"):
|
|
40
|
+
_native = ClassDB.instantiate("GDScriptSyntaxHighlighter")
|
|
41
|
+
_preview = TextEdit.new()
|
|
42
|
+
_preview.syntax_highlighter = _native
|
|
43
|
+
func _native_color(colors: Dictionary, column: int) -> Color:
|
|
44
|
+
var result := color("code")
|
|
45
|
+
var keys := colors.keys()
|
|
46
|
+
keys.sort()
|
|
47
|
+
for key in keys:
|
|
48
|
+
if key > column: break
|
|
49
|
+
result = colors[key].color
|
|
50
|
+
return result
|
|
51
|
+
func _get_line_syntax_highlighting(index: int) -> Dictionary:
|
|
39
52
|
var edit := get_text_edit()
|
|
40
|
-
if edit == null:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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)
|
|
53
|
+
if edit == null: return {}
|
|
54
|
+
_ensure_native()
|
|
55
|
+
if _version != edit.get_version():
|
|
56
|
+
lexical.update(edit.text)
|
|
57
|
+
_version = edit.get_version()
|
|
58
|
+
if _native != null:
|
|
59
|
+
var masked: Array = []
|
|
60
|
+
for row in range(lexical.lines.size()):
|
|
61
|
+
var line: String = lexical.lines[row]
|
|
62
|
+
# Keep all code-point columns/newlines; markup cannot poison native
|
|
63
|
+
# GDScript string/comment state across a GGX island. No compilation.
|
|
64
|
+
for token in lexical.line(row).tokens:
|
|
65
|
+
if not token.native: line = line.left(token.start)+" ".repeat(token.end-token.start)+line.substr(token.end)
|
|
66
|
+
masked.append(line)
|
|
67
|
+
_preview.text = "\n".join(masked)
|
|
68
|
+
_native.update_cache()
|
|
69
|
+
var native_colors: Dictionary = _native.get_line_syntax_highlighting(index) if _native != null else {}
|
|
70
|
+
var result: Dictionary = native_colors.duplicate(true) if _native != null else {0:{"color":color("code")}}
|
|
71
|
+
for token in lexical.line(index).tokens:
|
|
72
|
+
if _native != null and token.native and not (token.kind == "annotation" and token.text == "bindable"): continue
|
|
73
|
+
result[token.start] = {"color":color(token.kind)}
|
|
74
|
+
result[token.end] = {"color":_native_color(native_colors,token.end) if _native != null else color("code")}
|
|
75
|
+
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,47 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Pure bounded edit plans. No saves, generated writes or authored Script loads.
|
|
4
|
+
const Build = preload("build_service.gd")
|
|
5
|
+
const Source = preload("../compiler/source.gd")
|
|
6
|
+
const Catalog = preload("components.gd")
|
|
7
|
+
static func occupied(name: String, resource: String, symbols: Dictionary) -> bool:
|
|
8
|
+
if symbols.has(name) or ClassDB.class_exists(name): return true
|
|
9
|
+
for entry in ProjectSettings.get_global_class_list():
|
|
10
|
+
if str(entry["class"]) == name and str(entry.path) != resource: return true
|
|
11
|
+
return false
|
|
12
|
+
static func alias_for(item: Dictionary, symbols: Dictionary, aliases: Dictionary) -> String:
|
|
13
|
+
for name in aliases:
|
|
14
|
+
if aliases[name] == Catalog.path(item): return name
|
|
15
|
+
var name: String = item.alias
|
|
16
|
+
if occupied(name,Catalog.path(item),symbols): name = item.canonical
|
|
17
|
+
var stem := name
|
|
18
|
+
var suffix := 2
|
|
19
|
+
while occupied(name,Catalog.path(item),symbols):
|
|
20
|
+
name = stem+str(suffix)
|
|
21
|
+
suffix += 1
|
|
22
|
+
return name
|
|
23
|
+
static func declaration(name: String, resource: String, source: String) -> String:
|
|
24
|
+
return "const "+name+" = preload("+JSON.stringify(Source.relative_path(Build.output_for(source).get_base_dir(),resource))+")\n"
|
|
25
|
+
static func plan(text: String, source: String, requested: Array, symbols: Dictionary, aliases: Dictionary, tokens: Array) -> Dictionary:
|
|
26
|
+
var declarations: Array = []
|
|
27
|
+
var names: Dictionary = aliases.duplicate()
|
|
28
|
+
for request in requested:
|
|
29
|
+
if names.get(request.alias) == request.path: continue
|
|
30
|
+
# Caller resolves collisions explicitly; never replace an authored name.
|
|
31
|
+
if occupied(request.alias,request.path,symbols) or names.has(request.alias): continue
|
|
32
|
+
declarations.append(declaration(request.alias,request.path,source))
|
|
33
|
+
names[request.alias] = request.path
|
|
34
|
+
# A first build_view()->Element needs the explicit composition resource too.
|
|
35
|
+
if not occupied("Element",Catalog.path(Catalog.named("Element")),symbols) and not names.has("Element"):
|
|
36
|
+
for index in range(tokens.size()-1):
|
|
37
|
+
if tokens[index].text == "->" and tokens[index+1].text == "Element":
|
|
38
|
+
declarations.push_front(declaration("Element",Catalog.path(Catalog.named("Element")),source))
|
|
39
|
+
break
|
|
40
|
+
var row := 0
|
|
41
|
+
for token in tokens:
|
|
42
|
+
if token.indent == 0 and token.text in ["extends","class_name"]: row = maxi(row,int(token.row)+1)
|
|
43
|
+
# Preserve file-level tool/icon annotations when no extends header exists yet.
|
|
44
|
+
if row == 0:
|
|
45
|
+
var lines := text.split("\n")
|
|
46
|
+
while row < lines.size() and (lines[row].strip_edges().is_empty() or lines[row].strip_edges().begins_with("#") or lines[row].begins_with("@tool") or lines[row].begins_with("@icon")): row += 1
|
|
47
|
+
return {"row":mini(row,text.count("\n")),"text":"".join(declarations)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://ckzxzc2w16s
|
|
@@ -0,0 +1,286 @@
|
|
|
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 Acceptance = preload("completion_edit.gd")
|
|
7
|
+
const Catalog = preload("components.gd")
|
|
8
|
+
const Completion = preload("completion.gd")
|
|
9
|
+
const Source = preload("../compiler/source.gd")
|
|
10
|
+
const Parser = preload("../compiler/parser.gd")
|
|
11
|
+
const Bindable = preload("../compiler/bindable.gd")
|
|
12
|
+
const GUTTER := "Estragon diagnostics"
|
|
13
|
+
var interface: EditorInterface
|
|
14
|
+
var navigation: RefCounted
|
|
15
|
+
var entries: Dictionary = {}
|
|
16
|
+
var _timer: Timer
|
|
17
|
+
var _active := true
|
|
18
|
+
var _generation := 0
|
|
19
|
+
func _init(editor_interface: EditorInterface, navigator: RefCounted) -> void:
|
|
20
|
+
interface = editor_interface
|
|
21
|
+
navigation = navigator
|
|
22
|
+
func _ready() -> void:
|
|
23
|
+
_timer = Timer.new()
|
|
24
|
+
_timer.one_shot = true
|
|
25
|
+
_timer.wait_time = 0.45
|
|
26
|
+
_timer.timeout.connect(_analyze)
|
|
27
|
+
add_child(_timer)
|
|
28
|
+
func attach(editor: ScriptEditorBase, code: CodeEdit, path: String) -> void:
|
|
29
|
+
if not _active: return
|
|
30
|
+
var id := code.get_instance_id()
|
|
31
|
+
if entries.has(id):
|
|
32
|
+
if entries[id].path == path: return
|
|
33
|
+
_detach(id)
|
|
34
|
+
if not path.ends_with(".gogo"): return
|
|
35
|
+
entries[id] = {"code":weakref(code),"editor":weakref(editor),"path":path,"model":Completion.new(),"lexical":Context.new(),"records":[],"pending":true,"marked":[],"line_count":code.get_line_count(),"mutating":false,"snapshot":-1,"script":code.get_script(),"lookup_enabled":code.symbol_lookup_on_click,"lookup":_lookup.bind(id),"caret":_hint.bind(id),"enabled":code.code_completion_enabled,"prefixes":code.code_completion_prefixes,"request":_complete.bind(id),"edit":_changed.bind(id),"gutter":_gutter_clicked.bind(id),"theme":_theme_changed.bind(id),"closing":_closed.bind(id)}
|
|
36
|
+
if code.get_script() == null:
|
|
37
|
+
code.set_script(Acceptance)
|
|
38
|
+
code.set("estragon_accept",_accept.bind(id))
|
|
39
|
+
code.symbol_lookup_on_click = true
|
|
40
|
+
code.symbol_lookup.connect(entries[id].lookup)
|
|
41
|
+
code.caret_changed.connect(entries[id].caret)
|
|
42
|
+
code.code_completion_enabled = true
|
|
43
|
+
code.code_completion_prefixes = PackedStringArray([".","<","/","@","{"])
|
|
44
|
+
code.code_completion_requested.connect(entries[id].request)
|
|
45
|
+
code.text_changed.connect(entries[id].edit)
|
|
46
|
+
code.text_set.connect(entries[id].edit)
|
|
47
|
+
code.gutter_clicked.connect(entries[id].gutter)
|
|
48
|
+
code.theme_changed.connect(entries[id].theme)
|
|
49
|
+
code.tree_exiting.connect(entries[id].closing)
|
|
50
|
+
# Native Text storage compares a removed gutter index to line count.
|
|
51
|
+
# Index zero is valid even for empty/single-line tabs (4.0/4.7 bridge).
|
|
52
|
+
code.add_gutter(0)
|
|
53
|
+
var gutter := 0
|
|
54
|
+
code.set_gutter_name(gutter,GUTTER)
|
|
55
|
+
code.set_gutter_type(gutter,TextEdit.GUTTER_TYPE_STRING)
|
|
56
|
+
code.set_gutter_width(gutter,20)
|
|
57
|
+
code.set_gutter_draw(gutter,true)
|
|
58
|
+
_timer.start()
|
|
59
|
+
func _gutter_index(code: CodeEdit) -> int:
|
|
60
|
+
for index in range(code.get_gutter_count()):
|
|
61
|
+
if code.get_gutter_name(index) == GUTTER: return index
|
|
62
|
+
return -1
|
|
63
|
+
func _detach(id: int) -> void:
|
|
64
|
+
var entry: Dictionary = entries[id]
|
|
65
|
+
var code = entry.code.get_ref()
|
|
66
|
+
if code != null:
|
|
67
|
+
for pair in [["code_completion_requested","request"],["text_changed","edit"],["text_set","edit"],["gutter_clicked","gutter"],["theme_changed","theme"],["tree_exiting","closing"],["symbol_lookup","lookup"],["caret_changed","caret"]]:
|
|
68
|
+
if code.is_connected(pair[0],entry[pair[1]]): code.disconnect(pair[0],entry[pair[1]])
|
|
69
|
+
code.set_code_hint("")
|
|
70
|
+
code.symbol_lookup_on_click = entry.lookup_enabled
|
|
71
|
+
code.cancel_code_completion()
|
|
72
|
+
code.code_completion_enabled = entry.enabled
|
|
73
|
+
code.code_completion_prefixes = entry.prefixes
|
|
74
|
+
var index := _gutter_index(code)
|
|
75
|
+
if index >= 0: code.remove_gutter(index)
|
|
76
|
+
if code.get_script() == Acceptance: code.set_script(entry.script)
|
|
77
|
+
entries.erase(id)
|
|
78
|
+
func _closed(id: int) -> void:
|
|
79
|
+
if entries.has(id): _detach(id)
|
|
80
|
+
func stop() -> void:
|
|
81
|
+
_active = false
|
|
82
|
+
_generation += 1
|
|
83
|
+
if _timer != null: _timer.stop()
|
|
84
|
+
for id in entries.keys(): _detach(id)
|
|
85
|
+
func invalidate() -> void:
|
|
86
|
+
for entry in entries.values(): entry.model.invalidate()
|
|
87
|
+
func _theme_changed(id: int) -> void:
|
|
88
|
+
if not entries.has(id): return
|
|
89
|
+
var code = entries[id].code.get_ref()
|
|
90
|
+
if code != null and code.syntax_highlighter != null: code.syntax_highlighter.update_cache()
|
|
91
|
+
_mark(entries[id])
|
|
92
|
+
func _changed(id: int, request_completion: bool = true) -> void:
|
|
93
|
+
if not _active or not entries.has(id) or entries[id].mutating: return
|
|
94
|
+
var entry: Dictionary = entries[id]
|
|
95
|
+
entry.pending = true
|
|
96
|
+
entry.records = []
|
|
97
|
+
_mark(entry)
|
|
98
|
+
var code = entry.code.get_ref()
|
|
99
|
+
if code != null and code.syntax_highlighter != null: code.syntax_highlighter.clear_highlighting_cache()
|
|
100
|
+
_timer.start()
|
|
101
|
+
if request_completion: _auto_complete.call_deferred(id)
|
|
102
|
+
func _auto_complete(id: int) -> void:
|
|
103
|
+
if not _active or not entries.has(id): return
|
|
104
|
+
var code = entries[id].code.get_ref()
|
|
105
|
+
if code == null or not code.has_focus(): return
|
|
106
|
+
var left: String = code.get_line(code.get_caret_line()).left(code.get_caret_column())
|
|
107
|
+
if not left.is_empty() and (left[-1] in [".","<","/","@","{","("] or left.length() >= 2 and left[-1].is_valid_identifier()): code.request_code_completion(false)
|
|
108
|
+
func _complete(id: int) -> void:
|
|
109
|
+
if not _active or not entries.has(id): return
|
|
110
|
+
var entry: Dictionary = entries[id]
|
|
111
|
+
var code = entry.code.get_ref()
|
|
112
|
+
if code == null: return
|
|
113
|
+
code.cancel_code_completion()
|
|
114
|
+
entry.model.metadata = {}
|
|
115
|
+
for script in interface.get_script_editor().get_open_scripts(): entry.model.metadata[script.resource_path] = script
|
|
116
|
+
for item in Catalog.ITEMS: entry.model.metadata[Catalog.path(item)] = item.script
|
|
117
|
+
entry.model.sources = {}
|
|
118
|
+
for other in entries.values():
|
|
119
|
+
var buffer = other.code.get_ref()
|
|
120
|
+
if buffer != null: entry.model.sources[other.path] = buffer.text
|
|
121
|
+
var options: Array = entry.model.candidates(code.text,entry.path,entry.lexical,code.get_caret_line(),code.get_caret_column())
|
|
122
|
+
entry.snapshot = code.get_version()
|
|
123
|
+
for option in options:
|
|
124
|
+
if code.get_script() != Acceptance and not option.get("imports",[]).is_empty(): continue
|
|
125
|
+
code.add_code_completion_option(option.kind,option.text,option.get("insert",option.text),code.get_theme_color("font_color"),null,option)
|
|
126
|
+
code.update_code_completion_options(true)
|
|
127
|
+
_hint(id)
|
|
128
|
+
func _apply_imports(code: CodeEdit, plan: Dictionary) -> void:
|
|
129
|
+
if plan.text.is_empty(): return
|
|
130
|
+
var row := code.get_caret_line()
|
|
131
|
+
var column := code.get_caret_column()
|
|
132
|
+
code.set_caret_line(plan.row)
|
|
133
|
+
code.set_caret_column(0)
|
|
134
|
+
code.insert_text_at_caret(plan.text)
|
|
135
|
+
code.set_caret_line(row+plan.text.count("\n") if row >= plan.row else row)
|
|
136
|
+
code.set_caret_column(column)
|
|
137
|
+
func _accept(replace: bool, id: int) -> void:
|
|
138
|
+
if not _active or not entries.has(id): return
|
|
139
|
+
var entry: Dictionary = entries[id]
|
|
140
|
+
var code = entry.code.get_ref()
|
|
141
|
+
if code == null: return
|
|
142
|
+
var selected: int = code.get_code_completion_selected_index()
|
|
143
|
+
if selected < 0 or code.get_caret_count() != 1 or entry.snapshot != code.get_version():
|
|
144
|
+
code.cancel_code_completion()
|
|
145
|
+
return
|
|
146
|
+
var selected_option: Dictionary = code.get_code_completion_option(selected)
|
|
147
|
+
var option = selected_option.get("default_value")
|
|
148
|
+
if not option is Dictionary or not option.has("start"):
|
|
149
|
+
code.cancel_code_completion()
|
|
150
|
+
return
|
|
151
|
+
var row: int = option.row
|
|
152
|
+
var start: int = option.start
|
|
153
|
+
var end: int = code.get_caret_column()
|
|
154
|
+
if row != code.get_caret_line() or start < 0 or start > end: code.cancel_code_completion(); return
|
|
155
|
+
var line: String = code.get_line(row)
|
|
156
|
+
var insert: String = option.get("insert",option.text)
|
|
157
|
+
var remaining := insert.substr(end-start)
|
|
158
|
+
if replace and not option.get("path",false):
|
|
159
|
+
while end < line.length() and (line[end].is_valid_identifier() or line[end].is_valid_int()): end += 1
|
|
160
|
+
else:
|
|
161
|
+
var matched := 0
|
|
162
|
+
while end < line.length() and matched < remaining.length() and line[end] == remaining[matched]: end += 1; matched += 1
|
|
163
|
+
if option.get("path",false) and insert[-1] in ['"',"'"] and end < line.length() and line[end] == insert[-1]: end += 1
|
|
164
|
+
var requests: Array = option.get("imports",[])
|
|
165
|
+
var plan: Dictionary = entry.model.import_plan(code.text,entry.path,requests) if not requests.is_empty() else {"row":0,"text":""}
|
|
166
|
+
code.cancel_code_completion()
|
|
167
|
+
entry.mutating = true
|
|
168
|
+
code.begin_complex_operation()
|
|
169
|
+
if code.has_selection():
|
|
170
|
+
code.insert_text_at_caret(insert)
|
|
171
|
+
else:
|
|
172
|
+
code.remove_text(row,start,row,end)
|
|
173
|
+
code.set_caret_line(row)
|
|
174
|
+
code.set_caret_column(start)
|
|
175
|
+
code.insert_text_at_caret(insert)
|
|
176
|
+
_apply_imports(code,plan)
|
|
177
|
+
code.end_complex_operation()
|
|
178
|
+
entry.mutating = false
|
|
179
|
+
_changed(id,false)
|
|
180
|
+
if insert.ends_with("/"): code.request_code_completion(false)
|
|
181
|
+
func add_missing_imports() -> void:
|
|
182
|
+
for id in entries:
|
|
183
|
+
var entry: Dictionary = entries[id]
|
|
184
|
+
var code = entry.code.get_ref()
|
|
185
|
+
if code == null or not code.is_visible_in_tree(): continue
|
|
186
|
+
var plan: Dictionary = entry.model.import_plan(code.text,entry.path)
|
|
187
|
+
entry.mutating = true
|
|
188
|
+
code.begin_complex_operation()
|
|
189
|
+
_apply_imports(code,plan)
|
|
190
|
+
code.end_complex_operation()
|
|
191
|
+
entry.mutating = false
|
|
192
|
+
_changed(id,false)
|
|
193
|
+
return
|
|
194
|
+
func _hint(id: int) -> void:
|
|
195
|
+
if not _active or not entries.has(id) or entries[id].mutating: return
|
|
196
|
+
var entry: Dictionary = entries[id]
|
|
197
|
+
var code = entry.code.get_ref()
|
|
198
|
+
if code == null: return
|
|
199
|
+
entry.hint = entry.model.call_hint(code.text,entry.path,entry.lexical,code.get_caret_line(),code.get_caret_column())
|
|
200
|
+
code.set_code_hint(entry.hint)
|
|
201
|
+
func _lookup(symbol: String, _row: int, _column: int, id: int) -> void:
|
|
202
|
+
if not entries.has(id): return
|
|
203
|
+
var entry: Dictionary = entries[id]
|
|
204
|
+
var code = entry.code.get_ref()
|
|
205
|
+
if code == null: return
|
|
206
|
+
var path: String = entry.model.definition(code.text,entry.path,symbol)
|
|
207
|
+
if not path.is_empty(): navigation.open(path)
|
|
208
|
+
func _analyze() -> void:
|
|
209
|
+
if not _active: return
|
|
210
|
+
var records: Array = []
|
|
211
|
+
for id in entries.keys():
|
|
212
|
+
var entry: Dictionary = entries[id]
|
|
213
|
+
var code = entry.code.get_ref()
|
|
214
|
+
if code == null: entries.erase(id); continue
|
|
215
|
+
if entry.pending:
|
|
216
|
+
entry.pending = false
|
|
217
|
+
var source := Source.new(code.text,entry.path)
|
|
218
|
+
var module = Parser.new(source).parse()
|
|
219
|
+
if module != null: Bindable.new(source).apply(module)
|
|
220
|
+
entry.records = []
|
|
221
|
+
for diagnostic in source.diagnostics:
|
|
222
|
+
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})
|
|
223
|
+
_mark(entry)
|
|
224
|
+
records.append_array(entry.records)
|
|
225
|
+
diagnostics_changed.emit(records,"Typing feedback — syntax only; save/Play validates semantics")
|
|
226
|
+
func report_build(report: Dictionary) -> void:
|
|
227
|
+
for entry in entries.values():
|
|
228
|
+
entry.records = []
|
|
229
|
+
entry.pending = false
|
|
230
|
+
for item in report.get("source_diagnostics",[]):
|
|
231
|
+
var record: Dictionary = item.duplicate()
|
|
232
|
+
if not record.source.begins_with("res://"): record.source = "res://"+record.source
|
|
233
|
+
for entry in entries.values():
|
|
234
|
+
if entry.path == record.source: entry.records.append(record)
|
|
235
|
+
for entry in entries.values(): _mark(entry)
|
|
236
|
+
func _mark(entry: Dictionary) -> void:
|
|
237
|
+
var code = entry.code.get_ref()
|
|
238
|
+
if code == null: return
|
|
239
|
+
var gutter := _gutter_index(code)
|
|
240
|
+
if gutter < 0: return
|
|
241
|
+
var stale: Array = entry.marked if entry.line_count == code.get_line_count() else range(code.get_line_count())
|
|
242
|
+
for line in stale:
|
|
243
|
+
code.set_line_gutter_text(line,gutter,"")
|
|
244
|
+
code.set_line_gutter_metadata(line,gutter,null)
|
|
245
|
+
code.set_line_gutter_clickable(line,gutter,false)
|
|
246
|
+
entry.marked = []
|
|
247
|
+
entry.line_count = code.get_line_count()
|
|
248
|
+
for record in entry.records:
|
|
249
|
+
var row := clampi(record.line-1,0,code.get_line_count()-1)
|
|
250
|
+
if row not in entry.marked: entry.marked.append(row)
|
|
251
|
+
code.set_line_gutter_text(row,gutter,"!")
|
|
252
|
+
code.set_line_gutter_item_color(row,gutter,code.get_theme_color("error_color","Editor"))
|
|
253
|
+
code.set_line_gutter_metadata(row,gutter,record)
|
|
254
|
+
code.set_line_gutter_clickable(row,gutter,true)
|
|
255
|
+
func _gutter_clicked(line: int, gutter: int, id: int) -> void:
|
|
256
|
+
if not entries.has(id): return
|
|
257
|
+
var code = entries[id].code.get_ref()
|
|
258
|
+
if code != null and _gutter_index(code) == gutter:
|
|
259
|
+
var record = code.get_line_gutter_metadata(line,gutter)
|
|
260
|
+
if record is Dictionary: navigate(record)
|
|
261
|
+
static func scalar_column(text: String, column: int) -> int:
|
|
262
|
+
var units := 0
|
|
263
|
+
var index := 0
|
|
264
|
+
while index < text.length() and units < maxi(0,column-1):
|
|
265
|
+
units += 2 if text.unicode_at(index) > 0xffff else 1
|
|
266
|
+
index += 1
|
|
267
|
+
return index
|
|
268
|
+
func navigate(record: Dictionary) -> void:
|
|
269
|
+
var target := str(record.source)
|
|
270
|
+
if not target.begins_with("res://"): target = "res://"+target
|
|
271
|
+
var generation := _generation
|
|
272
|
+
await navigation.open(target)
|
|
273
|
+
var deadline := Time.get_ticks_msec()+5000
|
|
274
|
+
while _active and generation == _generation and Time.get_ticks_msec() < deadline:
|
|
275
|
+
for entry in entries.values():
|
|
276
|
+
if entry.path != target: continue
|
|
277
|
+
var code = entry.code.get_ref()
|
|
278
|
+
if code == null or not code.is_visible_in_tree(): continue
|
|
279
|
+
var row := clampi(int(record.line)-1,0,code.get_line_count()-1)
|
|
280
|
+
var column := scalar_column(code.get_line(row),int(record.column))
|
|
281
|
+
code.set_caret_line(row)
|
|
282
|
+
code.set_caret_column(column)
|
|
283
|
+
code.set_line_as_center_visible(row)
|
|
284
|
+
code.grab_focus()
|
|
285
|
+
return
|
|
286
|
+
await get_tree().process_frame
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://c59p2w2nmld
|