@@ -140,6 +140,18 @@ public struct SourceKitLSPOptions: Sendable, Codable {
140
140
public var maxCoresPercentageToUseForBackgroundIndexing : Double ?
141
141
public var updateIndexStoreTimeout : Int ?
142
142
143
+ public var maxCoresPercentageToUseForBackgroundIndexingOrDefault : Double {
144
+ return maxCoresPercentageToUseForBackgroundIndexing ?? 1
145
+ }
146
+
147
+ public var updateIndexStoreTimeoutOrDefault : Duration {
148
+ if let updateIndexStoreTimeout {
149
+ . seconds( updateIndexStoreTimeout)
150
+ } else {
151
+ . seconds( 120 )
152
+ }
153
+ }
154
+
143
155
public init (
144
156
indexStorePath: String ? = nil ,
145
157
indexDatabasePath: String ? = nil ,
@@ -166,16 +178,19 @@ public struct SourceKitLSPOptions: Sendable, Codable {
166
178
}
167
179
}
168
180
169
- public var swiftPM : SwiftPMOptions ?
170
- public var compilationDatabase : CompilationDatabaseOptions ?
171
- public var fallbackBuildSystem : FallbackBuildSystemOptions ?
181
+ public var swiftPM : SwiftPMOptions
182
+ public var compilationDatabase : CompilationDatabaseOptions
183
+ public var fallbackBuildSystem : FallbackBuildSystemOptions
172
184
public var clangdOptions : [ String ] ?
173
- public var index : IndexOptions ?
185
+ public var index : IndexOptions
174
186
175
187
/// Default workspace type (buildserver|compdb|swiftpm). Overrides workspace type selection logic.
176
188
public var defaultWorkspaceType : WorkspaceType ?
177
189
public var generatedFilesPath : String ?
178
190
191
+ /// Whether background indexing is enabled.
192
+ public var backgroundIndexing : Bool ?
193
+
179
194
/// Experimental features that are enabled.
180
195
public var experimentalFeatures : Set < ExperimentalFeature > ? = nil
181
196
@@ -184,25 +199,29 @@ public struct SourceKitLSPOptions: Sendable, Codable {
184
199
///
185
200
/// This is mostly intended for testing purposes so we don't need to wait the debouncing time to get a diagnostics
186
201
/// notification when running unit tests.
187
- public var swiftPublishDiagnosticsDebounce : Double ? = nil
202
+ public var swiftPublishDiagnosticsDebounceDuration : Double ? = nil
188
203
189
- public var swiftPublishDiagnosticsDebounceDuration : TimeInterval {
190
- if let workDoneProgressDebounce {
191
- return workDoneProgressDebounce
204
+ public var swiftPublishDiagnosticsDebounceDurationOrDefault : Duration {
205
+ if let swiftPublishDiagnosticsDebounceDuration {
206
+ return . seconds ( swiftPublishDiagnosticsDebounceDuration )
192
207
}
193
- return 2 /* seconds */
208
+ return . seconds( 2 )
194
209
}
195
210
196
211
/// When a task is started that should be displayed to the client as a work done progress, how many milliseconds to
197
212
/// wait before actually starting the work done progress. This prevents flickering of the work done progress in the
198
213
/// client for short-lived index tasks which end within this duration.
199
- public var workDoneProgressDebounce : Double ? = nil
214
+ public var workDoneProgressDebounceDuration : Double ? = nil
200
215
201
- public var workDoneProgressDebounceDuration : Duration {
202
- if let workDoneProgressDebounce {
203
- return . seconds( workDoneProgressDebounce )
216
+ public var workDoneProgressDebounceDurationOrDefault : Duration {
217
+ if let workDoneProgressDebounceDuration {
218
+ return . seconds( workDoneProgressDebounceDuration )
204
219
}
205
- return . seconds( 0 )
220
+ return . seconds( 1 )
221
+ }
222
+
223
+ public var backgroundIndexingOrDefault : Bool {
224
+ return backgroundIndexing ?? false
206
225
}
207
226
208
227
public init (
@@ -213,9 +232,10 @@ public struct SourceKitLSPOptions: Sendable, Codable {
213
232
index: IndexOptions = . init( ) ,
214
233
defaultWorkspaceType: WorkspaceType ? = nil ,
215
234
generatedFilesPath: String ? = nil ,
235
+ backgroundIndexing: Bool ? = nil ,
216
236
experimentalFeatures: Set < ExperimentalFeature > ? = nil ,
217
- swiftPublishDiagnosticsDebounce : Double ? = nil ,
218
- workDoneProgressDebounce : Double ? = nil
237
+ swiftPublishDiagnosticsDebounceDuration : Double ? = nil ,
238
+ workDoneProgressDebounceDuration : Double ? = nil
219
239
) {
220
240
self . swiftPM = swiftPM
221
241
self . fallbackBuildSystem = fallbackBuildSystem
@@ -224,9 +244,10 @@ public struct SourceKitLSPOptions: Sendable, Codable {
224
244
self . index = index
225
245
self . generatedFilesPath = generatedFilesPath
226
246
self . defaultWorkspaceType = defaultWorkspaceType
247
+ self . backgroundIndexing = backgroundIndexing
227
248
self . experimentalFeatures = experimentalFeatures
228
- self . swiftPublishDiagnosticsDebounce = swiftPublishDiagnosticsDebounce
229
- self . workDoneProgressDebounce = workDoneProgressDebounce
249
+ self . swiftPublishDiagnosticsDebounceDuration = swiftPublishDiagnosticsDebounceDuration
250
+ self . workDoneProgressDebounceDuration = workDoneProgressDebounceDuration
230
251
}
231
252
232
253
public init ? ( path: URL ? ) {
@@ -236,7 +257,7 @@ public struct SourceKitLSPOptions: Sendable, Codable {
236
257
guard
237
258
let decoded = orLog (
238
259
" Parsing config.json " ,
239
- { try JSONDecoder ( ) . decode ( SourceKitLSPOptions . self, from: contents) }
260
+ { try JSONDecoder ( ) . decode ( Self . self, from: contents) }
240
261
)
241
262
else {
242
263
return nil
@@ -246,23 +267,25 @@ public struct SourceKitLSPOptions: Sendable, Codable {
246
267
247
268
public static func merging( base: SourceKitLSPOptions , override: SourceKitLSPOptions ? ) -> SourceKitLSPOptions {
248
269
return SourceKitLSPOptions (
249
- swiftPM: SwiftPMOptions . merging ( base: base. swiftPM ?? . init ( ) , override: override? . swiftPM) ,
270
+ swiftPM: SwiftPMOptions . merging ( base: base. swiftPM, override: override? . swiftPM) ,
250
271
fallbackBuildSystem: FallbackBuildSystemOptions . merging (
251
- base: base. fallbackBuildSystem ?? . init ( ) ,
272
+ base: base. fallbackBuildSystem,
252
273
override: override? . fallbackBuildSystem
253
274
) ,
254
275
compilationDatabase: CompilationDatabaseOptions . merging (
255
- base: base. compilationDatabase ?? . init ( ) ,
276
+ base: base. compilationDatabase,
256
277
override: override? . compilationDatabase
257
278
) ,
258
279
clangdOptions: override? . clangdOptions ?? base. clangdOptions,
259
- index: IndexOptions . merging ( base: base. index ?? . init ( ) , override: override? . index) ,
280
+ index: IndexOptions . merging ( base: base. index, override: override? . index) ,
260
281
defaultWorkspaceType: override? . defaultWorkspaceType ?? base. defaultWorkspaceType,
261
282
generatedFilesPath: override? . generatedFilesPath ?? base. generatedFilesPath,
283
+ backgroundIndexing: override? . backgroundIndexing ?? base. backgroundIndexing,
262
284
experimentalFeatures: override? . experimentalFeatures ?? base. experimentalFeatures,
263
- swiftPublishDiagnosticsDebounce: override? . swiftPublishDiagnosticsDebounce
264
- ?? base. swiftPublishDiagnosticsDebounce,
265
- workDoneProgressDebounce: override? . workDoneProgressDebounce ?? base. workDoneProgressDebounce
285
+ swiftPublishDiagnosticsDebounceDuration: override? . swiftPublishDiagnosticsDebounceDuration
286
+ ?? base. swiftPublishDiagnosticsDebounceDuration,
287
+ workDoneProgressDebounceDuration: override? . workDoneProgressDebounceDuration
288
+ ?? base. workDoneProgressDebounceDuration
266
289
)
267
290
}
268
291
@@ -279,4 +302,34 @@ public struct SourceKitLSPOptions: Sendable, Codable {
279
302
}
280
303
return experimentalFeatures. contains ( feature)
281
304
}
305
+
306
+ public init ( from decoder: any Decoder ) throws {
307
+ let container = try decoder. container ( keyedBy: CodingKeys . self)
308
+
309
+ self . swiftPM = try container. decodeIfPresent ( SwiftPMOptions . self, forKey: CodingKeys . swiftPM) ?? . init( )
310
+ self . compilationDatabase =
311
+ try container. decodeIfPresent ( CompilationDatabaseOptions . self, forKey: CodingKeys . compilationDatabase) ?? . init( )
312
+ self . fallbackBuildSystem =
313
+ try container. decodeIfPresent ( FallbackBuildSystemOptions . self, forKey: CodingKeys . fallbackBuildSystem) ?? . init( )
314
+ self . clangdOptions = try container. decodeIfPresent ( [ String ] . self, forKey: CodingKeys . clangdOptions)
315
+ self . index = try container. decodeIfPresent ( IndexOptions . self, forKey: CodingKeys . index) ?? . init( )
316
+ self . defaultWorkspaceType = try container. decodeIfPresent (
317
+ WorkspaceType . self,
318
+ forKey: CodingKeys . defaultWorkspaceType
319
+ )
320
+ self . generatedFilesPath = try container. decodeIfPresent ( String . self, forKey: CodingKeys . generatedFilesPath)
321
+ self . backgroundIndexing = try container. decodeIfPresent ( Bool . self, forKey: CodingKeys . backgroundIndexing)
322
+ self . experimentalFeatures = try container. decodeIfPresent (
323
+ Set< ExperimentalFeature> . self ,
324
+ forKey: CodingKeys . experimentalFeatures
325
+ )
326
+ self . swiftPublishDiagnosticsDebounceDuration = try container. decodeIfPresent (
327
+ Double . self,
328
+ forKey: CodingKeys . swiftPublishDiagnosticsDebounceDuration
329
+ )
330
+ self . workDoneProgressDebounceDuration = try container. decodeIfPresent (
331
+ Double . self,
332
+ forKey: CodingKeys . workDoneProgressDebounceDuration
333
+ )
334
+ }
282
335
}
0 commit comments