Skip to content

Commit 0f0d66f

Browse files
Added ignored directories for on-save functionality (#191)
* Added ignored directories for on-save functionality * Update ignore directory logic to normalize directories and use path parts --------- Co-authored-by: Nathan Lovato <12694995+NathanLovato@users.noreply.github.com>
1 parent c206c33 commit 0f0d66f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

addons/GDQuest_GDScript_formatter/plugin.gd

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const SETTING_FORMATTER_PATH = "formatter_path"
2222
const SETTING_LINT_ON_SAVE = "lint_on_save"
2323
const SETTING_LINT_LINE_LENGTH = "lint_line_length"
2424
const SETTING_LINT_IGNORED_RULES = "lint_ignored_rules"
25+
# Directories to ignore when Format on Save is enabled
26+
const SETTING_IGNORED_DIRECTORIES = "format_on_save_ignored_directories"
2527

2628
const COMMAND_PALETTE_CATEGORY = "gdquest gdscript formatter/"
2729
const COMMAND_PALETTE_FORMAT_SCRIPT = "Format GDScript"
@@ -30,7 +32,7 @@ const COMMAND_PALETTE_INSTALL_UPDATE = "Install or Update Formatter"
3032
const COMMAND_PALETTE_UNINSTALL = "Uninstall Formatter"
3133
const COMMAND_PALETTE_REPORT_ISSUE = "Report Issue"
3234

33-
const DEFAULT_SETTINGS = {
35+
var DEFAULT_SETTINGS = {
3436
SETTING_FORMAT_ON_SAVE: false,
3537
SETTING_USE_SPACES: false,
3638
SETTING_INDENT_SIZE: 4,
@@ -40,6 +42,7 @@ const DEFAULT_SETTINGS = {
4042
SETTING_LINT_ON_SAVE: false,
4143
SETTING_LINT_LINE_LENGTH: 100,
4244
SETTING_LINT_IGNORED_RULES: "",
45+
SETTING_IGNORED_DIRECTORIES: PackedStringArray(["addons/"]),
4346
}
4447

4548
## Which gutter lint icons are shown in.
@@ -203,6 +206,24 @@ func _on_resource_saved(saved_resource: Resource) -> void:
203206

204207
var script := saved_resource as GDScript
205208

209+
var ignored_directories := get_editor_setting(SETTING_IGNORED_DIRECTORIES)
210+
var path = script.resource_path.trim_prefix("res://")
211+
212+
var script_path_parts := path.split("/")
213+
214+
for directory: String in ignored_directories:
215+
var normalized_dir := directory.trim_prefix("res://")
216+
var directory_parts := normalized_dir.split("/")
217+
218+
var matches := true
219+
for i in range(directory_parts.size()):
220+
if directory_parts[i] != script_path_parts[i]:
221+
matches = false
222+
break
223+
224+
if matches:
225+
return
226+
206227
if not has_command(get_editor_setting(SETTING_FORMATTER_PATH)) or not is_instance_valid(script):
207228
return
208229

0 commit comments

Comments
 (0)