From 17404dd7dff768a10c9b5d4586e01dbfc841de4f Mon Sep 17 00:00:00 2001 From: Abdera7mane <56tzminecraft@gmail.com> Date: Tue, 19 Oct 2021 16:47:08 +0100 Subject: [PATCH 1/2] Exclude warning-ignore comments when generating reference --- godot-scripts/Collector.gd | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/godot-scripts/Collector.gd b/godot-scripts/Collector.gd index 65367d2..d6b0cba 100644 --- a/godot-scripts/Collector.gd +++ b/godot-scripts/Collector.gd @@ -2,6 +2,15 @@ tool extends SceneTree # Finds and generates a code reference from gdscript files. +var warnings_regex: RegEx + +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) # Returns a list of file paths found in the directory. # @@ -90,9 +99,30 @@ 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) 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"]) + for meta in ["constants", "members", "signals", "methods", "static_functions"]: + for metadata in symbols[meta]: + metadata["description"] = clean_description(metadata["description"]) + + for sub_class in symbols["sub_classes"]: + clean_symbols(sub_class) + +func clean_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, " ") From 8ed002b13879aaeec44a0ca3cda9b446e8d8fd23 Mon Sep 17 00:00:00 2001 From: Nathan Lovato Date: Thu, 21 Oct 2021 07:42:06 -0600 Subject: [PATCH 2/2] refactor: update code style and rename functions in Collector.gd --- godot-scripts/Collector.gd | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) 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, " ")