FileWatcher¶
File system watching for monitoring file changes.
FileSystemWatcher
¶
FileSystemWatcher(client: VSCodeClient, watcher_id: str, glob_pattern: str, ignore_create_events: bool = False, ignore_change_events: bool = False, ignore_delete_events: bool = False)
Watches for file system changes (create, change, delete).
File system watchers use glob patterns to match files and can monitor workspace folders or specific paths.
Initialize a FileSystemWatcher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
VSCodeClient
|
The VSCodeClient instance |
required |
watcher_id
|
str
|
Unique identifier for this watcher |
required |
glob_pattern
|
str
|
Glob pattern to match files (e.g., '*/.py') |
required |
ignore_create_events
|
bool
|
If true, file creation events are ignored |
False
|
ignore_change_events
|
bool
|
If true, file change events are ignored |
False
|
ignore_delete_events
|
bool
|
If true, file deletion events are ignored |
False
|
Source code in vscode_sockpuppet/filewatcher.py
on_did_create
¶
Register a handler for file creation events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
Callable[[str], None]
|
Callback function that takes a file URI string |
required |
Returns:
| Type | Description |
|---|---|
Callable[[], None]
|
Dispose function to unregister the handler |
Example
def on_file_created(uri: str): print(f"File created: {uri}")
watcher = workspace.create_file_system_watcher("*/.py") dispose = watcher.on_did_create(on_file_created)
Later, to stop listening:¶
dispose()
Source code in vscode_sockpuppet/filewatcher.py
on_did_change
¶
Register a handler for file change events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
Callable[[str], None]
|
Callback function that takes a file URI string |
required |
Returns:
| Type | Description |
|---|---|
Callable[[], None]
|
Dispose function to unregister the handler |
Example
def on_file_changed(uri: str): print(f"File changed: {uri}")
watcher = workspace.create_file_system_watcher("*/.py") dispose = watcher.on_did_change(on_file_changed)
Source code in vscode_sockpuppet/filewatcher.py
on_did_delete
¶
Register a handler for file deletion events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
Callable[[str], None]
|
Callback function that takes a file URI string |
required |
Returns:
| Type | Description |
|---|---|
Callable[[], None]
|
Dispose function to unregister the handler |
Example
def on_file_deleted(uri: str): print(f"File deleted: {uri}")
watcher = workspace.create_file_system_watcher("*/.py") dispose = watcher.on_did_delete(on_file_deleted)
Source code in vscode_sockpuppet/filewatcher.py
dispose
¶
Dispose the file system watcher and stop watching for events.
Example
watcher = workspace.create_file_system_watcher("*/.py")
... use watcher ...¶
watcher.dispose() # Stop watching