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 vscode.RelativePattern and vscode.workspace.findFiles #4

Open
caponetto opened this issue Aug 30, 2021 · 5 comments
Open

Using vscode.RelativePattern and vscode.workspace.findFiles #4

caponetto opened this issue Aug 30, 2021 · 5 comments

Comments

@caponetto
Copy link

I've changed the helloworld-web-sample with this simple testing code below but it can't find files when running it with the vscode-test-web (files.length always 0). It works fine when I run it using the Run Web Extension in VS Code though (files.length > 0).

Is there a different way of using vscode.RelativePattern and vscode.workspace.findFiles for browser? Thanks!

diff --git a/helloworld-web-sample/src/web/extension.ts b/helloworld-web-sample/src/web/extension.ts
index 176a2dd..482892a 100644
--- a/helloworld-web-sample/src/web/extension.ts
+++ b/helloworld-web-sample/src/web/extension.ts
@@ -13,11 +13,13 @@ export function activate(context: vscode.ExtensionContext) {
 	// The command has been defined in the package.json file
 	// Now provide the implementation of the command with registerCommand
 	// The commandId parameter must match the command field in package.json
-	let disposable = vscode.commands.registerCommand('helloworld-web-sample.helloWorld', () => {
+	let disposable = vscode.commands.registerCommand('helloworld-web-sample.helloWorld', async () => {
 		// The code you place here will be executed every time your command is executed
 
 		// Display a message box to the user
-		vscode.window.showInformationMessage('Hello World from helloworld-web-sample in a web extension host!');
+		const relativePattern = new vscode.RelativePattern(vscode.workspace.workspaceFolders![0], "**/*");
+		const files = await vscode.workspace.findFiles(relativePattern);
+		await vscode.window.showInformationMessage(`Hello World from helloworld-web-sample in a web extension host! ${files.length}`);
 	});
 
 	context.subscriptions.push(disposable);
@aeschli
Copy link
Contributor

aeschli commented Sep 24, 2021

Now you can also specify a local folder with test data:

vscode-test-web --browserType=chromium --extensionDevelopmentPath=$extensionLocation $testDataLocation

VS Code Browser will open on a virtual workspace (vscode-test-web://mount). A file system provider will fetch the file/folder data from the local disk. Changes to the file system are kept in memory and are not written back to disk.

@aeschli aeschli closed this as completed Sep 24, 2021
@caponetto
Copy link
Author

Hi @aeschli, thanks for the tip.
However, the code I sent still doesn't seem to be working since I'm always seeing zero for files.length.
Am I missing something?

@aeschli
Copy link
Contributor

aeschli commented Sep 27, 2021

Ah, I forgot, the file system provider doesn't yet support the fileFiles API. I'm waiting for the FileSearchProvider to become final.

@aeschli aeschli reopened this Sep 27, 2021
@joelspadin
Copy link

joelspadin commented Oct 15, 2023

Is vscode.workspace.findFiles() still broken? If I try to call

const glob = await vscode.workspace.findFiles(new vscode.RelativePattern(workspace, '**/west.yml'));

it appears to neither return a value nor throw an exception.

@aeschli
Copy link
Contributor

aeschli commented Oct 16, 2023

No progress there, unfortunately...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants