some optimization on addons
This commit is contained in:
parent
186cb926e8
commit
9f4c9edd43
2 changed files with 33 additions and 30 deletions
|
@ -23,7 +23,7 @@ static func _blank_for_func_class(code: String) -> String:
|
||||||
var comment_line_regex = RegEx.create_from_string(r"^\s*#")
|
var comment_line_regex = RegEx.create_from_string(r"^\s*#")
|
||||||
var empty_line_regex = RegEx.create_from_string(r"^\s+$")
|
var empty_line_regex = RegEx.create_from_string(r"^\s+$")
|
||||||
var lines := code.split('\n')
|
var lines := code.split('\n')
|
||||||
var modified_lines: Array[String] = []
|
var modified_lines: PackedStringArray = []
|
||||||
|
|
||||||
for line: String in lines:
|
for line: String in lines:
|
||||||
# Spaces between functions & classes
|
# Spaces between functions & classes
|
||||||
|
|
|
@ -6,20 +6,22 @@ const Dock := preload("res://addons/Todo_Manager/Dock.gd")
|
||||||
const Todo := preload("res://addons/Todo_Manager/todo_class.gd")
|
const Todo := preload("res://addons/Todo_Manager/todo_class.gd")
|
||||||
const TodoItem := preload("res://addons/Todo_Manager/todoItem_class.gd")
|
const TodoItem := preload("res://addons/Todo_Manager/todoItem_class.gd")
|
||||||
|
|
||||||
var _dockUI : Dock
|
var _dockUI: Dock
|
||||||
|
|
||||||
|
|
||||||
class TodoCacheValue:
|
class TodoCacheValue:
|
||||||
var todos: Array
|
var todos: Array
|
||||||
var last_modified_time: int
|
var last_modified_time: int
|
||||||
|
|
||||||
|
|
||||||
func _init(todos: Array, last_modified_time: int):
|
func _init(todos: Array, last_modified_time: int):
|
||||||
self.todos = todos
|
self.todos = todos
|
||||||
self.last_modified_time = last_modified_time
|
self.last_modified_time = last_modified_time
|
||||||
|
|
||||||
var todo_cache : Dictionary # { key: script_path, value: TodoCacheValue }
|
var todo_cache: Dictionary # { key: script_path, value: TodoCacheValue }
|
||||||
var remove_queue : Array
|
var remove_queue: Array
|
||||||
var combined_pattern : String
|
var combined_pattern: String
|
||||||
var cased_patterns : Array[String]
|
var cased_patterns: PackedStringArray
|
||||||
|
|
||||||
var refresh_lock := false # makes sure _on_filesystem_changed only triggers once
|
var refresh_lock := false # makes sure _on_filesystem_changed only triggers once
|
||||||
|
|
||||||
|
@ -27,7 +29,7 @@ var refresh_lock := false # makes sure _on_filesystem_changed only triggers once
|
||||||
func _enter_tree() -> void:
|
func _enter_tree() -> void:
|
||||||
_dockUI = DockScene.instantiate() as Control
|
_dockUI = DockScene.instantiate() as Control
|
||||||
add_control_to_bottom_panel(_dockUI, "TODO")
|
add_control_to_bottom_panel(_dockUI, "TODO")
|
||||||
get_editor_interface().get_resource_filesystem().connect("filesystem_changed",
|
get_editor_interface().get_resource_filesystem().connect("filesystem_changed",
|
||||||
_on_filesystem_changed)
|
_on_filesystem_changed)
|
||||||
get_editor_interface().get_file_system_dock().connect("file_removed", queue_remove)
|
get_editor_interface().get_file_system_dock().connect("file_removed", queue_remove)
|
||||||
get_editor_interface().get_script_editor().connect("editor_script_changed",
|
get_editor_interface().get_script_editor().connect("editor_script_changed",
|
||||||
|
@ -51,7 +53,7 @@ func queue_remove(file: String):
|
||||||
_dockUI.todo_items.remove_at(i)
|
_dockUI.todo_items.remove_at(i)
|
||||||
|
|
||||||
|
|
||||||
func find_tokens_from_path(scripts: Array[String]) -> void:
|
func find_tokens_from_path(scripts: PackedStringArray) -> void:
|
||||||
for script_path in scripts:
|
for script_path in scripts:
|
||||||
var file := FileAccess.open(script_path, FileAccess.READ)
|
var file := FileAccess.open(script_path, FileAccess.READ)
|
||||||
var contents := file.get_as_text()
|
var contents := file.get_as_text()
|
||||||
|
@ -85,13 +87,13 @@ func find_tokens(text: String, script_path: String) -> void:
|
||||||
var regex = RegEx.new()
|
var regex = RegEx.new()
|
||||||
# if regex.compile("#\\s*\\bTODO\\b.*|#\\s*\\bHACK\\b.*") == OK:
|
# if regex.compile("#\\s*\\bTODO\\b.*|#\\s*\\bHACK\\b.*") == OK:
|
||||||
if regex.compile(combined_pattern) == OK:
|
if regex.compile(combined_pattern) == OK:
|
||||||
var result : Array[RegExMatch] = regex.search_all(text)
|
var result: Array[RegExMatch] = regex.search_all(text)
|
||||||
if result.is_empty():
|
if result.is_empty():
|
||||||
for i in _dockUI.todo_items.size():
|
for i in _dockUI.todo_items.size():
|
||||||
if _dockUI.todo_items[i].script_path == script_path:
|
if _dockUI.todo_items[i].script_path == script_path:
|
||||||
_dockUI.todo_items.remove_at(i)
|
_dockUI.todo_items.remove_at(i)
|
||||||
return # No tokens found
|
return # No tokens found
|
||||||
var match_found : bool
|
var match_found: bool
|
||||||
var i := 0
|
var i := 0
|
||||||
for todo_item in _dockUI.todo_items:
|
for todo_item in _dockUI.todo_items:
|
||||||
if todo_item.script_path == script_path:
|
if todo_item.script_path == script_path:
|
||||||
|
@ -111,7 +113,7 @@ func create_todo_item(regex_results: Array[RegExMatch], text: String, script_pat
|
||||||
var last_line_number := 0
|
var last_line_number := 0
|
||||||
var lines := text.split("\n")
|
var lines := text.split("\n")
|
||||||
for r in regex_results:
|
for r in regex_results:
|
||||||
var new_todo : Todo = create_todo(r.get_string(), script_path)
|
var new_todo: Todo = create_todo(r.get_string(), script_path)
|
||||||
new_todo.line_number = get_line_number(r.get_string(), text, last_line_number)
|
new_todo.line_number = get_line_number(r.get_string(), text, last_line_number)
|
||||||
# GD Multiline comment
|
# GD Multiline comment
|
||||||
var trailing_line := new_todo.line_number
|
var trailing_line := new_todo.line_number
|
||||||
|
@ -123,10 +125,10 @@ func create_todo_item(regex_results: Array[RegExMatch], text: String, script_pat
|
||||||
break
|
break
|
||||||
if should_break:
|
if should_break:
|
||||||
break
|
break
|
||||||
|
|
||||||
new_todo.content += "\n" + lines[trailing_line]
|
new_todo.content += "\n" + lines[trailing_line]
|
||||||
trailing_line += 1
|
trailing_line += 1
|
||||||
|
|
||||||
last_line_number = new_todo.line_number
|
last_line_number = new_todo.line_number
|
||||||
todo_item.todos.append(new_todo)
|
todo_item.todos.append(new_todo)
|
||||||
cache_todos(todo_item.todos, script_path)
|
cache_todos(todo_item.todos, script_path)
|
||||||
|
@ -137,7 +139,7 @@ func update_todo_item(todo_item: TodoItem, regex_results: Array[RegExMatch], tex
|
||||||
todo_item.todos.clear()
|
todo_item.todos.clear()
|
||||||
var lines := text.split("\n")
|
var lines := text.split("\n")
|
||||||
for r in regex_results:
|
for r in regex_results:
|
||||||
var new_todo : Todo = create_todo(r.get_string(), script_path)
|
var new_todo: Todo = create_todo(r.get_string(), script_path)
|
||||||
new_todo.line_number = get_line_number(r.get_string(), text)
|
new_todo.line_number = get_line_number(r.get_string(), text)
|
||||||
# GD Multiline comment
|
# GD Multiline comment
|
||||||
var trailing_line := new_todo.line_number
|
var trailing_line := new_todo.line_number
|
||||||
|
@ -149,7 +151,7 @@ func update_todo_item(todo_item: TodoItem, regex_results: Array[RegExMatch], tex
|
||||||
break
|
break
|
||||||
if should_break:
|
if should_break:
|
||||||
break
|
break
|
||||||
|
|
||||||
new_todo.content += "\n" + lines[trailing_line]
|
new_todo.content += "\n" + lines[trailing_line]
|
||||||
trailing_line += 1
|
trailing_line += 1
|
||||||
todo_item.todos.append(new_todo)
|
todo_item.todos.append(new_todo)
|
||||||
|
@ -178,22 +180,22 @@ func _on_filesystem_changed() -> void:
|
||||||
rescan_files(false)
|
rescan_files(false)
|
||||||
|
|
||||||
|
|
||||||
func find_scripts() -> Array[String]:
|
func find_scripts() -> PackedStringArray:
|
||||||
var scripts : Array[String]
|
var scripts: PackedStringArray
|
||||||
var directory_queue : Array[String]
|
var directory_queue: Array[String]
|
||||||
var dir := DirAccess.open("res://")
|
var dir := DirAccess.open("res://")
|
||||||
if dir.get_open_error() == OK:
|
if dir.get_open_error() == OK:
|
||||||
get_dir_contents(dir, scripts, directory_queue)
|
get_dir_contents(dir, scripts, directory_queue)
|
||||||
else:
|
else:
|
||||||
printerr("TODO_Manager: There was an error during find_scripts()")
|
printerr("TODO_Manager: There was an error during find_scripts()")
|
||||||
|
|
||||||
while not directory_queue.is_empty():
|
while not directory_queue.is_empty():
|
||||||
if dir.change_dir(directory_queue[0]) == OK:
|
if dir.change_dir(directory_queue[0]) == OK:
|
||||||
get_dir_contents(dir, scripts, directory_queue)
|
get_dir_contents(dir, scripts, directory_queue)
|
||||||
else:
|
else:
|
||||||
printerr("TODO_Manager: There was an error at: " + directory_queue[0])
|
printerr("TODO_Manager: There was an error at: " + directory_queue[0])
|
||||||
directory_queue.pop_front()
|
directory_queue.pop_front()
|
||||||
|
|
||||||
return scripts
|
return scripts
|
||||||
|
|
||||||
|
|
||||||
|
@ -206,16 +208,17 @@ func get_cached_todos(script_path: String) -> Array:
|
||||||
if todo_cache.has(script_path) and !script_path.contains("tscn::"):
|
if todo_cache.has(script_path) and !script_path.contains("tscn::"):
|
||||||
var cached_value: TodoCacheValue = todo_cache[script_path]
|
var cached_value: TodoCacheValue = todo_cache[script_path]
|
||||||
if cached_value.last_modified_time == FileAccess.get_modified_time(script_path):
|
if cached_value.last_modified_time == FileAccess.get_modified_time(script_path):
|
||||||
|
|
||||||
return cached_value.todos
|
return cached_value.todos
|
||||||
return []
|
return []
|
||||||
|
|
||||||
func get_dir_contents(dir: DirAccess, scripts: Array[String], directory_queue: Array[String]) -> void:
|
|
||||||
|
func get_dir_contents(dir: DirAccess, scripts: PackedStringArray, directory_queue: PackedStringArray) -> void:
|
||||||
dir.include_navigational = false
|
dir.include_navigational = false
|
||||||
dir.include_hidden = false
|
dir.include_hidden = false
|
||||||
dir.list_dir_begin()
|
dir.list_dir_begin()
|
||||||
var file_name : String = dir.get_next()
|
var file_name: String = dir.get_next()
|
||||||
|
|
||||||
while file_name != "":
|
while file_name != "":
|
||||||
if dir.current_is_dir():
|
if dir.current_is_dir():
|
||||||
if file_name == ".import" or file_name == ".mono": # Skip .import folder which should never have scripts
|
if file_name == ".import" or file_name == ".mono": # Skip .import folder which should never have scripts
|
||||||
|
@ -225,7 +228,7 @@ func get_dir_contents(dir: DirAccess, scripts: Array[String], directory_queue: A
|
||||||
else:
|
else:
|
||||||
if file_name.ends_with(".gd") or file_name.ends_with(".cs") \
|
if file_name.ends_with(".gd") or file_name.ends_with(".cs") \
|
||||||
or file_name.ends_with(".c") or file_name.ends_with(".cpp") or file_name.ends_with(".h") \
|
or file_name.ends_with(".c") or file_name.ends_with(".cpp") or file_name.ends_with(".h") \
|
||||||
or ((file_name.ends_with(".tscn") and _dockUI.builtin_enabled)):
|
or((file_name.ends_with(".tscn") and _dockUI.builtin_enabled)):
|
||||||
scripts.append(dir.get_current_dir().path_join(file_name))
|
scripts.append(dir.get_current_dir().path_join(file_name))
|
||||||
file_name = dir.get_next()
|
file_name = dir.get_next()
|
||||||
|
|
||||||
|
@ -245,9 +248,9 @@ func combine_patterns(patterns: Array) -> String:
|
||||||
for pattern in patterns:
|
for pattern in patterns:
|
||||||
if pattern[2] == _dockUI.CASE_INSENSITIVE:
|
if pattern[2] == _dockUI.CASE_INSENSITIVE:
|
||||||
cased_patterns.append(pattern[0].insert(0, "((?i)") + ")")
|
cased_patterns.append(pattern[0].insert(0, "((?i)") + ")")
|
||||||
else:
|
else:
|
||||||
cased_patterns.append("(" + pattern[0] + ")")
|
cased_patterns.append("(" + pattern[0] + ")")
|
||||||
|
|
||||||
if patterns.size() == 1:
|
if patterns.size() == 1:
|
||||||
return cased_patterns[0]
|
return cased_patterns[0]
|
||||||
else:
|
else:
|
||||||
|
@ -266,7 +269,7 @@ func create_todo(todo_string: String, script_path: String) -> Todo:
|
||||||
var regex = RegEx.new()
|
var regex = RegEx.new()
|
||||||
for pattern in cased_patterns:
|
for pattern in cased_patterns:
|
||||||
if regex.compile(pattern) == OK:
|
if regex.compile(pattern) == OK:
|
||||||
var result : RegExMatch = regex.search(todo_string)
|
var result: RegExMatch = regex.search(todo_string)
|
||||||
if result:
|
if result:
|
||||||
todo.pattern = pattern
|
todo.pattern = pattern
|
||||||
todo.title = result.strings[0]
|
todo.title = result.strings[0]
|
||||||
|
@ -274,7 +277,7 @@ func create_todo(todo_string: String, script_path: String) -> Todo:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
printerr("Error compiling " + pattern)
|
printerr("Error compiling " + pattern)
|
||||||
|
|
||||||
todo.content = todo_string
|
todo.content = todo_string
|
||||||
todo.script_path = script_path
|
todo.script_path = script_path
|
||||||
return todo
|
return todo
|
||||||
|
|
Loading…
Reference in a new issue