[bug] Don't rely on findFiles

If the user has an exclusion pattern set for `.*` or `out`, then the
`findFiles` function won't be able to find the `.fx-build-dir` or the
`tests.json` file. Instead, we can just try to read those files
directly.

Change-Id: I9d66047ba3e5f2b63db6fd0fc872cc753191fffd
Reviewed-on: https://fuchsia-review.googlesource.com/c/vscode-plugins/+/1044800
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Jacob Rutherford <jruthe@google.com>
diff --git a/src/test_controller.ts b/src/test_controller.ts
index 8031d5c..add4bbc 100644
--- a/src/test_controller.ts
+++ b/src/test_controller.ts
@@ -3,6 +3,7 @@
 // found in the LICENSE file.
 
 import * as vscode from 'vscode';
+import * as logger from './logger';
 import {
   TestController,
   TestItem,
@@ -146,23 +147,33 @@
         const bytes = await vscode.workspace.fs.readFile(uri);
         const content = new TextDecoder().decode(bytes).trim();
 
-        const pattern = new vscode.RelativePattern(workspaceFolder, `${content}/tests.json`);
+        const testsJsonFilePath = `${content}/tests.json`;
+        const pattern = new vscode.RelativePattern(workspaceFolder, testsJsonFilePath);
         const watcher = vscode.workspace.createFileSystemWatcher(pattern);
         watcher.onDidCreate(uri => scanTestsJson(uri));
         watcher.onDidChange(uri => scanTestsJson(uri));
+        const testsJsonFile = vscode.Uri.joinPath(workspaceFolder.uri, testsJsonFilePath);
         // TODO: We need to remove all the test items when this file is deleted.
-        for (const file of await vscode.workspace.findFiles(pattern)) {
-          await scanTestsJson(file);
+        try {
+          await scanTestsJson(testsJsonFile);
+        } catch (ex) {
+          // The tests.json file doesn't exist yet.
+          logger.debug(`Unable to scan tests.json: ${ex}`);
         }
       }
 
-      const pattern = new vscode.RelativePattern(workspaceFolder, '.fx-build-dir');
+      const fxBuildDirFileName = '.fx-build-dir';
+      const pattern = new vscode.RelativePattern(workspaceFolder, fxBuildDirFileName);
       const watcher = vscode.workspace.createFileSystemWatcher(pattern);
       watcher.onDidCreate(uri => scanBuildDir(uri));
       watcher.onDidChange(uri => scanBuildDir(uri));
       // TODO: We need to remove all the test items when this file is deleted.
-      for (const file of await vscode.workspace.findFiles(pattern)) {
-        await scanBuildDir(file);
+      const fxBuildDirFile = vscode.Uri.joinPath(workspaceFolder.uri, fxBuildDirFileName);
+      try {
+        await scanBuildDir(fxBuildDirFile);
+      } catch (ex) {
+        // The .fx-build-dir file doesn't exist yet.
+        logger.debug(`Unable to scan .fx-build-dir: ${ex}`);
       }
     })
   );