Skip to content

Conversation

Copy link

Copilot AI commented Aug 19, 2025

This PR addresses fundamental issues with file change detection and file system operations by migrating from VS Code's onDidSaveTextDocument event to native file watching and replacing the fdir and picomatch dependencies with VS Code's built-in file system APIs.

Key Changes

Optimized File Watching Architecture

  • Replaced onDidSaveTextDocument with dual FileSystemWatcher setup for more comprehensive and efficient change detection
  • Separate Partial File Watcher: Monitors files matching partialsList patterns and triggers compilation of ALL files when changes occur
  • Separate Non-Partial File Watcher: Monitors all SASS/SCSS files (excluding partials) and compiles only the specific changed file
  • Implemented proper cleanup with disposeFileWatchers() when stopping watch mode
  • Enhanced change handling to detect file creation, modification, and deletion events

File System API Migration

  • Removed fdir dependency completely from package.json
  • Removed picomatch dependency and replaced with VS Code's native pattern matching
  • Replaced with vscode.workspace.findFiles() for file discovery operations
  • Implemented RelativePattern for include/exclude pattern matching with simple regex-based matching for common patterns
  • Leveraged VS Code's native APIs for better cross-platform compatibility

Benefits

Better External Change Detection: The new file watching approach detects changes from:

  • Browser developer tools
  • External editors
  • File system operations outside VS Code
  • Automated build processes

Optimized Compilation Performance: The dual watcher architecture provides:

  • Targeted compilation: partial changes compile all files, non-partial changes only compile the specific file
  • Better resource utilization through dedicated watchers
  • Reduced unnecessary compilation cycles

Improved Network Drive Support: Eliminates fdir-related issues with:

  • Shadow files on network drives
  • UNC paths and mapped drives
  • File system performance bottlenecks

Enhanced Reliability: VS Code's native file system APIs provide:

  • Consistent behavior across platforms
  • Better error handling and recovery
  • Optimized performance for large workspaces
  • Reduced bundle size by removing external dependencies

Implementation Details

The migration maintains full backward compatibility with existing compilation logic while introducing more efficient file watching. The dual watcher setup ensures that partial file changes (which typically affect multiple output files) trigger full compilation, while non-partial file changes only compile the specific changed file for optimal performance.

File watchers are automatically set up when starting watch mode and properly disposed when stopping, preventing memory leaks and ensuring clean resource management.

Fixes #325.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Author

Copilot AI commented Aug 19, 2025

@glenn2223 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Co-authored-by: glenn2223 <33450392+glenn2223@users.noreply.github.com>
Copilot AI changed the title [WIP] Switching up the watching pattern and filesystem implementation Switch to VS Code file watching and replace fdir with native file system APIs Aug 19, 2025
Copilot AI requested a review from glenn2223 August 19, 2025 13:51
@glenn2223
Copy link
Owner

@copilot

Introduce a second watcher; this one will take on the responsibility of compiling all files when a partial file is saved. The current watcher will then only need to compile non-partial files.

Does this drop the requirement for picomatch?

…es, remove picomatch dependency

Co-authored-by: glenn2223 <33450392+glenn2223@users.noreply.github.com>
Copy link
Author

Copilot AI commented Sep 8, 2025

@copilot

Introduce a second watcher; this one will take on the responsibility of compiling all files when a partial file is saved. The current watcher will then only need to compile non-partial fi...

I've implemented the separate watcher approach as requested. The new implementation features:

Two Dedicated Watchers:

  • Partial File Watcher: Monitors files matching partialsList patterns and compiles ALL files when changes occur
  • Non-Partial File Watcher: Monitors all SASS/SCSS files (excluding partials) and compiles only the specific changed file

picomatch Dependency Removed:
Yes, this change successfully eliminates the requirement for picomatch! I've replaced it with VS Code's native pattern matching APIs (RelativePattern and findFiles) and simple regex-based matching for common patterns.

Benefits:

  • More efficient compilation (partial changes trigger full rebuild, non-partial changes only compile the single file)
  • Reduced bundle size by removing picomatch dependency
  • Better performance through targeted file watching

The implementation maintains backward compatibility while providing more precise change detection and compilation behavior.

Commit: 4d73d65

Copilot AI changed the title Switch to VS Code file watching and replace fdir with native file system APIs Switch to VS Code file watching, replace fdir and picomatch with native file system APIs Sep 8, 2025
…ng or encoding

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switching up the watching pattern and filesystem implementation

2 participants