diff --git a/godot-scripts/Collector.gd b/godot-scripts/Collector.gd index d6b0cba..49a312a 100644 --- a/godot-scripts/Collector.gd +++ b/godot-scripts/Collector.gd @@ -1,16 +1,16 @@ +# Finds and generates a code reference from gdscript files. tool extends SceneTree -# Finds and generates a code reference from gdscript files. -var warnings_regex: RegEx +var warnings_regex := RegEx.new() + func _init() -> void: - warnings_regex = RegEx.new() - var pattern := "^\\s?(warning-ignore(-all|):\\w+|warnings-disable)\\s*$" var error := warnings_regex.compile(pattern) if error != OK: - printerr("Failed to compile '%s' to a regex pattern" % pattern) + printerr("Failed to compile '%s' to a regex pattern." % pattern) + # Returns a list of file paths found in the directory. # @@ -99,24 +99,24 @@ func get_reference(files := PoolStringArray(), refresh_cache := false) -> Dictio var symbols: Dictionary = workspace.generate_script_api(file) if symbols.has("name") and symbols["name"] == "": symbols["name"] = file.get_file() - clean_symbols(symbols) + remove_warning_comments(symbols) data["classes"].append(symbols) return data -# Takes a dictionary of code reference data and normalize it -# like stripping off 'warning-ignore' comments -func clean_symbols(symbols: Dictionary) -> void: - if not warnings_regex.is_valid(): - return - symbols["description"] = clean_description(symbols["description"]) + +# Directly removes 'warning-ignore', 'warning-ignore-all', and 'warning-disable' +# comments from all symbols in the `symbols` dictionary passed to the function. +func remove_warning_comments(symbols: Dictionary) -> void: + symbols["description"] = remove_warnings_from_description(symbols["description"]) for meta in ["constants", "members", "signals", "methods", "static_functions"]: for metadata in symbols[meta]: - metadata["description"] = clean_description(metadata["description"]) + metadata["description"] = remove_warnings_from_description(metadata["description"]) for sub_class in symbols["sub_classes"]: - clean_symbols(sub_class) + remove_warning_comments(sub_class) -func clean_description(description: String) -> String: + +func remove_warnings_from_description(description: String) -> String: var lines := description.strip_edges().split("\n") var clean_lines := PoolStringArray() for line in lines: @@ -124,5 +124,6 @@ func clean_description(description: String) -> String: clean_lines.append(line) return clean_lines.join("\n") + func print_pretty_json(reference: Dictionary) -> String: return JSON.print(reference, " ")