@@ -357,7 +357,7 @@ public actor SourceKitLSPServer {
357
357
358
358
// This should be created as soon as we receive an open call, even if the document
359
359
// isn't yet ready.
360
- guard let languageService = workspace. documentService. value [ doc] else {
360
+ guard let languageService = workspace. documentService ( for : doc) else {
361
361
return
362
362
}
363
363
@@ -377,7 +377,7 @@ public actor SourceKitLSPServer {
377
377
guard let workspace = await self . workspaceForDocument ( uri: request. textDocument. uri) else {
378
378
throw ResponseError . workspaceNotOpen ( request. textDocument. uri)
379
379
}
380
- guard let languageService = workspace. documentService. value [ doc] else {
380
+ guard let languageService = workspace. documentService ( for : doc) else {
381
381
throw ResponseError . unknown ( " No language service for ' \( request. textDocument. uri) ' found " )
382
382
}
383
383
return try await requestHandler ( request, workspace, languageService)
@@ -400,7 +400,7 @@ public actor SourceKitLSPServer {
400
400
guard let workspace = await self . workspaceForDocument ( uri: documentUri) else {
401
401
continue
402
402
}
403
- guard workspace. documentService. value [ documentUri] === languageService else {
403
+ guard workspace. documentService ( for : documentUri) === languageService else {
404
404
continue
405
405
}
406
406
guard let snapshot = try ? self . documentManager. latestSnapshot ( documentUri) else {
@@ -518,7 +518,7 @@ public actor SourceKitLSPServer {
518
518
_ language: Language ,
519
519
in workspace: Workspace
520
520
) async -> LanguageService ? {
521
- if let service = workspace. documentService. value [ uri] {
521
+ if let service = workspace. documentService ( for : uri) {
522
522
return service
523
523
}
524
524
@@ -731,6 +731,8 @@ extension SourceKitLSPServer: MessageHandler {
731
731
await request. reply { try await executeCommand ( request. params) }
732
732
case let request as RequestAndReply < FoldingRangeRequest > :
733
733
await self . handleRequest ( for: request, requestHandler: self . foldingRange)
734
+ case let request as RequestAndReply < GetReferenceDocumentRequest > :
735
+ await request. reply { try await getReferenceDocument ( request. params) }
734
736
case let request as RequestAndReply < HoverRequest > :
735
737
await self . handleRequest ( for: request, requestHandler: self . hover)
736
738
case let request as RequestAndReply < ImplementationRequest > :
@@ -802,7 +804,7 @@ extension SourceKitLSPServer: BuildSystemDelegate {
802
804
continue
803
805
}
804
806
805
- guard let service = await self . workspaceForDocument ( uri: uri) ? . documentService. value [ uri] else {
807
+ guard let service = await self . workspaceForDocument ( uri: uri) ? . documentService ( for : uri) else {
806
808
continue
807
809
}
808
810
@@ -826,7 +828,7 @@ extension SourceKitLSPServer: BuildSystemDelegate {
826
828
}
827
829
for uri in self . affectedOpenDocumentsForChangeSet ( changedFilesForWorkspace, self . documentManager) {
828
830
logger. log ( " Dependencies updated for opened file \( uri. forLogging) " )
829
- if let service = workspace. documentService. value [ uri] {
831
+ if let service = workspace. documentService ( for : uri) {
830
832
await service. documentDependenciesUpdated ( uri)
831
833
}
832
834
}
@@ -961,15 +963,26 @@ extension SourceKitLSPServer {
961
963
//
962
964
// The below is a workaround for the vscode-swift extension since it cannot set client capabilities.
963
965
// It passes "workspace/peekDocuments" through the `initializationOptions`.
966
+ //
967
+ // Similarly, for "workspace/getReferenceDocument".
964
968
var clientCapabilities = req. capabilities
965
- if case . dictionary( let initializationOptions) = req. initializationOptions,
966
- let peekDocuments = initializationOptions [ " workspace/peekDocuments " ]
967
- {
968
- if case . dictionary( var experimentalCapabilities) = clientCapabilities. experimental {
969
- experimentalCapabilities [ " workspace/peekDocuments " ] = peekDocuments
970
- clientCapabilities. experimental = . dictionary( experimentalCapabilities)
971
- } else {
972
- clientCapabilities. experimental = . dictionary( [ " workspace/peekDocuments " : peekDocuments] )
969
+ if case . dictionary( let initializationOptions) = req. initializationOptions {
970
+ if let peekDocuments = initializationOptions [ " workspace/peekDocuments " ] {
971
+ if case . dictionary( var experimentalCapabilities) = clientCapabilities. experimental {
972
+ experimentalCapabilities [ " workspace/peekDocuments " ] = peekDocuments
973
+ clientCapabilities. experimental = . dictionary( experimentalCapabilities)
974
+ } else {
975
+ clientCapabilities. experimental = . dictionary( [ " workspace/peekDocuments " : peekDocuments] )
976
+ }
977
+ }
978
+
979
+ if let getReferenceDocument = initializationOptions [ " workspace/getReferenceDocument " ] {
980
+ if case . dictionary( var experimentalCapabilities) = clientCapabilities. experimental {
981
+ experimentalCapabilities [ " workspace/getReferenceDocument " ] = getReferenceDocument
982
+ clientCapabilities. experimental = . dictionary( experimentalCapabilities)
983
+ } else {
984
+ clientCapabilities. experimental = . dictionary( [ " workspace/getReferenceDocument " : getReferenceDocument] )
985
+ }
973
986
}
974
987
}
975
988
@@ -1121,6 +1134,7 @@ extension SourceKitLSPServer {
1121
1134
" workspace/tests " : . dictionary( [ " version " : . int( 2 ) ] ) ,
1122
1135
" textDocument/tests " : . dictionary( [ " version " : . int( 2 ) ] ) ,
1123
1136
" workspace/triggerReindex " : . dictionary( [ " version " : . int( 1 ) ] ) ,
1137
+ " workspace/getReferenceDocument " : . dictionary( [ " version " : . int( 1 ) ] ) ,
1124
1138
] )
1125
1139
)
1126
1140
}
@@ -1320,7 +1334,7 @@ extension SourceKitLSPServer {
1320
1334
)
1321
1335
return
1322
1336
}
1323
- await workspace. documentService. value [ uri] ? . reopenDocument ( notification)
1337
+ await workspace. documentService ( for : uri) ? . reopenDocument ( notification)
1324
1338
}
1325
1339
1326
1340
func closeDocument( _ notification: DidCloseTextDocumentNotification , workspace: Workspace ) async {
@@ -1334,7 +1348,7 @@ extension SourceKitLSPServer {
1334
1348
1335
1349
await workspace. buildSystemManager. unregisterForChangeNotifications ( for: uri)
1336
1350
1337
- await workspace. documentService. value [ uri] ? . closeDocument ( notification)
1351
+ await workspace. documentService ( for : uri) ? . closeDocument ( notification)
1338
1352
}
1339
1353
1340
1354
func changeDocument( _ notification: DidChangeTextDocumentNotification ) async {
@@ -1360,7 +1374,7 @@ extension SourceKitLSPServer {
1360
1374
// Already logged failure
1361
1375
return
1362
1376
}
1363
- await workspace. documentService. value [ uri] ? . changeDocument (
1377
+ await workspace. documentService ( for : uri) ? . changeDocument (
1364
1378
notification,
1365
1379
preEditSnapshot: preEditSnapshot,
1366
1380
postEditSnapshot: postEditSnapshot,
@@ -1623,7 +1637,7 @@ extension SourceKitLSPServer {
1623
1637
guard let workspace = await workspaceForDocument ( uri: uri) else {
1624
1638
throw ResponseError . workspaceNotOpen ( uri)
1625
1639
}
1626
- guard let languageService = workspace. documentService. value [ uri] else {
1640
+ guard let languageService = workspace. documentService ( for : uri) else {
1627
1641
return nil
1628
1642
}
1629
1643
@@ -1634,6 +1648,21 @@ extension SourceKitLSPServer {
1634
1648
return try await languageService. executeCommand ( executeCommand)
1635
1649
}
1636
1650
1651
+ func getReferenceDocument( _ req: GetReferenceDocumentRequest ) async throws -> GetReferenceDocumentResponse {
1652
+ let referenceDocument = try req. uri. referenceDocument ( )
1653
+ let sourceFileURI = referenceDocument. sourceDocument ( )
1654
+
1655
+ guard let workspace = await workspaceForDocument ( uri: sourceFileURI) else {
1656
+ throw ResponseError . workspaceNotOpen ( sourceFileURI)
1657
+ }
1658
+
1659
+ guard let languageService = workspace. documentService ( for: sourceFileURI) else {
1660
+ throw ResponseError . unknown ( " No Language Service for URI: \( sourceFileURI) " )
1661
+ }
1662
+
1663
+ return try await languageService. getReferenceDocument ( req)
1664
+ }
1665
+
1637
1666
func codeAction(
1638
1667
_ req: CodeActionRequest ,
1639
1668
workspace: Workspace ,
0 commit comments