@@ -4,6 +4,7 @@ import * as vscode from "vscode";
4
4
import { SwiftFormatEditProvider } from "./SwiftFormatEditProvider" ;
5
5
import Current from "./Current" ;
6
6
import { promisify } from "util" ;
7
+ import * as fs from 'fs' ;
7
8
import * as path from "path" ;
8
9
import { exec } from "child_process" ;
9
10
@@ -34,16 +35,30 @@ export function activate(context: vscode.ExtensionContext) {
34
35
} ) ;
35
36
}
36
37
38
+ // Find Package.swift file for swiftformat
39
+ async function filterManifestsForSwiftformat ( manifests : vscode . Uri [ ] ) : Promise < vscode . Uri [ ] > {
40
+ const filteredManifests : vscode . Uri [ ] = [ ] ;
41
+ for ( const manifest of manifests ) {
42
+ const content = await fs . promises . readFile ( manifest . fsPath , 'utf8' ) ;
43
+ if ( content . includes ( 'SwiftFormat' ) ) {
44
+ filteredManifests . push ( manifest ) ;
45
+ }
46
+ }
47
+ return filteredManifests ;
48
+ }
49
+
37
50
async function buildSwiftformatIfNeeded ( ) {
38
51
const manifests = await vscode . workspace . findFiles (
39
52
"**/Package.swift" ,
40
53
"**/.build/**" ,
41
54
2 ,
42
55
) ;
43
- if ( manifests . length == 0 ) {
56
+ const filteredManifests = await filterManifestsForSwiftformat ( manifests ) ;
57
+ if ( filteredManifests . length == 0 ) {
44
58
return ;
45
59
}
46
- const buildOperations = manifests . map ( ( manifest ) => {
60
+
61
+ const buildOperations = filteredManifests . map ( ( manifest ) => {
47
62
const manifestPath = manifest . fsPath ;
48
63
const manifestDir = path . dirname ( manifestPath ) ;
49
64
return promisify ( exec ) ( "swift run -c release swiftformat --version" , {
0 commit comments