Skip to content

Commit de1699f

Browse files
authored
(fix) don't watch node_modules when using the FallbackWatcher (#950)
FallbackWatcher used in the language server was watching files in the node_modules and .git directories, which resulted in a V8 heap out of memory and unbearable performance when using the language server standalone, without VSCode (e.g. using neovim LSP).
1 parent 0ac9826 commit de1699f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/language-server/src/lib/FallbackWatcher.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ export class FallbackWatcher {
1010
private readonly callbacks: DidChangeHandler[] = [];
1111

1212
constructor(glob: string, workspacePaths: string[]) {
13-
this.watcher = watch(workspacePaths.map((workspacePath) => join(workspacePath, glob)));
13+
const gitOrNodeModules = /\.git|node_modules/;
14+
this.watcher = watch(
15+
workspacePaths.map((workspacePath) => join(workspacePath, glob)),
16+
{
17+
ignored: (path: string) =>
18+
gitOrNodeModules.test(path) &&
19+
// Handle Sapper's alias mapping
20+
!path.includes('src/node_modules') &&
21+
!path.includes('src\\node_modules')
22+
}
23+
);
1424

1525
this.watcher
1626
.on('add', (path) => this.callback(path, FileChangeType.Created))

0 commit comments

Comments
 (0)