@@ -111,6 +111,18 @@ public struct SourceKitLSPOptions: Sendable, Codable {
111111 public var maxCoresPercentageToUseForBackgroundIndexing : Double ?
112112 public var updateIndexStoreTimeout : Int ?
113113
114+ public var maxCoresPercentageToUseForBackgroundIndexingOrDefault : Double {
115+ return maxCoresPercentageToUseForBackgroundIndexing ?? 1
116+ }
117+
118+ public var updateIndexStoreTimeoutOrDefault : Duration {
119+ if let updateIndexStoreTimeout {
120+ . seconds( updateIndexStoreTimeout)
121+ } else {
122+ . seconds( 120 )
123+ }
124+ }
125+
114126 public init (
115127 indexStorePath: String ? = nil ,
116128 indexDatabasePath: String ? = nil ,
@@ -137,16 +149,19 @@ public struct SourceKitLSPOptions: Sendable, Codable {
137149 }
138150 }
139151
140- public var swiftPM : SwiftPMOptions ?
141- public var compilationDatabase : CompilationDatabaseOptions ?
142- public var fallbackBuildSystem : FallbackBuildSystemOptions ?
152+ public var swiftPM : SwiftPMOptions
153+ public var compilationDatabase : CompilationDatabaseOptions
154+ public var fallbackBuildSystem : FallbackBuildSystemOptions
143155 public var clangdOptions : [ String ] ?
144- public var index : IndexOptions ?
156+ public var index : IndexOptions
145157
146158 /// Default workspace type (buildserver|compdb|swiftpm). Overrides workspace type selection logic.
147159 public var defaultWorkspaceType : WorkspaceType ?
148160 public var generatedFilesPath : String ?
149161
162+ /// Whether background indexing is enabled.
163+ public var backgroundIndexing : Bool ?
164+
150165 /// Experimental features that are enabled.
151166 public var experimentalFeatures : Set < ExperimentalFeature > ? = nil
152167
@@ -155,25 +170,29 @@ public struct SourceKitLSPOptions: Sendable, Codable {
155170 ///
156171 /// This is mostly intended for testing purposes so we don't need to wait the debouncing time to get a diagnostics
157172 /// notification when running unit tests.
158- public var swiftPublishDiagnosticsDebounce : Double ? = nil
173+ public var swiftPublishDiagnosticsDebounceDuration : Double ? = nil
159174
160- public var swiftPublishDiagnosticsDebounceDuration : TimeInterval {
161- if let workDoneProgressDebounce {
162- return workDoneProgressDebounce
175+ public var swiftPublishDiagnosticsDebounceDurationOrDefault : Duration {
176+ if let swiftPublishDiagnosticsDebounceDuration {
177+ return . seconds ( swiftPublishDiagnosticsDebounceDuration )
163178 }
164- return 2 /* seconds */
179+ return . seconds( 2 )
165180 }
166181
167182 /// When a task is started that should be displayed to the client as a work done progress, how many milliseconds to
168183 /// wait before actually starting the work done progress. This prevents flickering of the work done progress in the
169184 /// client for short-lived index tasks which end within this duration.
170- public var workDoneProgressDebounce : Double ? = nil
185+ public var workDoneProgressDebounceDuration : Double ? = nil
171186
172- public var workDoneProgressDebounceDuration : Duration {
173- if let workDoneProgressDebounce {
174- return . seconds( workDoneProgressDebounce )
187+ public var workDoneProgressDebounceDurationOrDefault : Duration {
188+ if let workDoneProgressDebounceDuration {
189+ return . seconds( workDoneProgressDebounceDuration )
175190 }
176- return . seconds( 0 )
191+ return . seconds( 1 )
192+ }
193+
194+ public var backgroundIndexingOrDefault : Bool {
195+ return backgroundIndexing ?? false
177196 }
178197
179198 public init (
@@ -184,9 +203,10 @@ public struct SourceKitLSPOptions: Sendable, Codable {
184203 index: IndexOptions = . init( ) ,
185204 defaultWorkspaceType: WorkspaceType ? = nil ,
186205 generatedFilesPath: String ? = nil ,
206+ backgroundIndexing: Bool ? = nil ,
187207 experimentalFeatures: Set < ExperimentalFeature > ? = nil ,
188- swiftPublishDiagnosticsDebounce : Double ? = nil ,
189- workDoneProgressDebounce : Double ? = nil
208+ swiftPublishDiagnosticsDebounceDuration : Double ? = nil ,
209+ workDoneProgressDebounceDuration : Double ? = nil
190210 ) {
191211 self . swiftPM = swiftPM
192212 self . fallbackBuildSystem = fallbackBuildSystem
@@ -195,9 +215,10 @@ public struct SourceKitLSPOptions: Sendable, Codable {
195215 self . index = index
196216 self . generatedFilesPath = generatedFilesPath
197217 self . defaultWorkspaceType = defaultWorkspaceType
218+ self . backgroundIndexing = backgroundIndexing
198219 self . experimentalFeatures = experimentalFeatures
199- self . swiftPublishDiagnosticsDebounce = swiftPublishDiagnosticsDebounce
200- self . workDoneProgressDebounce = workDoneProgressDebounce
220+ self . swiftPublishDiagnosticsDebounceDuration = swiftPublishDiagnosticsDebounceDuration
221+ self . workDoneProgressDebounceDuration = workDoneProgressDebounceDuration
201222 }
202223
203224 public init ? ( path: URL ? ) {
@@ -207,7 +228,7 @@ public struct SourceKitLSPOptions: Sendable, Codable {
207228 guard
208229 let decoded = orLog (
209230 " Parsing config.json " ,
210- { try JSONDecoder ( ) . decode ( SourceKitLSPOptions . self, from: contents) }
231+ { try JSONDecoder ( ) . decode ( Self . self, from: contents) }
211232 )
212233 else {
213234 return nil
@@ -217,23 +238,25 @@ public struct SourceKitLSPOptions: Sendable, Codable {
217238
218239 public static func merging( base: SourceKitLSPOptions , override: SourceKitLSPOptions ? ) -> SourceKitLSPOptions {
219240 return SourceKitLSPOptions (
220- swiftPM: SwiftPMOptions . merging ( base: base. swiftPM ?? . init ( ) , override: override? . swiftPM) ,
241+ swiftPM: SwiftPMOptions . merging ( base: base. swiftPM, override: override? . swiftPM) ,
221242 fallbackBuildSystem: FallbackBuildSystemOptions . merging (
222- base: base. fallbackBuildSystem ?? . init ( ) ,
243+ base: base. fallbackBuildSystem,
223244 override: override? . fallbackBuildSystem
224245 ) ,
225246 compilationDatabase: CompilationDatabaseOptions . merging (
226- base: base. compilationDatabase ?? . init ( ) ,
247+ base: base. compilationDatabase,
227248 override: override? . compilationDatabase
228249 ) ,
229250 clangdOptions: override? . clangdOptions ?? base. clangdOptions,
230- index: IndexOptions . merging ( base: base. index ?? . init ( ) , override: override? . index) ,
251+ index: IndexOptions . merging ( base: base. index, override: override? . index) ,
231252 defaultWorkspaceType: override? . defaultWorkspaceType ?? base. defaultWorkspaceType,
232253 generatedFilesPath: override? . generatedFilesPath ?? base. generatedFilesPath,
254+ backgroundIndexing: override? . backgroundIndexing ?? base. backgroundIndexing,
233255 experimentalFeatures: override? . experimentalFeatures ?? base. experimentalFeatures,
234- swiftPublishDiagnosticsDebounce: override? . swiftPublishDiagnosticsDebounce
235- ?? base. swiftPublishDiagnosticsDebounce,
236- workDoneProgressDebounce: override? . workDoneProgressDebounce ?? base. workDoneProgressDebounce
256+ swiftPublishDiagnosticsDebounceDuration: override? . swiftPublishDiagnosticsDebounceDuration
257+ ?? base. swiftPublishDiagnosticsDebounceDuration,
258+ workDoneProgressDebounceDuration: override? . workDoneProgressDebounceDuration
259+ ?? base. workDoneProgressDebounceDuration
237260 )
238261 }
239262
@@ -250,4 +273,34 @@ public struct SourceKitLSPOptions: Sendable, Codable {
250273 }
251274 return experimentalFeatures. contains ( feature)
252275 }
276+
277+ public init ( from decoder: any Decoder ) throws {
278+ let container = try decoder. container ( keyedBy: CodingKeys . self)
279+
280+ self . swiftPM = try container. decodeIfPresent ( SwiftPMOptions . self, forKey: CodingKeys . swiftPM) ?? . init( )
281+ self . compilationDatabase =
282+ try container. decodeIfPresent ( CompilationDatabaseOptions . self, forKey: CodingKeys . compilationDatabase) ?? . init( )
283+ self . fallbackBuildSystem =
284+ try container. decodeIfPresent ( FallbackBuildSystemOptions . self, forKey: CodingKeys . fallbackBuildSystem) ?? . init( )
285+ self . clangdOptions = try container. decodeIfPresent ( [ String ] . self, forKey: CodingKeys . clangdOptions)
286+ self . index = try container. decodeIfPresent ( IndexOptions . self, forKey: CodingKeys . index) ?? . init( )
287+ self . defaultWorkspaceType = try container. decodeIfPresent (
288+ WorkspaceType . self,
289+ forKey: CodingKeys . defaultWorkspaceType
290+ )
291+ self . generatedFilesPath = try container. decodeIfPresent ( String . self, forKey: CodingKeys . generatedFilesPath)
292+ self . backgroundIndexing = try container. decodeIfPresent ( Bool . self, forKey: CodingKeys . backgroundIndexing)
293+ self . experimentalFeatures = try container. decodeIfPresent (
294+ Set< ExperimentalFeature> . self ,
295+ forKey: CodingKeys . experimentalFeatures
296+ )
297+ self . swiftPublishDiagnosticsDebounceDuration = try container. decodeIfPresent (
298+ Double . self,
299+ forKey: CodingKeys . swiftPublishDiagnosticsDebounceDuration
300+ )
301+ self . workDoneProgressDebounceDuration = try container. decodeIfPresent (
302+ Double . self,
303+ forKey: CodingKeys . workDoneProgressDebounceDuration
304+ )
305+ }
253306}
0 commit comments