Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using FileSystemWatcher in Typescript (Visual Studio Code extension)

I am new to TypeScript and Visual Studio Code and want to develop a plugin for Visual Studio Code. But I am hung up with an event fired by a FileSystemWatcher. On activation, in my extension I create a FileSystemWatcher and want it to inform me about changes to all TypeScript files. This is what I've been doing so far:

var watcher = vscode.workspace.createFileSystemWatcher("*.ts"); //glob search string
watcher.ignoreChangeEvents = false;

watcher.onDidChange(() => {
 vscode.window.showInformationMessage("change applied!"); //In my opinion this should be called
});

I can see in debug that the watcher is created, but it never reacts to the event. Can someone explain how to use this callback the right way?

This is an event accessible via a function:

watcher.onDidChange
like image 298
Sebi Avatar asked Aug 16 '26 23:08

Sebi


1 Answers

On

var watcher = vscode.workspace.createFileSystemWatcher("*.ts");

please use "**/*.ts instead of "*.ts".

like image 177
Adiono Avatar answered Aug 18 '26 14:08

Adiono



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!