@@ -111,6 +111,18 @@ public struct SourceKitLSPOptions: Sendable, Codable {
111
111
public var maxCoresPercentageToUseForBackgroundIndexing : Double ?
112
112
public var updateIndexStoreTimeout : Int ?
113
113
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
+
114
126
public init (
115
127
indexStorePath: String ? = nil ,
116
128
indexDatabasePath: String ? = nil ,
@@ -137,16 +149,19 @@ public struct SourceKitLSPOptions: Sendable, Codable {
137
149
}
138
150
}
139
151
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
143
155
public var clangdOptions : [ String ] ?
144
- public var index : IndexOptions ?
156
+ public var index : IndexOptions
145
157
146
158
/// Default workspace type (buildserver|compdb|swiftpm). Overrides workspace type selection logic.
147
159
public var defaultWorkspaceType : WorkspaceType ?
148
160
public var generatedFilesPath : String ?
149
161
162
+ /// Whether background indexing is enabled.
163
+ public var backgroundIndexing : Bool ?
164
+
150
165
/// Experimental features that are enabled.
151
166
public var experimentalFeatures : Set < ExperimentalFeature > ? = nil
152
167
@@ -155,25 +170,29 @@ public struct SourceKitLSPOptions: Sendable, Codable {
155
170
///
156
171
/// This is mostly intended for testing purposes so we don't need to wait the debouncing time to get a diagnostics
157
172
/// notification when running unit tests.
158
- public var swiftPublishDiagnosticsDebounce : Double ? = nil
173
+ public var swiftPublishDiagnosticsDebounceDuration : Double ? = nil
159
174
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 )
163
178
}
164
- return 2 /* seconds */
179
+ return . seconds( 2 )
165
180
}
166
181
167
182
/// When a task is started that should be displayed to the client as a work done progress, how many milliseconds to
168
183
/// wait before actually starting the work done progress. This prevents flickering of the work done progress in the
169
184
/// client for short-lived index tasks which end within this duration.
170
- public var workDoneProgressDebounce : Double ? = nil
185
+ public var workDoneProgressDebounceDuration : Double ? = nil
171
186
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 )
175
190
}
176
- return . seconds( 0 )
191
+ return . seconds( 1 )
192
+ }
193
+
194
+ public var backgroundIndexingOrDefault : Bool {
195
+ return backgroundIndexing ?? false
177
196
}
178
197
179
198
public init (
@@ -184,9 +203,10 @@ public struct SourceKitLSPOptions: Sendable, Codable {
184
203
index: IndexOptions = . init( ) ,
185
204
defaultWorkspaceType: WorkspaceType ? = nil ,
186
205
generatedFilesPath: String ? = nil ,
206
+ backgroundIndexing: Bool ? = nil ,
187
207
experimentalFeatures: Set < ExperimentalFeature > ? = nil ,
188
- swiftPublishDiagnosticsDebounce : Double ? = nil ,
189
- workDoneProgressDebounce : Double ? = nil
208
+ swiftPublishDiagnosticsDebounceDuration : Double ? = nil ,
209
+ workDoneProgressDebounceDuration : Double ? = nil
190
210
) {
191
211
self . swiftPM = swiftPM
192
212
self . fallbackBuildSystem = fallbackBuildSystem
@@ -195,9 +215,10 @@ public struct SourceKitLSPOptions: Sendable, Codable {
195
215
self . index = index
196
216
self . generatedFilesPath = generatedFilesPath
197
217
self . defaultWorkspaceType = defaultWorkspaceType
218
+ self . backgroundIndexing = backgroundIndexing
198
219
self . experimentalFeatures = experimentalFeatures
199
- self . swiftPublishDiagnosticsDebounce = swiftPublishDiagnosticsDebounce
200
- self . workDoneProgressDebounce = workDoneProgressDebounce
220
+ self . swiftPublishDiagnosticsDebounceDuration = swiftPublishDiagnosticsDebounceDuration
221
+ self . workDoneProgressDebounceDuration = workDoneProgressDebounceDuration
201
222
}
202
223
203
224
public init ? ( path: URL ? ) {
@@ -207,7 +228,7 @@ public struct SourceKitLSPOptions: Sendable, Codable {
207
228
guard
208
229
let decoded = orLog (
209
230
" Parsing config.json " ,
210
- { try JSONDecoder ( ) . decode ( SourceKitLSPOptions . self, from: contents) }
231
+ { try JSONDecoder ( ) . decode ( Self . self, from: contents) }
211
232
)
212
233
else {
213
234
return nil
@@ -217,23 +238,25 @@ public struct SourceKitLSPOptions: Sendable, Codable {
217
238
218
239
public static func merging( base: SourceKitLSPOptions , override: SourceKitLSPOptions ? ) -> SourceKitLSPOptions {
219
240
return SourceKitLSPOptions (
220
- swiftPM: SwiftPMOptions . merging ( base: base. swiftPM ?? . init ( ) , override: override? . swiftPM) ,
241
+ swiftPM: SwiftPMOptions . merging ( base: base. swiftPM, override: override? . swiftPM) ,
221
242
fallbackBuildSystem: FallbackBuildSystemOptions . merging (
222
- base: base. fallbackBuildSystem ?? . init ( ) ,
243
+ base: base. fallbackBuildSystem,
223
244
override: override? . fallbackBuildSystem
224
245
) ,
225
246
compilationDatabase: CompilationDatabaseOptions . merging (
226
- base: base. compilationDatabase ?? . init ( ) ,
247
+ base: base. compilationDatabase,
227
248
override: override? . compilationDatabase
228
249
) ,
229
250
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) ,
231
252
defaultWorkspaceType: override? . defaultWorkspaceType ?? base. defaultWorkspaceType,
232
253
generatedFilesPath: override? . generatedFilesPath ?? base. generatedFilesPath,
254
+ backgroundIndexing: override? . backgroundIndexing ?? base. backgroundIndexing,
233
255
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
237
260
)
238
261
}
239
262
@@ -250,4 +273,34 @@ public struct SourceKitLSPOptions: Sendable, Codable {
250
273
}
251
274
return experimentalFeatures. contains ( feature)
252
275
}
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
+ }
253
306
}
0 commit comments