@@ -183,14 +183,14 @@ package actor SwiftLanguageService: LanguageService, Sendable {
183
183
/// `buildSettings(for:)` returns `nil` are not included.
184
184
private var buildSettingsForOpenFiles : [ DocumentURI : SwiftCompileCommand ] = [ : ]
185
185
186
- /// Calling `scheduleCall` on `refreshDiagnosticsDebouncer ` schedules a `DiagnosticsRefreshRequest` to be sent to
187
- /// to the client.
186
+ /// Calling `scheduleCall` on `refreshDiagnosticsAndSemanticTokensDebouncer ` schedules a `DiagnosticsRefreshRequest`
187
+ /// and `WorkspaceSemanticTokensRefreshRequest` to be sent to to the client.
188
188
///
189
189
/// We debounce these calls because the `DiagnosticsRefreshRequest` is a workspace-wide request. If we discover that
190
190
/// the client should update diagnostics for file A and then discover that it should also update diagnostics for file
191
191
/// B, we don't want to send two `DiagnosticsRefreshRequest`s. Instead, the two should be unified into a single
192
192
/// request.
193
- private let refreshDiagnosticsDebouncer : Debouncer < Void >
193
+ private let refreshDiagnosticsAndSemanticTokensDebouncer : Debouncer < Void >
194
194
195
195
/// Creates a language server for the given client using the sourcekitd dylib specified in `toolchain`.
196
196
/// `reopenDocuments` is a closure that will be called if sourcekitd crashes and the `SwiftLanguageService` asks its
@@ -229,19 +229,29 @@ package actor SwiftLanguageService: LanguageService, Sendable {
229
229
self . options = options
230
230
231
231
// The debounce duration of 500ms was chosen arbitrarily without scientific research.
232
- self . refreshDiagnosticsDebouncer = Debouncer ( debounceDuration: . milliseconds( 500 ) ) { [ weak sourceKitLSPServer] in
232
+ self . refreshDiagnosticsAndSemanticTokensDebouncer = Debouncer ( debounceDuration: . milliseconds( 500 ) ) {
233
+ [ weak sourceKitLSPServer] in
233
234
guard let sourceKitLSPServer else {
234
- logger. fault ( " Not sending DiagnosticRefreshRequest to client because sourceKitLSPServer has been deallocated " )
235
+ logger. fault (
236
+ " Not sending diagnostic and semantic token refresh request to client because sourceKitLSPServer has been deallocated "
237
+ )
235
238
return
236
239
}
237
- guard
238
- await sourceKitLSPServer. capabilityRegistry? . clientCapabilities. workspace? . diagnostics? . refreshSupport ?? false
239
- else {
240
+ let clientCapabilities = await sourceKitLSPServer. capabilityRegistry? . clientCapabilities
241
+ if clientCapabilities? . workspace? . diagnostics? . refreshSupport ?? false {
242
+ _ = await orLog ( " Sending DiagnosticRefreshRequest to client after document dependencies updated " ) {
243
+ try await sourceKitLSPServer. sendRequestToClient ( DiagnosticsRefreshRequest ( ) )
244
+ }
245
+ } else {
240
246
logger. debug ( " Not sending DiagnosticRefreshRequest because the client doesn't support it " )
241
- return
242
247
}
243
- _ = await orLog ( " Sending DiagnosticRefreshRequest to client after document dependencies updated " ) {
244
- try await sourceKitLSPServer. sendRequestToClient ( DiagnosticsRefreshRequest ( ) )
248
+
249
+ if clientCapabilities? . workspace? . semanticTokens? . refreshSupport ?? false {
250
+ _ = await orLog ( " Sending WorkspaceSemanticTokensRefreshRequest to client after document dependencies updated " ) {
251
+ try await sourceKitLSPServer. sendRequestToClient ( WorkspaceSemanticTokensRefreshRequest ( ) )
252
+ }
253
+ } else {
254
+ logger. debug ( " Not sending WorkspaceSemanticTokensRefreshRequest because the client doesn't support it " )
245
255
}
246
256
}
247
257
@@ -337,7 +347,7 @@ package actor SwiftLanguageService: LanguageService, Sendable {
337
347
await sourceKitLSPServer. sourcekitdCrashedWorkDoneProgress. end ( )
338
348
// We can provide diagnostics again now. Send a diagnostic refresh request to prompt the editor to reload
339
349
// diagnostics.
340
- await refreshDiagnosticsDebouncer . scheduleCall ( )
350
+ await refreshDiagnosticsAndSemanticTokensDebouncer . scheduleCall ( )
341
351
case ( . connected, . connected) ,
342
352
( . connectionInterrupted, . connectionInterrupted) ,
343
353
( . connectionInterrupted, . semanticFunctionalityDisabled) ,
@@ -469,7 +479,7 @@ extension SwiftLanguageService {
469
479
}
470
480
471
481
if await capabilityRegistry. clientSupportsPullDiagnostics ( for: . swift) {
472
- await self . refreshDiagnosticsDebouncer . scheduleCall ( )
482
+ await self . refreshDiagnosticsAndSemanticTokensDebouncer . scheduleCall ( )
473
483
} else {
474
484
await publishDiagnosticsIfNeeded ( for: snapshot. uri)
475
485
}
0 commit comments