Lsp-mode: File watches are created over-zealously

Created on 15 Mar 2019  路  6Comments  路  Source: emacs-lsp/lsp-mode

It seems that lsp-mode now creates file-watches for all the things in the projects root directory, which uses up resources and isn't always needed. For example, rls registers delete/change/create watchers explicitly only for Cargo.lock, Cargo.toml plus a deletion watcher for the target/ directory. Instead of creating only three file watches, lsp-mode decides to recursively watch files and directories from e.g. the target/ directory, which leads to errors like:

directory-files-recursively: Opening directory: No such file or directory, /somewhere/target/rls/debug/deps/rmeta31dHOO

Please correct me if I'm wrong, I haven't yet understood the file-watcher code in its entirety.

enhancement minor

Most helpful comment

@uqix the dir local solution will be per project. But you may use lsp-file-watch-ignored to skip a particular folder from being monitored.

All 6 comments

I agree that it is not the optimal solution, but at this point, this is the simplest solution having in mind that the language servers that are running in the folder are not defined and it is not trivial to deduplicate the paths. e. g. jdt-ls and boot-ls combined run watch 10+ file patterns and most of them are like **/*.java src/main/**. Also, they could unregister/register a file watch at any point. I agree that we might think for some optimizations, e. g. if the paths do not have wildcards - watch only them.

There is a similar issue for vscode:
https://github.com/Microsoft/vscode/issues/45295

directory-files-recursively: Opening directory: No such file or directory, /somewhere/target/rls/debug/deps/rmeta31dHOO

This is a bug that has to be fixed. You may ignore the target folder via lsp-file-watch-ignored for now.

I agree that creating only the required watches is a hard problem.

This is a bug that has to be fixed. You may ignore the target folder via lsp-file-watch-ignored for now.

Does that also ignore deletion events for the folder itself? Because that would be one of the three things that rls explicitly watches.

Does that also ignore deletion events for the folder itself?

The deletion events comes from the parent folder so it is fine to ignore the folder itself. I will fix the deletion event today, so you may ignore it.

I have pushed https://github.com/emacs-lsp/lsp-mode/commit/1f7e807d27e6b3e41f3a51b3d509a555d2692b34 which fixes the directory-files-recursively issue and I have documented the "Limitations" in the README page. I am not planning to address the issue related to optimizing the watches since it will become irrelevant if, for example, RLS starts to monitor **.rs files.

From README:

In case your project contains a lot of files you might want to disable file monitoring via lsp-enable-file-watchers (you may use dir-locals).

Is dir-locals for project root or any dir in the project?

@uqix the dir local solution will be per project. But you may use lsp-file-watch-ignored to skip a particular folder from being monitored.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xendk picture xendk  路  3Comments

josh-janrain picture josh-janrain  路  5Comments

rsuhada picture rsuhada  路  3Comments

raxod502 picture raxod502  路  4Comments

yyoncho picture yyoncho  路  5Comments