Skip to content

Commit 3f3a377

Browse files
committed
Add ignore to config for skipping watched files
* Leverages the .sentry.yml to add a list of patterns for files to ignore from the watched file paths. This can be useful for developers whose editors produce temporary dotfiles (lock and/or autosave files) for which it may not be desired to watch.
1 parent 40a9685 commit 3f3a377

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

.sentry.example.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ run_args:
3232
watch:
3333
- ./src/**/*.cr
3434
- ./src/**/*.ecr
35+
36+
# The list of patterns of files to ignore from the watched file paths.
37+
ignore:
38+
- /\.swp$/
39+
- /^\.#/

src/sentry.cr

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ module Sentry
4242
watch: {
4343
type: Array(String),
4444
default: ["./src/**/*.cr", "./src/**/*.ecr"],
45+
},
46+
ignore: {
47+
type: Array(String),
48+
default: [] of String,
4549
}
4650
)
4751

@@ -59,6 +63,7 @@ module Sentry
5963
@run = nil
6064
@run_args = ""
6165
@watch = [] of String
66+
@ignore = [] of String
6267
end
6368

6469
def display_name
@@ -120,6 +125,7 @@ module Sentry
120125
self.run = other.run if other.sets_run_command?
121126
self.run_args = other.run_args.join(" ") unless other.run_args.empty?
122127
self.watch = other.watch unless other.watch.empty?
128+
self.ignore = other.ignore unless other.ignore.empty?
123129
end
124130

125131
def to_s(io : IO)
@@ -133,6 +139,7 @@ module Sentry
133139
run: #{run}
134140
run_args: #{run_args}
135141
watch: #{watch}
142+
ignore: #{ignore}
136143
CONFIG
137144
end
138145
end
@@ -142,6 +149,7 @@ module Sentry
142149
property display_name : String
143150
property should_build = true
144151
property files = [] of String
152+
property ignore_regexes = [] of Regex
145153

146154
def initialize(
147155
@display_name : String,
@@ -150,9 +158,11 @@ module Sentry
150158
@build_args : Array(String) = [] of String,
151159
@run_args : Array(String) = [] of String,
152160
files = [] of String,
161+
ignore_regexes = [] of String,
153162
should_build = true
154163
)
155164
@files = files
165+
@ignore_regexes = ignore_regexes.map { |regex| Regex.new(regex.strip("/")) }
156166
@should_build = should_build
157167
@should_kill = false
158168
@app_built = false
@@ -204,13 +214,14 @@ module Sentry
204214
end
205215
end
206216

207-
# Scans all of the `@files`
217+
# Scans all of the `@files`, expect where matched with `@ignore_regexes`
208218
#
209219
def scan_files
210220
file_changed = false
211221
app_process = @app_process
212222
files = @files
213223
Dir.glob(files) do |file|
224+
next if @ignore_regexes.any? { |r| r === file || r === file.split("/").last }
214225
timestamp = get_timestamp(file)
215226
if FILE_TIMESTAMPS[file]? && FILE_TIMESTAMPS[file] != timestamp
216227
FILE_TIMESTAMPS[file] = timestamp

src/sentry_cli.cr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ if Sentry::Config.shard_name
8181
build_args: config.build_args,
8282
run_args: config.run_args,
8383
should_build: config.should_build?,
84-
files: config.watch
84+
files: config.watch,
85+
ignore_regexes: config.ignore
8586
)
8687

8788
process_runner.run

0 commit comments

Comments
 (0)