Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: file watching doesn't report file deletions caused by directory deletion #109754

Closed
stamblerre opened this issue Oct 30, 2020 · 3 comments
Closed
Assignees
Labels
*as-designed Described behavior is as designed file-watcher File watcher

Comments

@stamblerre
Copy link

In the Go language server, we register a file watcher with a GlobPattern of "**/*.{go,mod,sum}". I would expect that this file watcher would report deletions of files caused by the deletion of a directory, but this doesn't seem to be the case.

For example, if the workspace contains a directory foo with the file foo.go, deleting foo either in the terminal (rm -rf foo) or in the VS Code UI does not result in any change notifications for foo/foo.go. The only way I was able to get notifications was when I registered a watcher with the GlobPattern of "**", but we'd prefer to avoid registering for notifications for all files in the workspace.

Is this expected behavior or have we made some mistake here?

VSCode Version:

1.51.0-insider
2ee8b8c
x64

OS Version: Mac OS Catalina 10.15.7

@bpasero
Copy link
Member

bpasero commented Oct 31, 2020

Is this expected behavior or have we made some mistake here?

Expected. On some platforms or for performance reasons we may decide to fold the delete event into a single one for the folder. Since you can subscribe to a pattern that includes folders as well, the workaround is to register for the folder and then check if the events match your files as children.

@bpasero bpasero added the *as-designed Described behavior is as designed label Oct 31, 2020
@stamblerre
Copy link
Author

Expected. On some platforms or for performance reasons we may decide to fold the delete event into a single one for the folder. Since you can subscribe to a pattern that includes folders as well, the workaround is to register for the folder and then check if the events match your files as children.

I still find this a bit surprising. Doesn't that mean that the only valid GlobPattern is ** (since directories can have any name or extension)?

I might expect the file watcher to report directory deletions instead of per-file deletions when a directory was deleted, but I saw no notifications at all with a GlobPattern of "**/*.{go,mod,sum}", even though matching files were deleted when the directory was deleted.

gopherbot pushed a commit to golang/tools that referenced this issue Nov 17, 2020
VS Code's file watching API doesn't send notifications about directory
deletions unless you register for them explicitly (see
microsoft/vscode#109754). Rather than watch
every file in the workspace, keep track of every relevant directory and
register file watchers for it.

This CL moves the snapshot's WorkspaceDirectories function to the
session and changes it to a KnownDirectories function. It returns all of
the directories and subdirectories known the session at a given moment.
Top-level directories are marked as such so that their *.{go,mod,sum}
contents can be watched, while subdirectories are just watched by path
so we can be notified of deletions.

Fixes golang/go#42348

Change-Id: If80a26cf6af5a2c2f7d87bb57b9ef5cb3dcf04ac
Reviewed-on: https://go-review.googlesource.com/c/tools/+/267120
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
gopherbot pushed a commit to golang/tools that referenced this issue Nov 25, 2020
VS Code's file watching API doesn't send notifications about directory
deletions unless you register for them explicitly (see
microsoft/vscode#109754). Rather than watch
every file in the workspace, keep track of every relevant directory and
register file watchers for it.

This CL moves the snapshot's WorkspaceDirectories function to the
session and changes it to a KnownDirectories function. It returns all of
the directories and subdirectories known the session at a given moment.
Top-level directories are marked as such so that their *.{go,mod,sum}
contents can be watched, while subdirectories are just watched by path
so we can be notified of deletions.

Fixes golang/go#42348

Change-Id: Ic6d02dba55b5de89370522ea5d3cf1d198927997
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271438
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
@github-actions github-actions bot locked and limited conversation to collaborators Dec 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*as-designed Described behavior is as designed file-watcher File watcher
Projects
None yet
Development

No branches or pull requests

3 participants
@bpasero @stamblerre and others