From 967e66c2dfbb1a4df7112bc63c4fa6e3fa7fedf4 Mon Sep 17 00:00:00 2001 From: Valentin Knabel Date: Sat, 22 Jun 2024 12:00:59 +0200 Subject: [PATCH] fix: unused global search for build binaries #44 --- src/Current.ts | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Current.ts b/src/Current.ts index 1454743..df05f4f 100644 --- a/src/Current.ts +++ b/src/Current.ts @@ -76,31 +76,25 @@ export function prodEnvironment(): Current { .get("swiftformat.onlyEnableWithConfig", false), swiftFormatPath: (document: vscode.TextDocument) => { + // Grab the project root from the local workspace + const workspace = vscode.workspace.getWorkspaceFolder(document.uri); + if (workspace == null) { + return fallbackGlobalSwiftFormatPath(); + } + // Support running from Swift PM projects - const possibleLocalPaths = glob.sync( + let possibleLocalPaths = glob.sync( "**/.build/{release,debug}/swiftformat", { maxDepth: 5 }, ); for (const path of possibleLocalPaths) { - // Grab the project root from the local workspace - const workspace = vscode.workspace.getWorkspaceFolder(document.uri); - if (workspace == null) { - continue; - } const fullPath = paths.resolve(workspace.uri.fsPath, path); if (existsSync(fullPath)) { return [absolutePath(fullPath)]; } } - if ( - vscode.workspace - .getConfiguration() - .get("swiftformat.onlyEnableOnSwiftPMProjects", false) - ) { - return null; - } - // Fall back to global defaults found in settings + return fallbackGlobalSwiftFormatPath(); }, resetSwiftFormatPath: () => @@ -120,8 +114,15 @@ export function prodEnvironment(): Current { }; } -const fallbackGlobalSwiftFormatPath = (): string[] => { - var path = vscode.workspace +const fallbackGlobalSwiftFormatPath = (): string[] | null => { + if ( + vscode.workspace + .getConfiguration() + .get("swiftformat.onlyEnableOnSwiftPMProjects", false) + ) { + return null; + } + let path = vscode.workspace .getConfiguration() .get("swiftformat.path", null);