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

Using '**' in a GlobPattern does not match any number of path segments in Windows #65240

Closed
allileong opened this issue Dec 18, 2018 · 6 comments
Assignees
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)

Comments

@allileong
Copy link

  • VSCode Version: 1.30.0 and also 1.31.0-insiders
  • OS Version: 17763.107

I have tested this issue on both Mac and Windows and have only seen the unexpected behavior in Windows.

I would like to create a FileSystemWatcher to watch all file changes that are a variable number of levels deep inside of a specified directory. To create the globPattern passed to the vscode.workspace.createFileSystemWatcher() method I followed this documentation: https://code.visualstudio.com/docs/extensionAPI/vscode-api#GlobPattern.

On Mac, the globString looks like:
/Users/example.user/Documents/projects/my-vscode-project/{force-app,another-app}/**

On Windows, the globString looks like:
c:\Users\exampleuser\Desktop\my-vscode-project\{force-app,another-app}\**

My example project has a structure like so:

my-vscode-project
|-- force-app
.........|-- example-file-one-level-deep.js
.........|-- main
.................|-- default
.........................|-- example-file-three-levels-deep.js
|-- another-app
........|-- another-example-file-one-level-deep.js

On Mac, changes made to example-file-one-level-deep.js, example-file-three-levels-deep.js, and another-example-file-one-level-deep.js all trigger the fileWatcher.onDidChange() listener, and this is the behavior that I would expect.

On Windows, only changes made to files directly inside of force-app and another-app trigger the fileWatcher.onDidChange() listener. Files nested more than one level deep will not trigger the change listener. In other words, changing example-file-one-level-deep.js and another-example-file-one-level-deep.js will trigger the change listener, but changing example-file-three-levels-deep.js will not.

I am creating the globString and FileSystemWatcher like so:

const packageDirectoryPaths = ['force-app', 'another-app'];
const globString = path.join(
    vscode.workspace!.workspaceFolders![0].uri.fsPath;,
    `{${packageDirectoryPaths.join(',')}}`,
    '**'
);
vscode.workspace.createFileSystemWatcher(globString);

Please let me know if I have misunderstood how to create the correct globString. This behavior is unfortunately blocking forcedotcom/salesforcedx-vscode#822 from moving forward.

Thanks!

@bpasero
Copy link
Member

bpasero commented Dec 18, 2018

@allileong let me guess, you are not getting an event for your file when a delete happens in a parent folder?

@bpasero bpasero added the info-needed Issue requires more information from poster label Dec 18, 2018
@allileong
Copy link
Author

@bpasero, what do you mean by 'parent folder'? In the above example, if I delete example-file-one-level-deep.js whose parent folder is force-app, then I am getting an event for the deletion.

@bpasero
Copy link
Member

bpasero commented Dec 18, 2018

@allileong trying to find out if this is a duplicate of #60813 or #65077. We have an optimization in place that will report a delete or rename of a folder as a single event on that folder and not for each file that is below that folder.

@allileong
Copy link
Author

@bpasero, this issue seems to be similar in that '**' is not successfully matching on parent directories, but it doesn't seem to be a direct duplicate of those issues since this issue is affecting the file create, change, and delete events alike rather than just delete events.

@bpasero
Copy link
Member

bpasero commented Dec 19, 2018

@allileong you cannot use \ in glob patterns, it has to be / for a valid glob pattern. For your case it is easier to use our RelativePattern support:

const watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(vscode.workspace!.workspaceFolders![0], `{${packageDirectoryPaths.join(',')}}/**`));

@bpasero bpasero closed this as completed Dec 19, 2018
@bpasero bpasero added *question Issue represents a question, should be posted to StackOverflow (VS Code) and removed file-watcher File watcher info-needed Issue requires more information from poster labels Dec 19, 2018
@allileong
Copy link
Author

@bpasero Thank you for the info. RelativePattern with / works for me. I had made incorrect the assumption that I needed to use the backslash for Windows.

@vscodebot vscodebot bot locked and limited conversation to collaborators Feb 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)
Projects
None yet
Development

No branches or pull requests

2 participants