diff --git a/godot-scripts/Collector.gd b/godot-scripts/Collector.gd index 65367d2..49a312a 100644 --- a/godot-scripts/Collector.gd +++ b/godot-scripts/Collector.gd @@ -1,6 +1,15 @@ +# 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.new() + + +func _init() -> void: + 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) # Returns a list of file paths found in the directory. @@ -90,9 +99,31 @@ 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() + remove_warning_comments(symbols) data["classes"].append(symbols) return data +# 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"] = remove_warnings_from_description(metadata["description"]) + + for sub_class in symbols["sub_classes"]: + remove_warning_comments(sub_class) + + +func remove_warnings_from_description(description: String) -> String: + var lines := description.strip_edges().split("\n") + var clean_lines := PoolStringArray() + for line in lines: + if not warnings_regex.search(line): + clean_lines.append(line) + return clean_lines.join("\n") + + func print_pretty_json(reference: Dictionary) -> String: return JSON.print(reference, " ")