Skip to content

Commit 83d8a26

Browse files
tx3stndaveshanley
authored andcommitted
watch directory and filter on file name
1 parent 497ff57 commit 83d8a26

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tui/lint_filewatcher.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ func (m *ViolationResultTableModel) setupFileWatcher() tea.Cmd {
6363
return nil
6464
}
6565

66-
err = m.watcher.Add(absPath)
66+
// Watch the directory instead of the specific file to handle atomic saves
67+
watchDir := filepath.Dir(absPath)
68+
err = m.watcher.Add(watchDir)
6769
if err != nil {
68-
m.watchError = fmt.Sprintf("Failed to watch file %s: %v", absPath, err)
70+
m.watchError = fmt.Sprintf("Failed to watch directory %s: %v", watchDir, err)
6971
m.watchState = WatchStateError
7072
return nil
7173
}
@@ -86,7 +88,13 @@ func (m *ViolationResultTableModel) watchFileChanges() {
8688
return
8789
}
8890

89-
if event.Has(fsnotify.Write) || event.Has(fsnotify.Rename) {
91+
// Only process events for our target file
92+
targetFile := m.watchedFiles[0] // The absolute path of our spec file
93+
if event.Name != targetFile {
94+
continue
95+
}
96+
97+
if event.Has(fsnotify.Write) || event.Has(fsnotify.Rename) || event.Has(fsnotify.Create) {
9098
select {
9199
case m.watchMsgChan <- fileChangeMsg{fileName: event.Name}:
92100
default:

0 commit comments

Comments
 (0)