Skip to content

Commit 5f25d6a

Browse files
committed
Add option to skip building and running plugins
This *shouldn't* be needed, but allows running plugins to be skipped if there's any unexpected interactions with background indexing.
1 parent 751eb61 commit 5f25d6a

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

Documentation/Configuration File.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The structure of the file is currently not guaranteed to be stable. Options may
2727
- `linkerFlags: string[]`: Extra arguments passed to the linker. Equivalent to SwiftPM's `-Xlinker` option.
2828
- `buildToolsSwiftCompilerFlags: string[]`: Extra arguments passed to the compiler for Swift files or plugins. Equivalent to SwiftPM's `-Xbuild-tools-swiftc` option.
2929
- `disableSandbox: boolean`: Disables running subprocesses from SwiftPM in a sandbox. Equivalent to SwiftPM's `--disable-sandbox` option. Useful when running `sourcekit-lsp` in a sandbox because nested sandboxes are not supported.
30+
- `skipPlugins: boolean`: Whether to skip building and running plugins when creating the in-memory build graph. Note: this should generally not be enabled as it will cause generated files not to be found in semantic functionality. It exists only as an escape hatch if doing so causes any unintentional interactions with background indexing.
3031
- `compilationDatabase`: Dictionary with the following keys, defining options for workspaces with a compilation database.
3132
- `searchPaths: string[]`: Additional paths to search for a compilation database, relative to a workspace root.
3233
- `fallbackBuildSystem`: Dictionary with the following keys, defining options for files that aren't managed by any build system.

Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem {
355355
// We have a whole separate arena if we're performing background indexing. This allows us to also build and run
356356
// plugins, without having to worry about messing up any regular build state.
357357
let buildDescription: SourceKitLSPAPI.BuildDescription
358-
if isForIndexBuild {
358+
if isForIndexBuild && !(options.swiftPMOrDefault.skipPlugins ?? false) {
359359
let loaded = try await BuildDescription.load(
360360
destinationBuildParameters: destinationBuildParameters,
361361
toolsBuildParameters: toolsBuildParameters,

Sources/SKOptions/SourceKitLSPOptions.swift

+9-2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public struct SourceKitLSPOptions: Sendable, Codable, Equatable {
7676
/// Useful when running `sourcekit-lsp` in a sandbox because nested sandboxes are not supported.
7777
public var disableSandbox: Bool?
7878

79+
/// Whether to skip building and running plugins when creating the in-memory build graph. Note: this should
80+
/// generally not be enabled as it will cause generated files not to be found in semantic functionality. It exists
81+
/// only as an escape hatch if doing so causes any unintentional interactions with background indexing.
82+
public var skipPlugins: Bool?
83+
7984
public init(
8085
configuration: BuildConfiguration? = nil,
8186
scratchPath: String? = nil,
@@ -88,7 +93,8 @@ public struct SourceKitLSPOptions: Sendable, Codable, Equatable {
8893
swiftCompilerFlags: [String]? = nil,
8994
linkerFlags: [String]? = nil,
9095
buildToolsSwiftCompilerFlags: [String]? = nil,
91-
disableSandbox: Bool? = nil
96+
disableSandbox: Bool? = nil,
97+
skipPlugins: Bool? = nil
9298
) {
9399
self.configuration = configuration
94100
self.scratchPath = scratchPath
@@ -117,7 +123,8 @@ public struct SourceKitLSPOptions: Sendable, Codable, Equatable {
117123
swiftCompilerFlags: override?.swiftCompilerFlags ?? base.swiftCompilerFlags,
118124
linkerFlags: override?.linkerFlags ?? base.linkerFlags,
119125
buildToolsSwiftCompilerFlags: override?.buildToolsSwiftCompilerFlags ?? base.buildToolsSwiftCompilerFlags,
120-
disableSandbox: override?.disableSandbox ?? base.disableSandbox
126+
disableSandbox: override?.disableSandbox ?? base.disableSandbox,
127+
skipPlugins: override?.skipPlugins ?? base.skipPlugins
121128
)
122129
}
123130
}

config.schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@
268268
"markdownDescription" : "Build artifacts directory path. If nil, the build system may choose a default value. This path can be specified as a relative path, which will be interpreted relative to the project root. Equivalent to SwiftPM's `--scratch-path` option.",
269269
"type" : "string"
270270
},
271+
"skipPlugins" : {
272+
"description" : "Whether to skip building and running plugins when creating the in-memory build graph. Note: this should generally not be enabled as it will cause generated files not to be found in semantic functionality. It exists only as an escape hatch if doing so causes any unintentional interactions with background indexing.",
273+
"markdownDescription" : "Whether to skip building and running plugins when creating the in-memory build graph. Note: this should generally not be enabled as it will cause generated files not to be found in semantic functionality. It exists only as an escape hatch if doing so causes any unintentional interactions with background indexing.",
274+
"type" : "boolean"
275+
},
271276
"swiftCompilerFlags" : {
272277
"description" : "Extra arguments passed to the compiler for Swift files. Equivalent to SwiftPM's `-Xswiftc` option.",
273278
"items" : {

0 commit comments

Comments
 (0)