@@ -116,7 +116,6 @@ public actor SwiftLanguageServer: ToolchainLanguageServer {
116
116
private var inFlightPublishDiagnosticsTasks : [ DocumentURI : Task < Void , Never > ] = [ : ]
117
117
118
118
let syntaxTreeManager = SyntaxTreeManager ( )
119
- let semanticTokensManager = SemanticTokensManager ( )
120
119
121
120
nonisolated var keys : sourcekitd_keys { return sourcekitd. keys }
122
121
nonisolated var requests : sourcekitd_requests { return sourcekitd. requests }
@@ -195,7 +194,7 @@ public actor SwiftLanguageServer: ToolchainLanguageServer {
195
194
}
196
195
197
196
/// Returns the semantic tokens in `response` for the given `snapshot`.
198
- private func semanticTokens(
197
+ func semanticTokens(
199
198
of response: SKDResponseDictionary ,
200
199
for snapshot: DocumentSnapshot
201
200
) -> [ SyntaxHighlightingToken ] ? {
@@ -208,48 +207,6 @@ public actor SwiftLanguageServer: ToolchainLanguageServer {
208
207
209
208
return tokens
210
209
}
211
-
212
- /// Inform the client about changes to the syntax highlighting tokens.
213
- private func requestTokensRefresh( ) async {
214
- guard let sourceKitServer else {
215
- logger. fault ( " Cannot request a token refresh because SourceKitServer has been destructed " )
216
- return
217
- }
218
- if capabilityRegistry. clientHasSemanticTokenRefreshSupport {
219
- Task {
220
- do {
221
- _ = try await sourceKitServer. sendRequestToClient ( WorkspaceSemanticTokensRefreshRequest ( ) )
222
- } catch {
223
- logger. error ( " refreshing tokens failed: \( error. forLogging) " )
224
- }
225
- }
226
- }
227
- }
228
-
229
- func handleDocumentUpdate( uri: DocumentURI ) async {
230
- guard let snapshot = documentManager. latestSnapshot ( uri) else {
231
- return
232
- }
233
- // Make the magic 0,0 replacetext request to update diagnostics and semantic tokens.
234
-
235
- let req = SKDRequestDictionary ( sourcekitd: sourcekitd)
236
- req [ keys. request] = requests. editor_replacetext
237
- req [ keys. name] = uri. pseudoPath
238
- req [ keys. offset] = 0
239
- req [ keys. length] = 0
240
- req [ keys. sourcetext] = " "
241
-
242
- if let dict = try ? self . sourcekitd. sendSync ( req) {
243
- let isSemaStage = dict [ keys. diagnostic_stage] as sourcekitd_uid_t ? == sourcekitd. values. diag_stage_sema
244
- if isSemaStage, let semanticTokens = semanticTokens ( of: dict, for: snapshot) {
245
- // Only update semantic tokens if the 0,0 replacetext request returned semantic information.
246
- await semanticTokensManager. setSemanticTokens ( for: snapshot. id, semanticTokens: semanticTokens)
247
- }
248
- if isSemaStage {
249
- await requestTokensRefresh ( )
250
- }
251
- }
252
- }
253
210
}
254
211
255
212
extension SwiftLanguageServer {
@@ -412,8 +369,6 @@ extension SwiftLanguageServer {
412
369
req [ keys. name] = uri. pseudoPath
413
370
414
371
_ = try ? self . sourcekitd. sendSync ( req)
415
-
416
- await semanticTokensManager. discardSemanticTokens ( for: note. textDocument. uri)
417
372
}
418
373
419
374
/// Cancels any in-flight tasks to send a `PublishedDiagnosticsNotification` after edits.
@@ -508,11 +463,6 @@ extension SwiftLanguageServer {
508
463
postEditSnapshot: postEditSnapshot,
509
464
edits: ConcurrentEdits ( fromSequential: edits)
510
465
)
511
- await semanticTokensManager. registerEdit (
512
- preEditSnapshot: preEditSnapshot. id,
513
- postEditSnapshot: postEditSnapshot. id,
514
- edits: note. contentChanges
515
- )
516
466
517
467
publishDiagnosticsIfNeeded ( for: note. textDocument. uri)
518
468
}
@@ -1343,54 +1293,12 @@ extension SwiftLanguageServer: SKDNotificationHandler {
1343
1293
self . documentManager = DocumentManager ( )
1344
1294
}
1345
1295
1346
- guard let dict = notification. value else {
1347
- logger. fault (
1348
- """
1349
- Could not decode sourcekitd notification
1350
- \( notification. forLogging)
1351
- """
1352
- )
1353
- return
1354
- }
1355
-
1356
1296
logger. debug (
1357
1297
"""
1358
1298
Received notification from sourcekitd
1359
1299
\( notification. forLogging)
1360
1300
"""
1361
1301
)
1362
-
1363
- if let kind: sourcekitd_uid_t = dict [ self . keys. notification] ,
1364
- kind == self . values. notification_documentupdate,
1365
- let name: String = dict [ self . keys. name]
1366
- {
1367
-
1368
- let uri : DocumentURI
1369
-
1370
- // Paths are expected to be absolute; on Windows, this means that the
1371
- // path is either drive letter prefixed (and thus `PathGetDriveNumberW`
1372
- // will provide the driver number OR it is a UNC path and `PathIsUNCW`
1373
- // will return `true`. On Unix platforms, the path will start with `/`
1374
- // which takes care of both a regular absolute path and a POSIX
1375
- // alternate root path.
1376
-
1377
- // TODO: this is not completely portable, e.g. MacOS 9 HFS paths are
1378
- // unhandled.
1379
- #if os(Windows)
1380
- let isPath : Bool = name. withCString ( encodedAs: UTF16 . self) {
1381
- !PathIsURLW( $0)
1382
- }
1383
- #else
1384
- let isPath : Bool = name. starts ( with: " / " )
1385
- #endif
1386
- if isPath {
1387
- // If sourcekitd returns us a path, translate it back into a URL
1388
- uri = DocumentURI ( URL ( fileURLWithPath: name) )
1389
- } else {
1390
- uri = DocumentURI ( string: name)
1391
- }
1392
- await self . handleDocumentUpdate ( uri: uri)
1393
- }
1394
1302
}
1395
1303
}
1396
1304
0 commit comments