Skip to content

Commit 7597945

Browse files
Use an enum for backgroundPreparationMode in the configuration file instead of a string
1 parent 96b582c commit 7597945

File tree

5 files changed

+40
-21
lines changed

5 files changed

+40
-21
lines changed

Documentation/Configuration File.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ The structure of the file is currently not guaranteed to be stable. Options may
4747
- `defaultWorkspaceType: "buildServer"|"compilationDatabase"|"swiftPM"`: Default workspace type. Overrides workspace type selection logic.
4848
- `generatedFilesPath: string`: Directory in which generated interfaces and macro expansions should be stored.
4949
- `backgroundIndexing: boolean`: Whether background indexing is enabled.
50-
- `backgroundPreparationMode: string`: Determines how background indexing should prepare a target. Possible values are: - `build`: Build a target to prepare it. - `noLazy`: Prepare a target without generating object files but do not do lazy type checking and function body skipping. - `enabled`: Prepare a target without generating object files and the like.
50+
- `backgroundPreparationMode: "build"|"noLazy"|"enabled"`: Determines how background indexing should prepare a target.
51+
- `build`: Build a target to prepare it.
52+
- `noLazy`: Prepare a target without generating object files but do not do lazy type checking and function body skipping. This uses SwiftPM's `--experimental-prepare-for-indexing-no-lazy` flag.
53+
- `enabled`: Prepare a target without generating object files.
5154
- `cancelTextDocumentRequestsOnEditAndClose: boolean`: Whether sending a `textDocument/didChange` or `textDocument/didClose` notification for a document should cancel all pending requests for that document.
5255
- `experimentalFeatures: ("on-type-formatting")[]`: Experimental features that are enabled.
5356
- `swiftPublishDiagnosticsDebounceDuration: number`: The time that `SwiftLanguageService` should wait after an edit before starting to compute diagnostics and sending a `PublishDiagnosticsNotification`.

Sources/SKOptions/SourceKitLSPOptions.swift

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,11 @@ public struct SourceKitLSPOptions: Sendable, Codable, Equatable {
242242
}
243243
}
244244

245-
public enum BackgroundPreparationMode: String {
245+
public enum BackgroundPreparationMode: String, Sendable, Codable, Equatable {
246246
/// Build a target to prepare it.
247247
case build
248248

249-
/// Prepare a target without generating object files but do not do lazy type checking.
249+
/// Prepare a target without generating object files but do not do lazy type checking and function body skipping.
250250
///
251251
/// This uses SwiftPM's `--experimental-prepare-for-indexing-no-lazy` flag.
252252
case noLazy
@@ -315,17 +315,11 @@ public struct SourceKitLSPOptions: Sendable, Codable, Equatable {
315315
return backgroundIndexing ?? true
316316
}
317317

318-
/// Determines how background indexing should prepare a target. Possible values are:
319-
/// - `build`: Build a target to prepare it.
320-
/// - `noLazy`: Prepare a target without generating object files but do not do lazy type checking and function body skipping.
321-
/// - `enabled`: Prepare a target without generating object files and the like.
322-
public var backgroundPreparationMode: String?
318+
/// Determines how background indexing should prepare a target.
319+
public var backgroundPreparationMode: BackgroundPreparationMode?
323320

324321
public var backgroundPreparationModeOrDefault: BackgroundPreparationMode {
325-
if let backgroundPreparationMode, let parsed = BackgroundPreparationMode(rawValue: backgroundPreparationMode) {
326-
return parsed
327-
}
328-
return .enabled
322+
return backgroundPreparationMode ?? .enabled
329323
}
330324

331325
/// Whether sending a `textDocument/didChange` or `textDocument/didClose` notification for a document should cancel
@@ -389,7 +383,7 @@ public struct SourceKitLSPOptions: Sendable, Codable, Equatable {
389383
defaultWorkspaceType: WorkspaceType? = nil,
390384
generatedFilesPath: String? = nil,
391385
backgroundIndexing: Bool? = nil,
392-
backgroundPreparationMode: String? = nil,
386+
backgroundPreparationMode: BackgroundPreparationMode? = nil,
393387
cancelTextDocumentRequestsOnEditAndClose: Bool? = nil,
394388
experimentalFeatures: Set<ExperimentalFeature>? = nil,
395389
swiftPublishDiagnosticsDebounceDuration: Double? = nil,

Tests/SourceKitLSPTests/BackgroundIndexingTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ final class BackgroundIndexingTests: XCTestCase {
10741074
func testCrossModuleFunctionalityEvenIfLowLevelModuleHasErrors() async throws {
10751075
try await SkipUnless.swiftPMSupportsExperimentalPrepareForIndexing()
10761076
var options = SourceKitLSPOptions.testDefault()
1077-
options.backgroundPreparationMode = SourceKitLSPOptions.BackgroundPreparationMode.enabled.rawValue
1077+
options.backgroundPreparationMode = .enabled
10781078
let project = try await SwiftPMTestProject(
10791079
files: [
10801080
"LibA/LibA.swift": """
@@ -1121,7 +1121,7 @@ final class BackgroundIndexingTests: XCTestCase {
11211121
func testCrossModuleFunctionalityWithPreparationNoSkipping() async throws {
11221122
try await SkipUnless.swiftPMSupportsExperimentalPrepareForIndexing()
11231123
var options = SourceKitLSPOptions.testDefault()
1124-
options.backgroundPreparationMode = SourceKitLSPOptions.BackgroundPreparationMode.noLazy.rawValue
1124+
options.backgroundPreparationMode = .noLazy
11251125
let project = try await SwiftPMTestProject(
11261126
files: [
11271127
"LibA/LibA.swift": """
@@ -1406,7 +1406,7 @@ final class BackgroundIndexingTests: XCTestCase {
14061406
try SkipUnless.longTestsEnabled()
14071407

14081408
var options = SourceKitLSPOptions.testDefault()
1409-
options.backgroundPreparationMode = SourceKitLSPOptions.BackgroundPreparationMode.enabled.rawValue
1409+
options.backgroundPreparationMode = .enabled
14101410
options.indexOrDefault.updateIndexStoreTimeout = 1 /* second */
14111411

14121412
let dateStarted = Date()
@@ -1538,7 +1538,7 @@ final class BackgroundIndexingTests: XCTestCase {
15381538
)
15391539
""",
15401540
options: SourceKitLSPOptions(
1541-
backgroundPreparationMode: SourceKitLSPOptions.BackgroundPreparationMode.enabled.rawValue
1541+
backgroundPreparationMode: .enabled
15421542
),
15431543
enableBackgroundIndexing: true
15441544
)
@@ -1602,7 +1602,7 @@ final class BackgroundIndexingTests: XCTestCase {
16021602
)
16031603
""",
16041604
options: SourceKitLSPOptions(
1605-
backgroundPreparationMode: SourceKitLSPOptions.BackgroundPreparationMode.enabled.rawValue
1605+
backgroundPreparationMode: .enabled
16061606
),
16071607
enableBackgroundIndexing: true
16081608
)

Utilities/ConfigSchemaGen/Sources/ConfigSchemaGen/OptionDocument.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,22 @@ struct OptionDocumentBuilder {
4848
doc += " " + description.split(separator: "\n").joined(separator: "\n\(indent) ")
4949
}
5050
doc += "\n"
51-
if case .object(let schema) = type.kind {
51+
switch type.kind {
52+
case .object(let schema):
5253
for property in schema.properties {
5354
try appendProperty(property, indentLevel: indentLevel + 1)
5455
}
56+
case .enum(let schema):
57+
for caseInfo in schema.cases {
58+
// Add detailed description for each case if available
59+
guard let description = caseInfo.description else {
60+
continue
61+
}
62+
doc += "\(indent) - `\(caseInfo.name)`"
63+
doc += ": " + description.split(separator: "\n").joined(separator: "\n\(indent) ")
64+
doc += "\n"
65+
}
66+
default: break
5567
}
5668
}
5769
guard case .object(let schema) = schema.kind else {

config.schema.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@
88
"type" : "boolean"
99
},
1010
"backgroundPreparationMode" : {
11-
"description" : "Determines how background indexing should prepare a target. Possible values are: - `build`: Build a target to prepare it. - `noLazy`: Prepare a target without generating object files but do not do lazy type checking and function body skipping. - `enabled`: Prepare a target without generating object files and the like.",
12-
"markdownDescription" : "Determines how background indexing should prepare a target. Possible values are: - `build`: Build a target to prepare it. - `noLazy`: Prepare a target without generating object files but do not do lazy type checking and function body skipping. - `enabled`: Prepare a target without generating object files and the like.",
11+
"description" : "Determines how background indexing should prepare a target.",
12+
"enum" : [
13+
"build",
14+
"noLazy",
15+
"enabled"
16+
],
17+
"markdownDescription" : "Determines how background indexing should prepare a target.",
18+
"markdownEnumDescriptions" : {
19+
"build" : "Build a target to prepare it.",
20+
"enabled" : "Prepare a target without generating object files.",
21+
"noLazy" : "Prepare a target without generating object files but do not do lazy type checking and function body skipping. This uses SwiftPM's `--experimental-prepare-for-indexing-no-lazy` flag."
22+
},
1323
"type" : "string"
1424
},
1525
"buildSettingsTimeout" : {

0 commit comments

Comments
 (0)