@@ -211,19 +211,22 @@ export class SwiftPackage {
211211 /**
212212 * Create a SwiftPackage from a folder
213213 * @param folder folder package is in
214+ * @param toolchain Swift toolchain to use
215+ * @param disableSwiftPMIntegration Whether to disable SwiftPM integration
214216 * @returns new SwiftPackage
215217 */
216218 public static async create (
217219 folder : vscode . Uri ,
218- toolchain : SwiftToolchain
220+ toolchain : SwiftToolchain ,
221+ disableSwiftPMIntegration : boolean = false
219222 ) : Promise < SwiftPackage > {
220223 const [ resolved , workspaceState ] = await Promise . all ( [
221224 SwiftPackage . loadPackageResolved ( folder ) ,
222225 SwiftPackage . loadWorkspaceState ( folder ) ,
223226 ] ) ;
224227 return new SwiftPackage (
225228 folder ,
226- SwiftPackage . loadPackage ( folder , toolchain ) ,
229+ SwiftPackage . loadPackage ( folder , toolchain , disableSwiftPMIntegration ) ,
227230 resolved ,
228231 workspaceState
229232 ) ;
@@ -250,12 +253,25 @@ export class SwiftPackage {
250253 /**
251254 * Run `swift package describe` and return results
252255 * @param folder folder package is in
256+ * @param toolchain Swift toolchain to use
257+ * @param disableSwiftPMIntegration Whether to disable SwiftPM integration
253258 * @returns results of `swift package describe`
254259 */
255260 static async loadPackage (
256261 folder : vscode . Uri ,
257- toolchain : SwiftToolchain
262+ toolchain : SwiftToolchain ,
263+ disableSwiftPMIntegration : boolean = false
258264 ) : Promise < SwiftPackageState > {
265+ // When SwiftPM integration is disabled, return empty package structure
266+ if ( disableSwiftPMIntegration ) {
267+ return {
268+ name : path . basename ( folder . fsPath ) ,
269+ products : [ ] ,
270+ dependencies : [ ] ,
271+ targets : [ ] ,
272+ } ;
273+ }
274+
259275 try {
260276 // Use swift package describe to describe the package targets, products, and platforms
261277 // Use swift package show-dependencies to get the dependencies in a tree format
@@ -307,8 +323,14 @@ export class SwiftPackage {
307323 private static async loadPlugins (
308324 folder : vscode . Uri ,
309325 toolchain : SwiftToolchain ,
310- logger : SwiftLogger
326+ logger : SwiftLogger ,
327+ disableSwiftPMIntegration : boolean = false
311328 ) : Promise < PackagePlugin [ ] > {
329+ // When SwiftPM integration is disabled, return empty plugin list
330+ if ( disableSwiftPMIntegration ) {
331+ return [ ] ;
332+ }
333+
312334 try {
313335 const { stdout } = await execSwift ( [ "package" , "plugin" , "--list" ] , toolchain , {
314336 cwd : folder . fsPath ,
@@ -355,8 +377,12 @@ export class SwiftPackage {
355377 }
356378
357379 /** Reload swift package */
358- public async reload ( toolchain : SwiftToolchain ) {
359- const loadedContents = await SwiftPackage . loadPackage ( this . folder , toolchain ) ;
380+ public async reload ( toolchain : SwiftToolchain , disableSwiftPMIntegration : boolean = false ) {
381+ const loadedContents = await SwiftPackage . loadPackage (
382+ this . folder ,
383+ toolchain ,
384+ disableSwiftPMIntegration
385+ ) ;
360386 this . _contents = loadedContents ;
361387 this . contentsPromise = Promise . resolve ( loadedContents ) ;
362388 }
@@ -370,8 +396,17 @@ export class SwiftPackage {
370396 this . workspaceState = await SwiftPackage . loadWorkspaceState ( this . folder ) ;
371397 }
372398
373- public async loadSwiftPlugins ( toolchain : SwiftToolchain , logger : SwiftLogger ) {
374- this . plugins = await SwiftPackage . loadPlugins ( this . folder , toolchain , logger ) ;
399+ public async loadSwiftPlugins (
400+ toolchain : SwiftToolchain ,
401+ logger : SwiftLogger ,
402+ disableSwiftPMIntegration : boolean = false
403+ ) {
404+ this . plugins = await SwiftPackage . loadPlugins (
405+ this . folder ,
406+ toolchain ,
407+ logger ,
408+ disableSwiftPMIntegration
409+ ) ;
375410 }
376411
377412 /** Return if has valid contents */
0 commit comments