vscode#FileChangeType TypeScript Examples
The following examples show how to use
vscode#FileChangeType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utopia-fs.ts From utopia with MIT License | 6 votes |
private async notifyFileChanged(path: string, modifiedBySelf: boolean): Promise<void> {
const uri = toUtopiaURI(this.projectID, path)
const hasUnsavedContent = await pathIsFileWithUnsavedContent(path)
const fileWasSaved = !hasUnsavedContent
if (fileWasSaved) {
// Notify VS Code of updates to the saved content
this.queueFileChangeEvent({
type: FileChangeType.Changed,
uri: uri,
})
}
if (!modifiedBySelf) {
// Notify our extension of changes coming from Utopia only
if (fileWasSaved) {
this.queueUtopiaSavedChangeEvent(uri)
} else {
this.queueUtopiaUnsavedChangeEvent(uri)
}
}
}
Example #2
Source File: VirtualFileSystemProvider.ts From vscode-drawio with GNU General Public License v3.0 | 6 votes |
public getOrCreateFile(uri: Uri): { file: File; didFileExist: boolean } {
const key = uri.toString();
const f = this.files.get(key);
if (f) {
return { file: f, didFileExist: true };
}
const newFile = new File(uri, Uint8Array.from([]));
newFile.onDidChangeFile(() =>
this.fileChangedEmitter.fire([
{ type: FileChangeType.Changed, uri: newFile.uri },
])
);
this.files.set(key, newFile);
return { file: newFile, didFileExist: false };
}
Example #3
Source File: file-watcher.ts From karma-test-explorer with MIT License | 6 votes |
private registerFileHandler(
filePatterns: readonly string[],
handler: (filePath: string, changeType: FileChangeType) => void
): FileSystemWatcher[] {
const fileWatchers: FileSystemWatcher[] = [];
const workspaceRootPath = normalizePath(this.workspaceFolder.uri.fsPath);
const relativeProjectRootPath = relative(workspaceRootPath, this.projectRootPath);
const isProjectRootSameAsWorkspace = this.projectRootPath === workspaceRootPath;
this.logger.debug(() => `Registering file handler for files: ${JSON.stringify(filePatterns, null, 2)}`);
for (const fileOrPattern of filePatterns) {
const relativeFileOrPattern = isProjectRootSameAsWorkspace
? fileOrPattern
: normalizePath(join(relativeProjectRootPath, fileOrPattern));
const absoluteFileOrPattern = new RelativePattern(this.workspaceFolder, relativeFileOrPattern);
this.logger.debug(
() =>
`Creating file watcher for file or pattern '${fileOrPattern}' ` +
`using base path: ${absoluteFileOrPattern.base}`
);
const fileWatcher = workspace.createFileSystemWatcher(absoluteFileOrPattern);
fileWatchers.push(fileWatcher);
this.disposables.push(
fileWatcher.onDidChange(fileUri => handler(normalizePath(fileUri.fsPath), FileChangeType.Changed)),
fileWatcher.onDidCreate(fileUri => handler(normalizePath(fileUri.fsPath), FileChangeType.Created)),
fileWatcher.onDidDelete(fileUri => handler(normalizePath(fileUri.fsPath), FileChangeType.Deleted))
);
}
return fileWatchers;
}
Example #4
Source File: utopia-fs.ts From utopia with MIT License | 5 votes |
private notifyFileCreated(path: string): void {
this.queueFileChangeEvent({
type: FileChangeType.Created,
uri: toUtopiaURI(this.projectID, path),
})
}
Example #5
Source File: utopia-fs.ts From utopia with MIT License | 5 votes |
private notifyFileDeleted(path: string): void {
this.queueFileChangeEvent({
type: FileChangeType.Deleted,
uri: toUtopiaURI(this.projectID, path),
})
}
Example #6
Source File: file-watcher.ts From karma-test-explorer with MIT License | 5 votes |
private createFileWatchers(): Disposable[] {
this.logger.debug(() => 'Creating file watchers for monitored files');
const reloadTriggerFilesRelativePaths = this.reloadTriggerFiles.map(triggerFile =>
normalizePath(relative(this.projectRootPath, triggerFile))
);
this.logger.trace(
() =>
`Monitored files ( configured --> normalized): ` +
`${JSON.stringify(this.reloadTriggerFiles, null, 2)} --> ` +
`${JSON.stringify(reloadTriggerFilesRelativePaths, null, 2)}`
);
const reloadTriggerFilesWatchers = this.registerFileHandler(
reloadTriggerFilesRelativePaths,
debounce(WATCHED_FILE_CHANGE_BATCH_DELAY, filePath => {
this.logger.info(() => `Reloading due to monitored file changed: ${filePath}`);
this.projectCommands.execute(ProjectCommand.Reset);
})
);
this.logger.debug(() => 'Creating file watchers for test file changes');
const testFileGlobs = this.testFilePatterns;
const reloadTestFilesWatchers = this.registerFileHandler(testFileGlobs, async (changedTestFile, changeType) => {
if (!this.testLocator?.isTestFile(changedTestFile)) {
this.logger.warn(() => `Expected changed file to be spec file but it is not: ${changedTestFile}`);
return;
}
this.logger.debug(() => `Changed file is spec file: ${changedTestFile}`);
await (changeType === FileChangeType.Deleted
? this.testLocator.removeFiles([changedTestFile])
: this.testLocator.refreshFiles([changedTestFile]));
if (this.fileWatcherOptions.retireTestsInChangedFiles) {
const changedTestIds = this.testStore?.getTestsByFile(changedTestFile).map(changedTest => changedTest.id) ?? [];
if (changedTestIds.length > 0) {
this.logger.debug(() => `Retiring ${changedTestIds.length} tests from updated spec file: ${changedTestFile}`);
this.testRetireEventEmitter.fire({ tests: changedTestIds });
}
}
});
return [...reloadTriggerFilesWatchers, ...reloadTestFilesWatchers];
}