Skip to content

Commit

Permalink
refactor: update code style and rename functions in Collector.gd
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanLovato committed Oct 21, 2021
1 parent 17404dd commit 8ed002b
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions godot-scripts/Collector.gd
Original file line number Diff line number Diff line change
@@ -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.
#
Expand Down Expand Up @@ -99,30 +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()
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:
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, " ")

0 comments on commit 8ed002b

Please sign in to comment.