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

Watching files outside of the workspace did not work at all #196466

Closed
sbatten opened this issue Oct 24, 2023 · 3 comments
Closed

Watching files outside of the workspace did not work at all #196466

sbatten opened this issue Oct 24, 2023 · 3 comments
Assignees
Labels
file-watcher File watcher info-needed Issue requires more information from poster

Comments

@sbatten
Copy link
Member

sbatten commented Oct 24, 2023

Testing #196194

export function activate(context: vscode.ExtensionContext) {

	// Use the console to output diagnostic information (console.log) and errors (console.error)
	// This line of code will only be executed once when your extension is activated
	console.log('Congratulations, your extension "filewatcher-test" is now active!');



	let folder = vscode.workspace.workspaceFolders?.[0]?.uri;
	if (!folder) {
		console.log('No workspace folder to watch... using hard coded path');
		folder = vscode.Uri.file('/home/username/Source/testing-1/')
		return;
	}

	const pattern: vscode.RelativePattern = new vscode.RelativePattern(folder, '**/*.test.ts');
	const fileWatcher = vscode.workspace.createFileSystemWatcher(pattern);

	fileWatcher.onDidChange(uri => console.log(`${uri.path} changed.`));
	fileWatcher.onDidCreate(uri => console.log(`${uri.path} created.`));
	fileWatcher.onDidDelete(uri => console.log(`${uri.path} deleted.`));

	context.subscriptions.push(fileWatcher);

}

Using this method and editing files outside of the workspace did not trigger any events but the extension was activated.

@bpasero
Copy link
Member

bpasero commented Oct 25, 2023

@sbatten you seem to be watching inside the workspace though because you create a watcher with vscode.workspace.workspaceFolders?.[0]?.uri. Did you test this in an empty window to get the vscode.Uri.file('/home/username/Source/testing-1/') fallback?

@bpasero bpasero added the info-needed Issue requires more information from poster label Oct 25, 2023
@bpasero
Copy link
Member

bpasero commented Oct 25, 2023

Oh and there is an early return statement that makes this fail. If you remove it it should work.

@bpasero
Copy link
Member

bpasero commented Oct 25, 2023

@bhavyaus can you also your sample code?

@bpasero bpasero closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
file-watcher File watcher info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

2 participants