Skip to content

Commit

Permalink
Ignore non-swiftformat manifests (#47)
Browse files Browse the repository at this point in the history
* Ignore non-swiftformat manifests

* Change search string
  • Loading branch information
vinocher-bc authored Nov 21, 2024
1 parent 967e66c commit fc66f22
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -34,16 +35,30 @@ export function activate(context: vscode.ExtensionContext) {
});
}

// Find Package.swift file for swiftformat
async function filterManifestsForSwiftformat(manifests: vscode.Uri[]): Promise<vscode.Uri[]> {
const filteredManifests: vscode.Uri[] = [];
for (const manifest of manifests) {
const content = await fs.promises.readFile(manifest.fsPath, 'utf8');
if (content.includes('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", {
Expand Down

0 comments on commit fc66f22

Please sign in to comment.