@@ -140,6 +140,18 @@ public struct SourceKitLSPOptions: Sendable, Codable {
140140 public var maxCoresPercentageToUseForBackgroundIndexing : Double ?
141141 public var updateIndexStoreTimeout : Int ?
142142
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+
143155 public init (
144156 indexStorePath: String ? = nil ,
145157 indexDatabasePath: String ? = nil ,
@@ -166,16 +178,19 @@ public struct SourceKitLSPOptions: Sendable, Codable {
166178 }
167179 }
168180
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
172184 public var clangdOptions : [ String ] ?
173- public var index : IndexOptions ?
185+ public var index : IndexOptions
174186
175187 /// Default workspace type (buildserver|compdb|swiftpm). Overrides workspace type selection logic.
176188 public var defaultWorkspaceType : WorkspaceType ?
177189 public var generatedFilesPath : String ?
178190
191+ /// Whether background indexing is enabled.
192+ public var backgroundIndexing : Bool ?
193+
179194 /// Experimental features that are enabled.
180195 public var experimentalFeatures : Set < ExperimentalFeature > ? = nil
181196
@@ -184,25 +199,29 @@ public struct SourceKitLSPOptions: Sendable, Codable {
184199 ///
185200 /// This is mostly intended for testing purposes so we don't need to wait the debouncing time to get a diagnostics
186201 /// notification when running unit tests.
187- public var swiftPublishDiagnosticsDebounce : Double ? = nil
202+ public var swiftPublishDiagnosticsDebounceDuration : Double ? = nil
188203
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 )
192207 }
193- return 2 /* seconds */
208+ return . seconds( 2 )
194209 }
195210
196211 /// When a task is started that should be displayed to the client as a work done progress, how many milliseconds to
197212 /// wait before actually starting the work done progress. This prevents flickering of the work done progress in the
198213 /// client for short-lived index tasks which end within this duration.
199- public var workDoneProgressDebounce : Double ? = nil
214+ public var workDoneProgressDebounceDuration : Double ? = nil
200215
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 )
204219 }
205- return . seconds( 0 )
220+ return . seconds( 1 )
221+ }
222+
223+ public var backgroundIndexingOrDefault : Bool {
224+ return backgroundIndexing ?? false
206225 }
207226
208227 public init (
@@ -213,9 +232,10 @@ public struct SourceKitLSPOptions: Sendable, Codable {
213232 index: IndexOptions = . init( ) ,
214233 defaultWorkspaceType: WorkspaceType ? = nil ,
215234 generatedFilesPath: String ? = nil ,
235+ backgroundIndexing: Bool ? = nil ,
216236 experimentalFeatures: Set < ExperimentalFeature > ? = nil ,
217- swiftPublishDiagnosticsDebounce : Double ? = nil ,
218- workDoneProgressDebounce : Double ? = nil
237+ swiftPublishDiagnosticsDebounceDuration : Double ? = nil ,
238+ workDoneProgressDebounceDuration : Double ? = nil
219239 ) {
220240 self . swiftPM = swiftPM
221241 self . fallbackBuildSystem = fallbackBuildSystem
@@ -224,9 +244,10 @@ public struct SourceKitLSPOptions: Sendable, Codable {
224244 self . index = index
225245 self . generatedFilesPath = generatedFilesPath
226246 self . defaultWorkspaceType = defaultWorkspaceType
247+ self . backgroundIndexing = backgroundIndexing
227248 self . experimentalFeatures = experimentalFeatures
228- self . swiftPublishDiagnosticsDebounce = swiftPublishDiagnosticsDebounce
229- self . workDoneProgressDebounce = workDoneProgressDebounce
249+ self . swiftPublishDiagnosticsDebounceDuration = swiftPublishDiagnosticsDebounceDuration
250+ self . workDoneProgressDebounceDuration = workDoneProgressDebounceDuration
230251 }
231252
232253 public init ? ( path: URL ? ) {
@@ -236,7 +257,7 @@ public struct SourceKitLSPOptions: Sendable, Codable {
236257 guard
237258 let decoded = orLog (
238259 " Parsing config.json " ,
239- { try JSONDecoder ( ) . decode ( SourceKitLSPOptions . self, from: contents) }
260+ { try JSONDecoder ( ) . decode ( Self . self, from: contents) }
240261 )
241262 else {
242263 return nil
@@ -246,23 +267,25 @@ public struct SourceKitLSPOptions: Sendable, Codable {
246267
247268 public static func merging( base: SourceKitLSPOptions , override: SourceKitLSPOptions ? ) -> SourceKitLSPOptions {
248269 return SourceKitLSPOptions (
249- swiftPM: SwiftPMOptions . merging ( base: base. swiftPM ?? . init ( ) , override: override? . swiftPM) ,
270+ swiftPM: SwiftPMOptions . merging ( base: base. swiftPM, override: override? . swiftPM) ,
250271 fallbackBuildSystem: FallbackBuildSystemOptions . merging (
251- base: base. fallbackBuildSystem ?? . init ( ) ,
272+ base: base. fallbackBuildSystem,
252273 override: override? . fallbackBuildSystem
253274 ) ,
254275 compilationDatabase: CompilationDatabaseOptions . merging (
255- base: base. compilationDatabase ?? . init ( ) ,
276+ base: base. compilationDatabase,
256277 override: override? . compilationDatabase
257278 ) ,
258279 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) ,
260281 defaultWorkspaceType: override? . defaultWorkspaceType ?? base. defaultWorkspaceType,
261282 generatedFilesPath: override? . generatedFilesPath ?? base. generatedFilesPath,
283+ backgroundIndexing: override? . backgroundIndexing ?? base. backgroundIndexing,
262284 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
266289 )
267290 }
268291
@@ -279,4 +302,34 @@ public struct SourceKitLSPOptions: Sendable, Codable {
279302 }
280303 return experimentalFeatures. contains ( feature)
281304 }
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+ }
282335}
0 commit comments