From b7971b84b0dcb17e50f468bae2624902887e3857 Mon Sep 17 00:00:00 2001 From: vinocher-bc Date: Tue, 25 Jun 2024 10:37:34 -0700 Subject: [PATCH 1/2] Ignore non-swiftformat manifests --- src/extension.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index e279d04..cafb1d9 100755 --- a/src/extension.ts +++ b/src/extension.ts @@ -4,6 +4,7 @@ import * as vscode from "vscode"; import { SwiftFormatEditProvider } from "./SwiftFormatEditProvider"; import Current from "./Current"; import { promisify } from "util"; +import * as fs from 'fs'; import * as path from "path"; import { exec } from "child_process"; @@ -34,16 +35,30 @@ export function activate(context: vscode.ExtensionContext) { }); } +// Find Package.swift file for swiftformat +async function filterManifestsForSwiftformat(manifests: vscode.Uri[]): Promise { + const filteredManifests: vscode.Uri[] = []; + for (const manifest of manifests) { + const content = await fs.promises.readFile(manifest.fsPath, 'utf8'); + if (content.includes('name: "swiftformat"')) { + filteredManifests.push(manifest); + } + } + return filteredManifests; +} + async function buildSwiftformatIfNeeded() { const manifests = await vscode.workspace.findFiles( "**/Package.swift", "**/.build/**", 2, ); - if (manifests.length == 0) { + const filteredManifests = await filterManifestsForSwiftformat(manifests); + if (filteredManifests.length == 0) { return; } - const buildOperations = manifests.map((manifest) => { + + const buildOperations = filteredManifests.map((manifest) => { const manifestPath = manifest.fsPath; const manifestDir = path.dirname(manifestPath); return promisify(exec)("swift run -c release swiftformat --version", { From edb383706b3c6b3de72a3e4c7de39c3f0b34062a Mon Sep 17 00:00:00 2001 From: vinocher-bc Date: Tue, 25 Jun 2024 10:54:30 -0700 Subject: [PATCH 2/2] Change search string --- src/extension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index cafb1d9..830372f 100755 --- a/src/extension.ts +++ b/src/extension.ts @@ -40,7 +40,7 @@ async function filterManifestsForSwiftformat(manifests: vscode.Uri[]): Promise