@@ -76,31 +76,25 @@ export function prodEnvironment(): Current {
76
76
. get ( "swiftformat.onlyEnableWithConfig" , false ) ,
77
77
78
78
swiftFormatPath : ( document : vscode . TextDocument ) => {
79
+ // Grab the project root from the local workspace
80
+ const workspace = vscode . workspace . getWorkspaceFolder ( document . uri ) ;
81
+ if ( workspace == null ) {
82
+ return fallbackGlobalSwiftFormatPath ( ) ;
83
+ }
84
+
79
85
// Support running from Swift PM projects
80
- const possibleLocalPaths = glob . sync (
86
+ let possibleLocalPaths = glob . sync (
81
87
"**/.build/{release,debug}/swiftformat" ,
82
88
{ maxDepth : 5 } ,
83
89
) ;
84
90
for ( const path of possibleLocalPaths ) {
85
- // Grab the project root from the local workspace
86
- const workspace = vscode . workspace . getWorkspaceFolder ( document . uri ) ;
87
- if ( workspace == null ) {
88
- continue ;
89
- }
90
91
const fullPath = paths . resolve ( workspace . uri . fsPath , path ) ;
91
92
92
93
if ( existsSync ( fullPath ) ) {
93
94
return [ absolutePath ( fullPath ) ] ;
94
95
}
95
96
}
96
- if (
97
- vscode . workspace
98
- . getConfiguration ( )
99
- . get ( "swiftformat.onlyEnableOnSwiftPMProjects" , false )
100
- ) {
101
- return null ;
102
- }
103
- // Fall back to global defaults found in settings
97
+
104
98
return fallbackGlobalSwiftFormatPath ( ) ;
105
99
} ,
106
100
resetSwiftFormatPath : ( ) =>
@@ -120,8 +114,15 @@ export function prodEnvironment(): Current {
120
114
} ;
121
115
}
122
116
123
- const fallbackGlobalSwiftFormatPath = ( ) : string [ ] => {
124
- var path = vscode . workspace
117
+ const fallbackGlobalSwiftFormatPath = ( ) : string [ ] | null => {
118
+ if (
119
+ vscode . workspace
120
+ . getConfiguration ( )
121
+ . get ( "swiftformat.onlyEnableOnSwiftPMProjects" , false )
122
+ ) {
123
+ return null ;
124
+ }
125
+ let path = vscode . workspace
125
126
. getConfiguration ( )
126
127
. get < string [ ] | string | null > ( "swiftformat.path" , null ) ;
127
128
0 commit comments