Skip to content

Add file system watcher for reactive sidebar updates#33

Merged
7sg56 merged 7 commits intomainfrom
copilot/fix-sidebar-file-sync-issue
Mar 7, 2026
Merged

Add file system watcher for reactive sidebar updates#33
7sg56 merged 7 commits intomainfrom
copilot/fix-sidebar-file-sync-issue

Conversation

Copy link
Contributor

Copilot AI commented Mar 6, 2026

What does this PR do?

The sidebar file explorer doesn't react to external filesystem changes — files created, deleted, or renamed outside the app (terminal, other editors) are invisible until manual refresh or restart.

Adds a notify-based file watcher on the Rust backend that emits debounced Tauri events to the frontend on structural changes (create/remove/rename). The frontend listens and auto-refreshes the file tree.

Backend (src-tauri/):

  • watcher.rsFileWatcherState wrapping notify::RecommendedWatcher with 300ms debounce via AtomicBool + timer thread. Only fires on structural events (create/remove/rename), not content modifications.
  • commands.rswatch_workspace / unwatch_workspace Tauri commands
  • lib.rs — Registers FileWatcherState as managed state
  • Cargo.toml — Added notify = "6", tempfile = "3" (dev, fixes pre-existing test gap)

Frontend (src/):

  • hooks/useFileWatcher.ts — Starts watcher on workspace load, listens for "workspace-changed" events, triggers refresh with concurrent-call guard
  • App.tsx — Wires up useFileWatcher()
// watcher.rs — event filter: only structural changes trigger sidebar refresh
let is_structural_change = matches!(
    event.kind,
    EventKind::Create(_) | EventKind::Remove(_)
        | EventKind::Modify(notify::event::ModifyKind::Name(_))
);

Merge conflict resolution:

  • Merged origin/main into PR branch to resolve conflicts with the search feature (search_workspace command, SearchPanel component, and related changes in commands.rs, lib.rs, and App.tsx)
  • Resolved App.tsx conflict from main's single-quote style migration; updated useFileWatcher.ts to match project's new Prettier config (singleQuote: true)

Related issue

Checklist

  • I tested my changes
  • I didn't break existing functionality
  • I followed repo style

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits March 6, 2026 11:00
- Add `notify` crate for file watching (Rust backend)
- Add `tempfile` dev-dependency (fixes pre-existing test issue)
- Create `watcher.rs` module with debounced FileWatcherState
- Add `watch_workspace` and `unwatch_workspace` Tauri commands
- Register watcher state and commands in lib.rs
- Create `useFileWatcher` hook for frontend event listening
- Integrate file watcher hook in App.tsx

Co-authored-by: 7sg56 <102475617+7sg56@users.noreply.github.com>
Co-authored-by: 7sg56 <102475617+7sg56@users.noreply.github.com>
@7sg56 7sg56 added the bug Something isn't working label Mar 6, 2026
Copilot AI changed the title [WIP] Fix sidebar not reflecting local file changes Add file system watcher for reactive sidebar updates Mar 6, 2026
Copilot finished work on behalf of 7sg56 March 6, 2026 11:07
@7sg56
Copy link
Owner

7sg56 commented Mar 6, 2026

@copilot there are conflicts

Copilot AI and others added 3 commits March 6, 2026 11:50
Co-authored-by: 7sg56 <102475617+7sg56@users.noreply.github.com>
…ile-sync-issue

# Conflicts:
#	src-tauri/src/commands.rs
#	src-tauri/src/lib.rs
Co-authored-by: 7sg56 <102475617+7sg56@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 6, 2026

@copilot there are conflicts

Resolved in 179ce0e. Merged origin/main into the PR branch — the conflicts were in commands.rs (duplicate SearchResult struct + search_workspace function from the search feature) and lib.rs (overlapping invoke handler registrations). Both files now include both the search feature and the file watcher additions. Build, tests, lint, and typecheck all pass.

Copilot finished work on behalf of 7sg56 March 6, 2026 11:53
@7sg56
Copy link
Owner

7sg56 commented Mar 6, 2026

There exists conflict.tsx @copilot

@7sg56
Copy link
Owner

7sg56 commented Mar 7, 2026

fix the conflicts @copilot

Copy link
Contributor Author

Copilot AI commented Mar 7, 2026

fix the conflicts @copilot

Resolved in 7a52e59. Merged origin/main into the PR branch — the conflict was in src/App.tsx where main switched to single-quote imports. Also updated useFileWatcher.ts to match the project's new single-quote Prettier config. Typecheck and lint both pass.

Copilot finished work on behalf of 7sg56 March 7, 2026 18:00
@7sg56 7sg56 marked this pull request as ready for review March 7, 2026 18:06
@7sg56 7sg56 merged commit 98b73f7 into main Mar 7, 2026
8 checks passed
@7sg56 7sg56 deleted the copilot/fix-sidebar-file-sync-issue branch March 7, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants