Skip to content

Commit 967e66c

Browse files
committed
fix: unused global search for build binaries #44
1 parent 6d11fe2 commit 967e66c

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/Current.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,31 +76,25 @@ export function prodEnvironment(): Current {
7676
.get("swiftformat.onlyEnableWithConfig", false),
7777

7878
swiftFormatPath: (document: vscode.TextDocument) => {
79+
// Grab the project root from the local workspace
80+
const workspace = vscode.workspace.getWorkspaceFolder(document.uri);
81+
if (workspace == null) {
82+
return fallbackGlobalSwiftFormatPath();
83+
}
84+
7985
// Support running from Swift PM projects
80-
const possibleLocalPaths = glob.sync(
86+
let possibleLocalPaths = glob.sync(
8187
"**/.build/{release,debug}/swiftformat",
8288
{ maxDepth: 5 },
8389
);
8490
for (const path of possibleLocalPaths) {
85-
// Grab the project root from the local workspace
86-
const workspace = vscode.workspace.getWorkspaceFolder(document.uri);
87-
if (workspace == null) {
88-
continue;
89-
}
9091
const fullPath = paths.resolve(workspace.uri.fsPath, path);
9192

9293
if (existsSync(fullPath)) {
9394
return [absolutePath(fullPath)];
9495
}
9596
}
96-
if (
97-
vscode.workspace
98-
.getConfiguration()
99-
.get("swiftformat.onlyEnableOnSwiftPMProjects", false)
100-
) {
101-
return null;
102-
}
103-
// Fall back to global defaults found in settings
97+
10498
return fallbackGlobalSwiftFormatPath();
10599
},
106100
resetSwiftFormatPath: () =>
@@ -120,8 +114,15 @@ export function prodEnvironment(): Current {
120114
};
121115
}
122116

123-
const fallbackGlobalSwiftFormatPath = (): string[] => {
124-
var path = vscode.workspace
117+
const fallbackGlobalSwiftFormatPath = (): string[] | null => {
118+
if (
119+
vscode.workspace
120+
.getConfiguration()
121+
.get("swiftformat.onlyEnableOnSwiftPMProjects", false)
122+
) {
123+
return null;
124+
}
125+
let path = vscode.workspace
125126
.getConfiguration()
126127
.get<string[] | string | null>("swiftformat.path", null);
127128

0 commit comments

Comments
 (0)