-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1714 from posit-dev/dotnomad/watcher-manager
Create watcher manager to handle file watching
- Loading branch information
Showing
6 changed files
with
128 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const POSIT_FOLDER = ".posit"; | ||
export const PUBLISH_FOLDER = ".posit/publish"; | ||
export const PUBLISH_DEPLOYMENTS_FOLDER = ".posit/publish/deployments"; | ||
|
||
export const CONFIGURATIONS_PATTERN = ".posit/publish/*.toml"; | ||
export const DEPLOYMENTS_PATTERN = ".posit/publish/deployments/*.toml"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { | ||
Disposable, | ||
RelativePattern, | ||
WorkspaceFolder, | ||
FileSystemWatcher, | ||
workspace, | ||
} from "vscode"; | ||
|
||
import { | ||
PUBLISH_DEPLOYMENTS_FOLDER, | ||
POSIT_FOLDER, | ||
PUBLISH_FOLDER, | ||
CONFIGURATIONS_PATTERN, | ||
DEPLOYMENTS_PATTERN, | ||
} from "src/constants"; | ||
|
||
/** | ||
* Manages all the file system watchers for the extension. | ||
* | ||
* The directory watchers only watch for onDidDelete events. | ||
*/ | ||
export class WatcherManager implements Disposable { | ||
positDir: FileSystemWatcher | undefined; | ||
publishDir: FileSystemWatcher | undefined; | ||
configurations: FileSystemWatcher | undefined; | ||
deploymentsDir: FileSystemWatcher | undefined; | ||
deployments: FileSystemWatcher | undefined; | ||
allFiles: FileSystemWatcher | undefined; | ||
|
||
constructor(root?: WorkspaceFolder) { | ||
if (root === undefined) { | ||
return; | ||
} | ||
|
||
this.positDir = workspace.createFileSystemWatcher( | ||
new RelativePattern(root, POSIT_FOLDER), | ||
true, | ||
true, | ||
false, | ||
); | ||
|
||
this.publishDir = workspace.createFileSystemWatcher( | ||
new RelativePattern(root, PUBLISH_FOLDER), | ||
true, | ||
true, | ||
false, | ||
); | ||
|
||
this.configurations = workspace.createFileSystemWatcher( | ||
new RelativePattern(root, CONFIGURATIONS_PATTERN), | ||
); | ||
|
||
this.deploymentsDir = workspace.createFileSystemWatcher( | ||
new RelativePattern(root, PUBLISH_DEPLOYMENTS_FOLDER), | ||
true, | ||
true, | ||
false, | ||
); | ||
|
||
this.deployments = workspace.createFileSystemWatcher( | ||
new RelativePattern(root, DEPLOYMENTS_PATTERN), | ||
); | ||
|
||
this.allFiles = workspace.createFileSystemWatcher( | ||
new RelativePattern(root, "**"), | ||
); | ||
} | ||
|
||
dispose() { | ||
this.positDir?.dispose(); | ||
this.publishDir?.dispose(); | ||
this.configurations?.dispose(); | ||
this.deploymentsDir?.dispose(); | ||
this.deployments?.dispose(); | ||
this.allFiles?.dispose(); | ||
} | ||
} |