@@ -127,6 +127,13 @@ func read_script(p_s:Script):
127127 if inst .has_method ("free" ):
128128 inst .free ()
129129
130+ func find_code_edits (parent :Node = SE ) -> Array [CodeEdit ]:
131+ var _to_return : Array [CodeEdit ] = []
132+ var _nodes = parent .find_children ("*" ,& "CodeEdit" ,true ,false )
133+ for n in _nodes :
134+ _to_return .append (n as CodeEdit )
135+ return _to_return
136+
130137func _readd_static_typing (p_script :Script ,p_info :String ):
131138 if p_info == "" :
132139 return
@@ -137,6 +144,13 @@ func _readd_static_typing(p_script:Script,p_info:String):
137144 if s .ends_with ("-" ):
138145 slices [i ] = s .trim_suffix ("-" ).to_int ()
139146 var s_c = p_script .source_code
147+ var code_edit : CodeEdit
148+ if len (slices ) > 1 :
149+ var candidates = find_code_edits ()
150+ for c in candidates :
151+ if c .text == s_c :
152+ code_edit = c
153+ break
140154 for i in range (1 ,len (slices ),2 ):
141155 var pos = slices [i - 1 ] as int
142156 var typing = slices [i ] as String
@@ -150,8 +164,9 @@ func _readd_static_typing(p_script:Script,p_info:String):
150164# for m in regex.search_all(p_script.source_code,pos,pos+len(typing)):
151165# print(m.get_string(0))
152166 s_c = regex .sub (s_c ,":" + typing ,true ,pos ,pos + len (typing )+ 1 )
153- p_script .source_code = s_c .trim_suffix (p_info )
154- p_script .changed .emit ()
167+ if code_edit :
168+ print ("Readed static typing in '" ,p_script .resource_path ,"' successfully." )
169+ code_edit .text = s_c .trim_suffix ("\n #" + p_info )
155170# print(p_script.source_code)
156171
157172func _read_internal_interface (inst :BasicInterface ,interface_global_name :StringName ):
@@ -279,7 +294,10 @@ func build_from_path(path):
279294 to_readd [m .get_start ()] = m .get_string (1 ) + i_name
280295 s_c = regex .sub (s_c ," $1" + empty + "$2" ,true )
281296 file = FileAccess .open (path , FileAccess .WRITE )
282- s_c += "\n #"
297+ if s_c .ends_with ("\n #\n " ):
298+ s_c = s_c .trim_suffix ("\n " )
299+ elif not s_c .ends_with ("\n #" ):
300+ s_c += "\n #"
283301 var to_readd_keys = to_readd .keys ()
284302 to_readd_keys .sort ()
285303 for key in to_readd_keys :
0 commit comments