Skip to content

Commit ba01944

Browse files
committed
chore: run gdscript-formatter over addon
1 parent 2e1a535 commit ba01944

3 files changed

Lines changed: 162 additions & 84 deletions

File tree

addons/GDQuest_GDScript_formatter/install_and_update.gd

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ func install_or_update_formatter() -> void:
3232

3333

3434
func _on_request_completed(
35-
_http_result: int,
36-
response_code: int,
37-
_http_headers: PackedStringArray,
38-
body: PackedByteArray,
35+
_http_result: int,
36+
response_code: int,
37+
_http_headers: PackedStringArray,
38+
body: PackedByteArray,
3939
) -> void:
4040
if response_code != 200:
4141
var error_message := "HTTP request failed. Response code: " + str(response_code)
@@ -78,11 +78,7 @@ func _process_response_latest_release(body: PackedByteArray) -> void:
7878
installation_failed.emit(error_message)
7979
return
8080

81-
print(
82-
"Found compatible release, starting download...\n",
83-
"Download URL: ",
84-
download_url,
85-
)
81+
print("Found compatible release, starting download...\n", "Download URL: ", download_url)
8682

8783
http_request_state = HttpRequestState.DOWNLOADING_BINARY
8884
http_request.request(download_url)
@@ -109,12 +105,7 @@ func _process_response_download_file(body: PackedByteArray) -> void:
109105
return
110106

111107
print(
112-
"\n".join(
113-
[
114-
"GDScript formatter installed successfully!",
115-
"Binary location: " + binary_path,
116-
],
117-
),
108+
"\n".join(["GDScript formatter installed successfully!", "Binary location: " + binary_path]),
118109
)
119110
installation_completed.emit(binary_path)
120111

@@ -124,7 +115,10 @@ func _get_platform_info() -> Dictionary:
124115
var processor_name := OS.get_processor_name().to_lower()
125116
var architecture := "x86_64"
126117

127-
if processor_name.contains("aarch64") or processor_name.contains("arm64") or processor_name.contains("apple"):
118+
if (
119+
processor_name.contains("aarch64") or processor_name.contains("arm64")
120+
or processor_name.contains("apple")
121+
):
128122
architecture = "aarch64"
129123
elif processor_name.contains("x86_64") or processor_name.contains("amd64"):
130124
architecture = "x86_64"
@@ -133,10 +127,7 @@ func _get_platform_info() -> Dictionary:
133127
if os_name.contains("windows"):
134128
binary_name = "gdscript-formatter.exe"
135129

136-
var platform_info := {
137-
"architecture": architecture,
138-
"binary_name": binary_name,
139-
}
130+
var platform_info := { "architecture": architecture, "binary_name": binary_name }
140131

141132
if os_name.contains("windows"):
142133
platform_info["os"] = "windows"
@@ -153,7 +144,11 @@ func _find_matching_asset(assets: Array, tag: String) -> String:
153144
if platform_info.is_empty():
154145
return ""
155146

156-
var expected_pattern := "gdscript-formatter-%s-%s-%s" % [tag, platform_info["os"], platform_info["architecture"]]
147+
var expected_pattern := "gdscript-formatter-%s-%s-%s" % [
148+
tag,
149+
platform_info["os"],
150+
platform_info["architecture"],
151+
]
157152
if platform_info["os"] == "windows":
158153
expected_pattern += ".exe"
159154
expected_pattern += ".zip"
@@ -229,15 +224,14 @@ func _download_and_install_binary(zip_data: PackedByteArray, platform_info: Dict
229224
if not OS.get_name().to_lower().contains("windows"):
230225
# This should be equivalent to setting the binary to permissions 755
231226
const UNIX_EXECUTABLE_PERMISSIONS = (
232-
FileAccess.UNIX_READ_OWNER
233-
| FileAccess.UNIX_WRITE_OWNER
234-
| FileAccess.UNIX_EXECUTE_OWNER
235-
| FileAccess.UNIX_READ_GROUP
236-
| FileAccess.UNIX_EXECUTE_GROUP
237-
| FileAccess.UNIX_READ_OTHER
238-
| FileAccess.UNIX_EXECUTE_OTHER
227+
FileAccess.UNIX_READ_OWNER | FileAccess.UNIX_WRITE_OWNER
228+
| FileAccess.UNIX_EXECUTE_OWNER | FileAccess.UNIX_READ_GROUP
229+
| FileAccess.UNIX_EXECUTE_GROUP | FileAccess.UNIX_READ_OTHER | FileAccess.UNIX_EXECUTE_OTHER
230+
)
231+
var permissions_error := FileAccess.set_unix_permissions(
232+
binary_path,
233+
UNIX_EXECUTABLE_PERMISSIONS,
239234
)
240-
var permissions_error := FileAccess.set_unix_permissions(binary_path, UNIX_EXECUTABLE_PERMISSIONS)
241235
if permissions_error != OK:
242236
push_error("Failed to make formatter executable: ", binary_path)
243237
DirAccess.remove_absolute(binary_path)

addons/GDQuest_GDScript_formatter/menu.gd

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ func _ready() -> void:
2525
var script_editor := EditorInterface.get_script_editor()
2626
var last_menu_button := _find_last_menu_button(script_editor)
2727
if not is_instance_valid(last_menu_button):
28-
push_warning("GDScript Formatter: Could not find valid menu button in script editor. Menu will not be available. Use the command palette instead.")
28+
push_warning(
29+
"GDScript Formatter: Could not find valid menu button in script editor. Menu will not be available. Use the command palette instead."
30+
)
2931
return
3032

3133
menu_button = MenuButton.new()
@@ -101,7 +103,10 @@ func _populate_menu(show_uninstall: bool = true) -> void:
101103

102104
popup_menu.add_item(MENU_ITEMS["format_script"], current_item_index)
103105
popup_menu.set_item_metadata(current_item_index, "format_script")
104-
popup_menu.set_item_tooltip(current_item_index, "Run the GDScript Formatter over the current script")
106+
popup_menu.set_item_tooltip(
107+
current_item_index,
108+
"Run the GDScript Formatter over the current script",
109+
)
105110

106111
current_item_index += 1
107112
popup_menu.add_item(MENU_ITEMS["lint_script"], current_item_index)
@@ -111,7 +116,10 @@ func _populate_menu(show_uninstall: bool = true) -> void:
111116
current_item_index += 1
112117
popup_menu.add_item(MENU_ITEMS["reorder_code"], current_item_index)
113118
popup_menu.set_item_metadata(current_item_index, "reorder_code")
114-
popup_menu.set_item_tooltip(current_item_index, "Reorder the code elements in the current script according to the GDScript Style Guide")
119+
popup_menu.set_item_tooltip(
120+
current_item_index,
121+
"Reorder the code elements in the current script according to the GDScript Style Guide",
122+
)
115123

116124
popup_menu.add_separator()
117125

@@ -121,13 +129,19 @@ func _populate_menu(show_uninstall: bool = true) -> void:
121129
current_item_index += 2
122130
popup_menu.add_item(MENU_ITEMS["install_update"], current_item_index)
123131
popup_menu.set_item_metadata(current_item_index, "install_update")
124-
popup_menu.set_item_tooltip(current_item_index, "Download the latest version of the GDScript Formatter")
132+
popup_menu.set_item_tooltip(
133+
current_item_index,
134+
"Download the latest version of the GDScript Formatter",
135+
)
125136

126137
if show_uninstall:
127138
current_item_index += 1
128139
popup_menu.add_item(MENU_ITEMS["uninstall"], current_item_index)
129140
popup_menu.set_item_metadata(current_item_index, "uninstall")
130-
popup_menu.set_item_tooltip(current_item_index, "Remove the GDScript Formatter installed through this add-on from your computer")
141+
popup_menu.set_item_tooltip(
142+
current_item_index,
143+
"Remove the GDScript Formatter installed through this add-on from your computer",
144+
)
131145

132146
popup_menu.add_separator()
133147

0 commit comments

Comments
 (0)