This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Handle workspace/didChangeWatchedFiles
ClosedPublic

Authored by malaperle on Sep 29 2017, 12:53 PM.

Details

Summary

The client can send notifications when it detects watched files have
changed. This patch adds the protocol handling for this type of notification.
For now, the notification will be passed down to the ClangdServer, but it will
not be acted upon. However, this will become useful for the indexer to react
to file changes.
The events could also potentially be used to invalidate other caches
(compilation database, etc).

This change also updates the VSCode extension so that it sends the events.

Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>

Event Timeline

malaperle created this revision.Sep 29 2017, 12:53 PM
malaperle set the repository for this revision to rL LLVM.
malaperle added a project: Restricted Project.
ilya-biryukov added inline comments.Sep 29 2017, 3:03 PM
clangd/ClangdServer.cpp
429

Code style: use FIXME instead of TODO.

clangd/clients/clangd-vscode/src/extension.ts
37

Won't this option make VSCode slow for very large or network-mounted projects?

I'm asking because we may want to have an option to disable it in that case.

38

Maybe extract a helper variable with array of supported extensions and use it both here and in documentSelector?

So that we always keep those lists in sync.

malaperle updated this revision to Diff 117298.Oct 1 2017, 9:45 PM
malaperle marked 3 inline comments as done.

Add VSCode config, address comments.

malaperle added inline comments.Oct 1 2017, 9:45 PM
clangd/clients/clangd-vscode/src/extension.ts
37

I haven't noticed any slowdowns in large projects (LLVM) but I haven't tested network-mounted. In fact, it seems VSCode stops sending the events when your workspace gets to a certain size, possibly when it reaches the limit of watched files (fs.inotify.max_user_watches on Linux). In any case, I added a config for disabling the file events.

ilya-biryukov added inline comments.Oct 2 2017, 3:11 AM
clangd/clients/clangd-vscode/src/extension.ts
37

Thanks.

I wonder if all LSP clients support watching for changes and whether it makes sense for clangd to implement file watching internally at some point.

ilya-biryukov accepted this revision.Oct 2 2017, 3:11 AM
This revision is now accepted and ready to land.Oct 2 2017, 3:11 AM
malaperle added inline comments.Oct 2 2017, 8:26 AM
clangd/clients/clangd-vscode/src/extension.ts
37

I was thinking that we could eventually add an option (InitializeParams?) to tell Clangd to watch the files instead of the client. However, I think a lot of clients have to watch the files anyway so it makes sense to reuse that if it's available. I don't think it would be good for both to be watching files as it can consumes a lot of system resources.
You can find some interesting discussions about this subject here:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=516216
https://github.com/Microsoft/language-server-protocol/issues/237

I think adding event-based file watching is going to be a non-trivial as this is done differently on Linux, Windows and Mac. I think it would make sense to add that to llvm::sys ideally.

This revision was automatically updated to reflect the committed changes.
ilya-biryukov added inline comments.Oct 4 2017, 1:29 AM
clangd/clients/clangd-vscode/src/extension.ts
37

Sure, if clients have it, we should definitely reuse it.

I don't think current protocol methods cover clangd's needs, though.
One important thing missing feature is watching changes outside workspace root (#include may easily point to any file on the filesystem).