emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.75k stars 873 forks source link

file-notify-add-watch watch a directory doesn't work when backup file disabled or edit file in vscode? #3296

Open jadestrong opened 2 years ago

jadestrong commented 2 years ago

Thank you for the bug report

Bug description

I use doom-emacs and rust-analyzer, when edit the Cargo.toml file in doom-emacs or vscode it will not trigger the workspace/didChangeWatchedFiles event.

lsp-mode use file-notify-add-watch to watch a directory change to trigger workspace/didChangeWatchedFiles. image

It works in vanilla Emacs because it enabled backup file feature, when edit and save a file will trigger a create or rename or delete event . When disable this feature such as doom-emacs or edit the file in vscode, it only change the file content, only trigger a file change event, so directory change event will not work as expect.

Steps to reproduce

hlissner/doom-emacs#5630 brotzeit/rustic#322 image When edit and save Cargo.toml file in doom-emacs and vscode, only file change event: image When edit in vanilla Emacs: image

Expected behavior

When edit Cargo.toml in vscode or emacs without backup file, can also reload rust-analyzer

Which Language Server did you use?

rust-analyzer

OS

MacOS

Error callstack

No response

Anything else?

No response

laampui commented 2 years ago

Screenshot_2022-01-25_20-20-07

similar issue: #https://github.com/facebook/create-react-app/issues/9056

same here...

danp commented 5 months ago

Running into this myself, on macOS. Maybe related to me using backup-by-copying t that I learned from #3516 / #4112? Not sure.

It does seem less than ideal that file-notify-add-watch can't detect changes to existing files, at least the way it's ending up working on macOS. There was some talk about improving in this bug but it was closed.

Is there something else lsp-mode could do? Would having (optional) support for using an external process for watching directories/files for changes help at all? At least then there would be a way to plug something in that can detect all creates/changes/deletes, I think.