diff --git a/package.json b/package.json index 8fa804ee2..1368f2144 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "workspaceContains:**/compile_commands.json", "workspaceContains:**/compile_flags.txt", "workspaceContains:**/buildServer.json", + "workspaceContains:**/.bsp/*.json", "onDebugResolve:swift-lldb", "onDebugResolve:swift" ], diff --git a/src/utilities/filesystem.ts b/src/utilities/filesystem.ts index 9aeeeab7c..b5a80c335 100644 --- a/src/utilities/filesystem.ts +++ b/src/utilities/filesystem.ts @@ -48,6 +48,19 @@ export async function fileExists(...pathComponents: string[]): Promise } } +/** + * Checks if a folder exists at the supplied path. + * @param pathComponents The folder path to check for existence + * @returns Whether or not the folder exists at the path + */ +export async function folderExists(...pathComponents: string[]): Promise { + try { + return (await fs.stat(path.join(...pathComponents))).isDirectory(); + } catch (e) { + return false; + } +} + /** * Return whether a file/folder is inside a folder. * @param subpath child file/folder diff --git a/src/utilities/workspace.ts b/src/utilities/workspace.ts index 27ae76734..182dc923d 100644 --- a/src/utilities/workspace.ts +++ b/src/utilities/workspace.ts @@ -16,7 +16,7 @@ import * as path from "path"; import { basename } from "path"; import * as vscode from "vscode"; -import { globDirectory, pathExists } from "./filesystem"; +import { folderExists, globDirectory, pathExists } from "./filesystem"; import { Version } from "./version"; export async function searchForPackages( @@ -28,7 +28,7 @@ export async function searchForPackages( const folders: Array = []; async function search(folder: vscode.Uri) { - // add folder if Package.swift/compile_commands.json/compile_flags.txt/buildServer.json exists + // add folder if Package.swift/compile_commands.json/compile_flags.txt/buildServer.json/.bsp exists if (await isValidWorkspaceFolder(folder.fsPath, disableSwiftPMIntegration, swiftVersion)) { folders.push(folder); } @@ -38,8 +38,18 @@ export async function searchForPackages( } await globDirectory(folder, { onlyDirectories: true }).then(async entries => { + const skipFolders = new Set([ + ".", + ".build", + "Packages", + "out", + "bazel-out", + "bazel-bin", + ]); + for (const entry of entries) { - if (basename(entry) !== "." && basename(entry) !== "Packages") { + const base = basename(entry); + if (!skipFolders.has(base)) { await search(vscode.Uri.file(entry)); } } @@ -67,7 +77,7 @@ export async function hasBSPConfigurationFile( const bspStat = await fs.stat(bspDir).catch(() => undefined); if (bspStat && bspStat.isDirectory()) { const files = await fs.readdir(bspDir).catch(() => []); - if (files.some((f: string) => f.endsWith(".json"))) { + if (files.some(f => f.endsWith(".json"))) { return true; } } @@ -94,11 +104,11 @@ export async function isValidWorkspaceFolder( return true; } - if (await pathExists(folder, "build")) { + if (await folderExists(folder, "build")) { return true; } - if (await pathExists(folder, "out")) { + if (await folderExists(folder, "out")) { return true; }