Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore non-swiftformat manifests #47

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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[]> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this below buildSwiftformatIfNeeded?

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