Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"workspaceContains:**/compile_commands.json",
"workspaceContains:**/compile_flags.txt",
"workspaceContains:**/buildServer.json",
"workspaceContains:**/.bsp/*.json",
"onDebugResolve:swift-lldb",
"onDebugResolve:swift"
],
Expand Down
13 changes: 13 additions & 0 deletions src/utilities/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ export async function fileExists(...pathComponents: string[]): Promise<boolean>
}
}

/**
* 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<boolean> {
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
Expand Down
22 changes: 16 additions & 6 deletions src/utilities/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -28,7 +28,7 @@ export async function searchForPackages(
const folders: Array<vscode.Uri> = [];

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);
}
Expand All @@ -38,8 +38,18 @@ export async function searchForPackages(
}

await globDirectory(folder, { onlyDirectories: true }).then(async entries => {
const skipFolders = new Set<string>([
".",
".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));
}
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}

Expand Down