在 Typescript 中使用 FileSystemWatcher(Visual Studio Code 扩展) [英] Using FileSystemWatcher in Typescript (Visual Studio Code extension)
问题描述
我是 TypeScript 和 Visual Studio Code 的新手,想为 Visual Studio Code 开发一个插件.但是我被 FileSystemWatcher
触发的事件挂了.激活时,在我的扩展程序中,我创建了一个 FileSystemWatcher
并希望它通知我所有 TypeScript 文件的更改.这就是我迄今为止一直在做的:
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
推荐答案
On
var watcher = vscode.workspace.createFileSystemWatcher("*.ts");
请使用 "**/*.ts
而不是 "*.ts"
.
这篇关于在 Typescript 中使用 FileSystemWatcher(Visual Studio Code 扩展)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!