Search code examples
visual-studio-codevscode-extensionslanguage-server-protocol

Is there a way to watch file system events inside node_modules folder for vscode-languageclient?


Inside the extensions activate(context:ExtensionContext) function, I want to add a FileSystemWatcher. While this works for e.g

const clientOptions: LanguageClientOptions = {
      documentSelector: [{scheme: 'file', language: 'plainText'}],
      synchronize: {
           fileEvents: vscode.workspace.createFileSystemWatcher('**/someFolder/*.txt')
      }
}

If I now want to watch a file inside the node_modules folder, nothing happens.. any idea?


Solution

  • There's a "files.watcherExclude" setting with the following defaults:

    "files.watcherExclude": {
        "**/.git/objects/**": true,
        "**/.git/subtree-cache/**": true,
        "**/node_modules/*/**": true,
        "**/.hg/store/**": true
    }
    

    Configure glob patterns of file paths to exclude from file watching. Patterns must match on absolute paths (i.e. prefix with ** or the full path to match properly). Changing this setting requires a restart. When you experience Code consuming lots of CPU time on startup, you can exclude large folders to reduce the initial load.

    Performance-wise it's probably not advisable to remove node_modules from here either, since it can contain a lot of files. In any case, since it's a user setting, you're not in control of this as an extension author.