Skip to content

Commit 6d8aa91

Browse files
committed
Ensure the extension activates with a .bsp folder
A .bsp folder was considered a valid workspace folder, but the extension acitvation events in the package.json were not configured to search for it, meaning another valid file/folder for activation had to be present. If that was the case, then the .bsp folder would be discovered correctly, but not if it was the only file/folder in the folder that would activate the extension. Add it to the list of valid activation file types. Also clean up this code path a bit, ignoring common folders we shouldn't search for projects.
1 parent 30d0581 commit 6d8aa91

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"workspaceContains:**/compile_commands.json",
3030
"workspaceContains:**/compile_flags.txt",
3131
"workspaceContains:**/buildServer.json",
32+
"workspaceContains:**/.bsp/*.json",
3233
"onDebugResolve:swift-lldb",
3334
"onDebugResolve:swift"
3435
],

src/utilities/filesystem.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ export async function fileExists(...pathComponents: string[]): Promise<boolean>
4848
}
4949
}
5050

51+
/**
52+
* Checks if a folder exists at the supplied path.
53+
* @param pathComponents The folder path to check for existence
54+
* @returns Whether or not the folder exists at the path
55+
*/
56+
export async function folderExists(...pathComponents: string[]): Promise<boolean> {
57+
try {
58+
return (await fs.stat(path.join(...pathComponents))).isDirectory();
59+
} catch (e) {
60+
return false;
61+
}
62+
}
63+
5164
/**
5265
* Return whether a file/folder is inside a folder.
5366
* @param subpath child file/folder

src/utilities/workspace.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import * as path from "path";
1616
import { basename } from "path";
1717
import * as vscode from "vscode";
1818

19-
import { globDirectory, pathExists } from "./filesystem";
19+
import { folderExists, globDirectory, pathExists } from "./filesystem";
2020
import { Version } from "./version";
2121

2222
export async function searchForPackages(
@@ -28,7 +28,7 @@ export async function searchForPackages(
2828
const folders: Array<vscode.Uri> = [];
2929

3030
async function search(folder: vscode.Uri) {
31-
// add folder if Package.swift/compile_commands.json/compile_flags.txt/buildServer.json exists
31+
// add folder if Package.swift/compile_commands.json/compile_flags.txt/buildServer.json/.bsp exists
3232
if (await isValidWorkspaceFolder(folder.fsPath, disableSwiftPMIntegration, swiftVersion)) {
3333
folders.push(folder);
3434
}
@@ -38,8 +38,18 @@ export async function searchForPackages(
3838
}
3939

4040
await globDirectory(folder, { onlyDirectories: true }).then(async entries => {
41+
const skipFolders = new Set<string>([
42+
".",
43+
".build",
44+
"Packages",
45+
"out",
46+
"bazel-out",
47+
"bazel-bin",
48+
]);
49+
4150
for (const entry of entries) {
42-
if (basename(entry) !== "." && basename(entry) !== "Packages") {
51+
const base = basename(entry);
52+
if (!skipFolders.has(base)) {
4353
await search(vscode.Uri.file(entry));
4454
}
4555
}
@@ -67,7 +77,7 @@ export async function hasBSPConfigurationFile(
6777
const bspStat = await fs.stat(bspDir).catch(() => undefined);
6878
if (bspStat && bspStat.isDirectory()) {
6979
const files = await fs.readdir(bspDir).catch(() => []);
70-
if (files.some((f: string) => f.endsWith(".json"))) {
80+
if (files.some(f => f.endsWith(".json"))) {
7181
return true;
7282
}
7383
}
@@ -94,11 +104,11 @@ export async function isValidWorkspaceFolder(
94104
return true;
95105
}
96106

97-
if (await pathExists(folder, "build")) {
107+
if (await folderExists(folder, "build")) {
98108
return true;
99109
}
100110

101-
if (await pathExists(folder, "out")) {
111+
if (await folderExists(folder, "out")) {
102112
return true;
103113
}
104114

0 commit comments

Comments
 (0)